Skip to content

Commit

Permalink
first and litle more attempt to build architecture of project
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-xz committed Jun 15, 2024
1 parent cc533f6 commit c652286
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Database/FindUrl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PostgreSQLTutorial;
namespace Hexlet\Code\Database;

/**
* Создание в PostgreSQL таблицы из демонстрации PHP
Expand Down
30 changes: 30 additions & 0 deletions src/Database/GetUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Hexlet\Code\Database;

use PostgreSQLTutorial\FindUrl;

class GetUrl
{
/**
* объект PDO
* @var \PDO
*/
private $pdo;


public function __construct($pdo)
{
$this->pdo = $pdo;
}

public function process()
{
$sql = 'SELECT *
FROM ad
ORDER BY created_at DESC';
$sth = $this->pdo->prepare($sql);
$sth->execute();
return $sth->fetchAll();
}
}
2 changes: 1 addition & 1 deletion src/Database/InsertUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Hexlet\Code\Database;

use PostgreSQLTutorial\FindUrl;
use Hexlet\Code\Database\FindUrl;

class InsertUrl
{
Expand Down
9 changes: 5 additions & 4 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

class Engine
{
private $action;
private $processor;
private $value;

public function __construct($databaseName, $action, $value)
{
public function __construct(
$databaseName,
$action,
$value = null
) {
$connectData = "Connect{$databaseName}";
$actionName = "{$action}{$databaseName}";
$database = $connectData::get()->connect();
$processor = new $actionName($database);
$this->processor = $processor;
$this->action = $action;
$this->value = $value;
}

Expand Down
17 changes: 17 additions & 0 deletions src/Validate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App;

class Validator
{
public function validate(string $url): array
{
$errors = [];
if (strlen($url) > 255) {
$errors['strlen'] = "Url must be less than 256 characters";
} elseif (!filter_var($url, FILTER_VALIDATE_URL)) {
$errors['valid'] = 'URL is not valid';
}
return $errors;
}
}

0 comments on commit c652286

Please sign in to comment.