-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: переписал приложение используя DDD
- Loading branch information
Showing
11 changed files
with
142 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
# Homework 13 | ||
# Homework 15 | ||
|
||
1. `cd app` | ||
2. `cp .env.example .env` | ||
3. `docker-compose up --build -d` | ||
4. `docker-compose exec -it postrges bash` | ||
4. `docker compose exec -it postrges bash` | ||
5. `psql -U test test < /var/www/application.local/sql/ddl.sql` | ||
6. `psql -U test test < /var/www/application.local/sql/dml.sql` | ||
7. `docker-compose exec -it php bash` | ||
7. `docker compose exec -it php bash` | ||
8. `cd /var/www/application.local` | ||
9. `composer install` | ||
10. `php public/index.php` | ||
10. `php public/index.php all` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AYamaliev\hw13\Application\Dto; | ||
|
||
class NewsDto | ||
{ | ||
private string $title; | ||
private string $text; | ||
private string $image; | ||
private string $created_at; | ||
|
||
public function __construct(array $arguments) | ||
{ | ||
foreach ($arguments as $argument) { | ||
[$argumentName, $argumentValue] = explode('=', $argument); | ||
|
||
switch ($argumentName) { | ||
case '--title': | ||
$this->title = $argumentValue; | ||
break; | ||
case '--text': | ||
$this->text = $argumentValue; | ||
break; | ||
case '--image': | ||
$this->image = $argumentValue; | ||
break; | ||
case '--created_at': | ||
$this->created_at = $argumentValue; | ||
break; | ||
} | ||
} | ||
} | ||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function getText(): string | ||
{ | ||
return $this->text; | ||
} | ||
|
||
public function getImage(): string | ||
{ | ||
return $this->image; | ||
} | ||
|
||
public function getCreatedAt(): string | ||
{ | ||
return $this->created_at; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../src/IdentityMap/IdentityMapInterface.php → ...main/IdentityMap/IdentityMapInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
app/www/application.local/src/Infrastructure/NewsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AYamaliev\hw13\Infrastructure; | ||
|
||
use AYamaliev\hw13\Application\DataMapper\NewsMapper; | ||
use AYamaliev\hw13\Application\Dto\NewsDto; | ||
use AYamaliev\hw13\Domain\IdentityMap\IdentityMap; | ||
use AYamaliev\hw13\Domain\News; | ||
|
||
class NewsController | ||
{ | ||
public \PDO $pdo; | ||
public IdentityMap $identityMap; | ||
public NewsMapper $newsMapper; | ||
|
||
public function __construct($connection) | ||
{ | ||
$this->identityMap = new IdentityMap(); | ||
$this->pdo = $connection; | ||
$this->newsMapper = new NewsMapper($this->pdo, $this->identityMap); | ||
} | ||
|
||
public function getAll(): array | ||
{ | ||
return $this->newsMapper->getAll(); | ||
} | ||
|
||
public function getById(int $id): ?News | ||
{ | ||
return $this->newsMapper->findById($id); | ||
} | ||
|
||
public function deleteById(int $id): bool | ||
{ | ||
$news = $this->newsMapper->findById($id); | ||
return $this->newsMapper->delete($news); | ||
} | ||
|
||
public function add(NewsDto $newsDto): News | ||
{ | ||
return $this->newsMapper->insert([ | ||
'title' => $newsDto->getTitle(), | ||
'text' => $newsDto->getText(), | ||
'image' => $newsDto->getImage(), | ||
'created_at' => $newsDto->getCreatedAt(), | ||
]); | ||
} | ||
} |