-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read layer usage in Write layer (example)
- Loading branch information
Showing
14 changed files
with
197 additions
and
11 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
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,2 @@ | ||
* | ||
!.gitignore |
12 changes: 12 additions & 0 deletions
12
...ter9/Application/Author/Command/UpgradeAuthorsWithMoreThanAThousandOfFollowersCommand.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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cheeper\Chapter9\Application\Author\Command; | ||
|
||
final readonly class UpgradeAuthorsWithMoreThanAThousandOfFollowersCommand | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...plication/Author/Command/UpgradeAuthorsWithMoreThanAThousandOfFollowersCommandHandler.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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cheeper\Chapter9\Application\Author\Command; | ||
|
||
use Cheeper\Chapter9\DomainModel\Author\AuthorRepository; | ||
use Cheeper\Chapter9\DomainModel\Author\AuthorsWithMoreThanAThousandOfFollowers; | ||
|
||
final readonly class UpgradeAuthorsWithMoreThanAThousandOfFollowersCommandHandler | ||
{ | ||
public function __construct( | ||
private AuthorRepository $authors, | ||
private AuthorsWithMoreThanAThousandOfFollowers $authorsWithMoreThanAThousandOfFollowers | ||
) { | ||
} | ||
|
||
public function __invoke(UpgradeAuthorsWithMoreThanAThousandOfFollowersCommand $command): void | ||
{ | ||
$authorsWithMoreThanAThousandOfFollowers = $this->authorsWithMoreThanAThousandOfFollowers; | ||
$authorIds = $authorsWithMoreThanAThousandOfFollowers(); | ||
|
||
foreach ($authorIds as $authorId) { | ||
$author = $this->authors->ofId($authorId); | ||
$author->upgrade(); | ||
$this->authors->save($author); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...thor/Event/WhenAuthorFollowedThenListAuthorsWithMoreThanThousandFollowersEventHandler.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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Cheeper\Chapter9\Application\Author\Event; | ||
|
||
use Cheeper\AllChapters\DomainModel\Author\AuthorId; | ||
use Cheeper\Chapter7\Application\Author\Projection\IncrementCountFollowersProjection; | ||
use Cheeper\Chapter7\Application\ProjectionBus; | ||
use Cheeper\Chapter8\DomainModel\Follow\AuthorFollowed; | ||
use Cheeper\Chapter8\DomainModel\Follow\FollowRepository; | ||
|
||
final readonly class WhenAuthorFollowedThenListAuthorsWithMoreThanThousandFollowersEventHandler | ||
{ | ||
public function __construct( | ||
private ProjectionBus $projectionBus, | ||
private FollowRepository $followRepository | ||
) { | ||
} | ||
|
||
public function __invoke(AuthorFollowed $event): void | ||
{ | ||
if ($this->followRepository->numberOfFollowersFor(AuthorId::fromString($event->toAuthorId())) >= 1000) { | ||
$this->projectionBus->project( | ||
IncrementCountFollowersProjection::ofAuthor( | ||
$event->toAuthorId() | ||
) | ||
); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ion/Author/Projection/AddAuthorToListOfAuthorsWithMoreThanThousandFollowersProjection.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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Cheeper\Chapter9\Application\Author\Projection; | ||
|
||
final readonly class AddAuthorToListOfAuthorsWithMoreThanThousandFollowersProjection | ||
{ | ||
public function __construct( | ||
public string $authorId | ||
) { | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...hor/Projection/AddAuthorToListOfAuthorsWithMoreThanThousandFollowersProjectionHandler.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Cheeper\Chapter9\Application\Author\Projection; | ||
|
||
final readonly class AddAuthorToListOfAuthorsWithMoreThanThousandFollowersProjectionHandler | ||
{ | ||
public function __construct( | ||
private string $filePath | ||
) { | ||
} | ||
|
||
public function __invoke(AddAuthorToListOfAuthorsWithMoreThanThousandFollowersProjection $projection): void | ||
{ | ||
file_put_contents($this->filePath, $projection->authorId . PHP_EOL, FILE_APPEND); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
src/Cheeper/Chapter9/DomainModel/Author/AuthorWasUpgraded.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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Cheeper\Chapter9\DomainModel\Author; | ||
|
||
use Cheeper\Chapter7\Application\MessageTrait; | ||
use Cheeper\Chapter7\DomainModel\DomainEvent; | ||
|
||
final readonly class AuthorWasUpgraded implements DomainEvent | ||
{ | ||
use MessageTrait; | ||
|
||
public function __construct( | ||
public string $authorId | ||
) { | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Cheeper/Chapter9/DomainModel/Author/AuthorsWithMoreThanAThousandOfFollowers.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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cheeper\Chapter9\DomainModel\Author; | ||
|
||
use Cheeper\AllChapters\DomainModel\Author\AuthorId; | ||
|
||
interface AuthorsWithMoreThanAThousandOfFollowers | ||
{ | ||
/** @return AuthorId[] */ | ||
public function __invoke(): array; | ||
} |
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
24 changes: 24 additions & 0 deletions
24
...er9/Infrastructure/DomainModel/Author/TextFileAuthorsWithMoreThanAThousandOfFollowers.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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cheeper\Chapter9\Infrastructure\DomainModel\Author; | ||
|
||
use Cheeper\AllChapters\DomainModel\Author\AuthorId; | ||
use Cheeper\Chapter9\DomainModel\Author\AuthorsWithMoreThanAThousandOfFollowers; | ||
|
||
final readonly class TextFileAuthorsWithMoreThanAThousandOfFollowers implements AuthorsWithMoreThanAThousandOfFollowers | ||
{ | ||
public function __construct( | ||
private string $filePath | ||
) { | ||
} | ||
|
||
public function __invoke(): array | ||
{ | ||
return array_map( | ||
fn(string $authorId) => AuthorId::fromString($authorId), | ||
file($this->filePath) | ||
); | ||
} | ||
} |