diff --git a/composer.json b/composer.json index c0085bf..4f9019d 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,8 @@ "require": { "php": ">=5.4.0", "monolog/monolog": "~1.10", - "symfony/event-dispatcher": "~2.5", - "symfony/http-kernel": "~2.5", + "symfony/event-dispatcher": "~2.5|~3.0", + "symfony/http-kernel": "~2.5|~3.0", "black/common": "~2.0.0", "cocur/slugify": "~1.0" }, diff --git a/spec/Black/Component/Page/Application/DTO/CreateWebPageDTOSpec.php b/spec/Page/Application/DTO/CreateWebPageDTOSpec.php similarity index 73% rename from spec/Black/Component/Page/Application/DTO/CreateWebPageDTOSpec.php rename to spec/Page/Application/DTO/CreateWebPageDTOSpec.php index 2d09db5..bdf1c67 100644 --- a/spec/Black/Component/Page/Application/DTO/CreateWebPageDTOSpec.php +++ b/spec/Page/Application/DTO/CreateWebPageDTOSpec.php @@ -1,6 +1,6 @@ shouldHaveType('Black\Component\Page\Application\DTO\CreateWebPageDTO'); + $this->shouldHaveType('Black\Page\Application\DTO\CreateWebPageDTO'); } public function it_should_return_id() @@ -41,16 +41,6 @@ public function it_should_return_name() $this->getName()->shouldReturn($this->name); } - public function it_should_return_context() - { - $this->getContext()->shouldReturn("http://schema.org"); - } - - public function it_should_return_type() - { - $this->getType()->shouldReturn("WebPage"); - } - public function it_should_serialize() { $this->serialize()->shouldBeString(); diff --git a/spec/Black/Component/Page/Application/DTO/CreateWebPageTransformerSpec.php b/spec/Page/Application/DTO/CreateWebPageTransformerSpec.php similarity index 71% rename from spec/Black/Component/Page/Application/DTO/CreateWebPageTransformerSpec.php rename to spec/Page/Application/DTO/CreateWebPageTransformerSpec.php index d93bcfb..ba95fbb 100644 --- a/spec/Black/Component/Page/Application/DTO/CreateWebPageTransformerSpec.php +++ b/spec/Page/Application/DTO/CreateWebPageTransformerSpec.php @@ -1,8 +1,8 @@ entityClass = 'Black\Component\Page\Domain\Model\WebPage'; - $this->dtoClass = 'Black\Component\Page\Application\DTO\CreateWebPageDTO'; + $this->entityClass = 'Black\Page\Domain\Model\WebPage'; + $this->dtoClass = 'Black\Page\Application\DTO\CreateWebPageDTO'; $this->beConstructedWith($this->entityClass, $this->dtoClass); } diff --git a/spec/Black/Component/Page/Application/DTO/WebPageDTOSpec.php b/spec/Page/Application/DTO/WebPageDTOSpec.php similarity index 72% rename from spec/Black/Component/Page/Application/DTO/WebPageDTOSpec.php rename to spec/Page/Application/DTO/WebPageDTOSpec.php index bb85c7c..03c5ac2 100644 --- a/spec/Black/Component/Page/Application/DTO/WebPageDTOSpec.php +++ b/spec/Page/Application/DTO/WebPageDTOSpec.php @@ -1,6 +1,6 @@ id = 1; - $this->author = 'test'; - $this->name = 'test'; + $this->id = 1; + $this->author = 'test'; + $this->name = 'test'; $this->headline = 'test'; - $this->about = 'test'; - $this->text = 'test'; + $this->about = 'test'; + $this->text = 'test'; $this->beConstructedWith($this->id, $this->author, $this->name, $this->headline, $this->about, $this->text); } public function it_is_initializable() { - $this->shouldHaveType('Black\Component\Page\Application\DTO\WebPageDTO'); + $this->shouldHaveType('Black\Page\Application\DTO\WebPageDTO'); } public function it_should_return_id() @@ -65,16 +65,6 @@ public function it_should_return_text() $this->getText()->shouldReturn($this->text); } - public function it_should_return_context() - { - $this->getContext()->shouldReturn("http://schema.org"); - } - - public function it_should_return_type() - { - $this->getType()->shouldReturn("WebPage"); - } - public function it_should_serialize() { $this->serialize()->shouldBeString(); diff --git a/spec/Black/Component/Page/Application/DTO/WebPageTransformerSpec.php b/spec/Page/Application/DTO/WebPageTransformerSpec.php similarity index 72% rename from spec/Black/Component/Page/Application/DTO/WebPageTransformerSpec.php rename to spec/Page/Application/DTO/WebPageTransformerSpec.php index 19fbb2a..3fbb911 100644 --- a/spec/Black/Component/Page/Application/DTO/WebPageTransformerSpec.php +++ b/spec/Page/Application/DTO/WebPageTransformerSpec.php @@ -1,8 +1,8 @@ entityClass = 'Black\Component\Page\Domain\Model\WebPage'; - $this->dtoClass = 'Black\Component\Page\Application\DTO\WebPageDTO'; + $this->entityClass = 'Black\Page\Domain\Model\WebPage'; + $this->dtoClass = 'Black\Page\Application\DTO\WebPageDTO'; $this->beConstructedWith($this->entityClass, $this->dtoClass); } diff --git a/spec/Black/Component/Page/Application/DTO/WriteWebPageDTOSpec.php b/spec/Page/Application/DTO/WriteWebPageDTOSpec.php similarity index 70% rename from spec/Black/Component/Page/Application/DTO/WriteWebPageDTOSpec.php rename to spec/Page/Application/DTO/WriteWebPageDTOSpec.php index 4f57c55..a2e9597 100644 --- a/spec/Black/Component/Page/Application/DTO/WriteWebPageDTOSpec.php +++ b/spec/Page/Application/DTO/WriteWebPageDTOSpec.php @@ -1,6 +1,6 @@ id = 1; + $this->id = 1; $this->headline = 'test'; - $this->about = 'test'; - $this->text = 'test'; + $this->about = 'test'; + $this->text = 'test'; $this->beConstructedWith($this->id, $this->headline, $this->about, $this->text); } public function it_is_initializable() { - $this->shouldHaveType('Black\Component\Page\Application\DTO\WriteWebPageDTO'); + $this->shouldHaveType('Black\Page\Application\DTO\WriteWebPageDTO'); } public function it_should_return_id() @@ -49,16 +49,6 @@ public function it_should_return_text() $this->getText()->shouldReturn($this->text); } - public function it_should_return_context() - { - $this->getContext()->shouldReturn("http://schema.org"); - } - - public function it_should_return_type() - { - $this->getType()->shouldReturn("WebPage"); - } - public function it_should_serialize() { $this->serialize()->shouldBeString(); diff --git a/spec/Black/Component/Page/Application/DTO/WriteWebPageTransformerSpec.php b/spec/Page/Application/DTO/WriteWebPageTransformerSpec.php similarity index 72% rename from spec/Black/Component/Page/Application/DTO/WriteWebPageTransformerSpec.php rename to spec/Page/Application/DTO/WriteWebPageTransformerSpec.php index 88e0fad..a988c3f 100644 --- a/spec/Black/Component/Page/Application/DTO/WriteWebPageTransformerSpec.php +++ b/spec/Page/Application/DTO/WriteWebPageTransformerSpec.php @@ -1,8 +1,8 @@ entityClass = 'Black\Component\Page\Domain\Model\WebPage'; - $this->dtoClass = 'Black\Component\Page\Application\DTO\WriteWebPageDTO'; + $this->entityClass = 'Black\Page\Domain\Model\WebPage'; + $this->dtoClass = 'Black\Page\Application\DTO\WriteWebPageDTO'; $this->beConstructedWith($this->entityClass, $this->dtoClass); } diff --git a/spec/Black/Component/Page/Application/Specification/PageIsPublishedSpecificationSpec.php b/spec/Page/Application/Specification/PageIsPublishedSpecificationSpec.php similarity index 58% rename from spec/Black/Component/Page/Application/Specification/PageIsPublishedSpecificationSpec.php rename to spec/Page/Application/Specification/PageIsPublishedSpecificationSpec.php index 8e8d4e6..b6302df 100644 --- a/spec/Black/Component/Page/Application/Specification/PageIsPublishedSpecificationSpec.php +++ b/spec/Page/Application/Specification/PageIsPublishedSpecificationSpec.php @@ -1,9 +1,9 @@ shouldHaveType('Black\Component\Page\Application\Specification\PageIsPublishedSpecification'); + $this->shouldHaveType('Black\Page\Application\Specification\PageIsPublishedSpecification'); } public function let() { $pageId = new WebPageId('12345'); - $page = new WebPage($pageId, 'test', 'test'); + $page = new WebPage($pageId, 'test', 'test', 'test'); $this->page = $page; } diff --git a/spec/Black/Component/Page/Domain/Model/WebPageIdSpec.php b/spec/Page/Domain/Model/WebPageIdSpec.php similarity index 81% rename from spec/Black/Component/Page/Domain/Model/WebPageIdSpec.php rename to spec/Page/Domain/Model/WebPageIdSpec.php index 95b8bb0..9410b72 100644 --- a/spec/Black/Component/Page/Domain/Model/WebPageIdSpec.php +++ b/spec/Page/Domain/Model/WebPageIdSpec.php @@ -1,8 +1,8 @@ shouldHaveType('Black\Component\Page\Domain\Model\WebPageId'); + $this->shouldHaveType('Black\Page\Domain\Model\WebPageId'); } public function it_should_have_a_value() diff --git a/spec/Black/Component/Page/Domain/Model/WebPageSpec.php b/spec/Page/Domain/Model/WebPageSpec.php similarity index 77% rename from spec/Black/Component/Page/Domain/Model/WebPageSpec.php rename to spec/Page/Domain/Model/WebPageSpec.php index f2af7fb..1ca1337 100644 --- a/spec/Black/Component/Page/Domain/Model/WebPageSpec.php +++ b/spec/Page/Domain/Model/WebPageSpec.php @@ -1,9 +1,9 @@ webPageId = $page->getWebPageId(); - $this->name = $page->getName(); - $this->author = $page->getAuthor(); + $this->name = $page->getName(); + $this->author = $page->getAuthor(); + $this->slug = $page->getSlug(); - $this->beConstructedWith($this->webPageId, $this->name, $this->author); + $this->beConstructedWith($this->webPageId, $this->name, $this->author, $this->slug); } public function it_is_initializable() { - $this->shouldHaveType('Black\Component\Page\Domain\Model\WebPage'); + $this->shouldHaveType('Black\Page\Domain\Model\WebPage'); } public function it_should_have_a_dateCreated() @@ -63,8 +64,8 @@ public function it_should_not_be_published() public function it_should_be_write() { $this->headline = "headline"; - $this->about = "about"; - $this->text = "text"; + $this->about = "about"; + $this->text = "text"; $this->write($this->headline, $this->about, $this->text); @@ -76,8 +77,8 @@ public function it_should_be_write() public function it_should_be_edited() { $this->headline = "headline 2"; - $this->about = "about 2"; - $this->text = "text 2"; + $this->about = "about 2"; + $this->text = "text 2"; $this->write($this->headline, $this->about, $this->text); diff --git a/src/Black/Component/Page/Application/Controller/CreatePageController.php b/src/Black/Component/Page/Application/Controller/CreatePageController.php deleted file mode 100644 index 7ffc79d..0000000 --- a/src/Black/Component/Page/Application/Controller/CreatePageController.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Application\Controller; - -use Black\Component\Page\Domain\Model\WebPageId; -use Black\Component\Page\Infrastructure\CQRS\Handler\CreateWebPageHandler; -use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus; - -/** - * Class CreatePageController - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -class CreatePageController -{ - /** - * @var \Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus - */ - protected $bus; - - /** - * @var - */ - protected $commandName; - - /** - * @var \Black\Component\Page\Infrastructure\CQRS\Handler\CreateWebPageHandler - */ - protected $handler; - - /** - * @param Bus $bus - * @param CreateWebPageHandler $handler - * @param $commandName - */ - public function __construct( - Bus $bus, - CreateWebPageHandler $handler, - $commandName - ) { - $this->bus = $bus; - $this->handler = $handler; - $this->commandName = $commandName; - } - - /** - * @param WebPageId $id - * @param $author - * @param $name - */ - public function createPageAction(WebPageId $id, $author, $name) - { - $this->bus->register($this->commandName, $this->handler); - $this->bus->handle(new $this->commandName($id, $author, $name)); - } -} diff --git a/src/Black/Component/Page/Application/Controller/PublishPageController.php b/src/Black/Component/Page/Application/Controller/PublishPageController.php deleted file mode 100644 index 66ca8f4..0000000 --- a/src/Black/Component/Page/Application/Controller/PublishPageController.php +++ /dev/null @@ -1,64 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Application\Controller; - -use Black\Component\Page\Domain\Model\WebPageId; -use Black\Component\Page\Infrastructure\CQRS\Handler\PublishWebPageHandler; -use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus; - -/** - * Class PublishPageController - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -class PublishPageController -{ - /** - * @var \Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus - */ - protected $bus; - - /** - * @var - */ - protected $commandName; - - /** - * @var \Black\Component\Page\Infrastructure\CQRS\Handler\PublishWebPageHandler - */ - protected $handler; - - /** - * @param Bus $bus - * @param PublishWebPageHandler $handler - * @param $commandName - */ - public function __construct( - Bus $bus, - PublishWebPageHandler $handler, - $commandName - ) { - $this->bus = $bus; - $this->handler = $handler; - $this->commandName = $commandName; - } - - /** - * @param WebPageId $id - */ - public function publishPageAction(WebPageId $id) - { - $this->bus->register($this->commandName, $this->handler); - $this->bus->handle(new $this->commandName($id)); - } -} diff --git a/src/Black/Component/Page/Application/Controller/ReadPageController.php b/src/Black/Component/Page/Application/Controller/ReadPageController.php deleted file mode 100644 index 2a8184d..0000000 --- a/src/Black/Component/Page/Application/Controller/ReadPageController.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Application\Controller; - -use Black\Component\Page\Application\Service\WebPageReadService; -use Black\Component\Page\Domain\Model\WebPageId; - -/** - * Class ReadPageController - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -class ReadPageController -{ - /** - * @var \Black\Component\Page\Application\Service\WebPageReadService - */ - protected $service; - - /** - * @param WebPageReadService $service - */ - public function __construct(WebPageReadService $service) - { - $this->service = $service; - } - - /** - * @param WebPageId $id - * - * @return \Black\Component\Page\Application\DTO\WebPageDTO - */ - public function readPageAction(WebPageId $id) - { - $page = $this->service->read($id); - - return $page; - } -} diff --git a/src/Black/Component/Page/Application/Controller/RemovePageController.php b/src/Black/Component/Page/Application/Controller/RemovePageController.php deleted file mode 100644 index 5fcbd1b..0000000 --- a/src/Black/Component/Page/Application/Controller/RemovePageController.php +++ /dev/null @@ -1,65 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Application\Controller; - -use Black\Component\Page\Domain\Model\WebPage; -use Black\Component\Page\Domain\Model\WebPageId; -use Black\Component\Page\Infrastructure\CQRS\Handler\RemoveWebPageHandler; -use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus; - -/** - * Class RemovePageController - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -class RemovePageController -{ - /** - * @var \Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus - */ - protected $bus; - - /** - * @var - */ - protected $commandName; - - /** - * @var \Black\Component\Page\Infrastructure\CQRS\Handler\RemoveWebPageHandler - */ - protected $handler; - - /** - * @param Bus $bus - * @param RemoveWebPageHandler $handler - * @param $commandName - */ - public function __construct( - Bus $bus, - RemoveWebPageHandler $handler, - $commandName - ) { - $this->bus = $bus; - $this->handler = $handler; - $this->commandName = $commandName; - } - - /** - * @param WebPageId $id - */ - public function removePageAction(WebPage $page) - { - $this->bus->register($this->commandName, $this->handler); - $this->bus->handle(new $this->commandName($page)); - } -} diff --git a/src/Black/Component/Page/Application/Controller/WritePageController.php b/src/Black/Component/Page/Application/Controller/WritePageController.php deleted file mode 100644 index 1b15818..0000000 --- a/src/Black/Component/Page/Application/Controller/WritePageController.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Application\Controller; - -use Black\Component\Page\Application\DTO\WriteWebPageDTO; -use Black\Component\Page\Domain\Model\WebPageId; -use Black\Component\Page\Infrastructure\CQRS\Handler\WriteWebPageHandler; -use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus; - -/** - * Class WritePageController - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -class WritePageController -{ - /** - * @var \Black\DDD\CQRSinPHP\Infrastructure\CQRS\Bus - */ - protected $bus; - - /** - * @var - */ - protected $commandName; - - /** - * @var \Black\Component\Page\Infrastructure\CQRS\Handler\WriteWebPageHandler - */ - protected $handler; - - /** - * @param Bus $bus - * @param WriteWebPageHandler $handler - * @param $commandName - */ - public function __construct( - Bus $bus, - WriteWebPageHandler $handler, - $commandName - ) { - $this->bus = $bus; - $this->handler = $handler; - $this->commandName = $commandName; - } - - /** - * @param WriteWebPageDTO $dto - */ - public function writePageAction(WriteWebPageDTO $dto) - { - $this->bus->register($this->commandName, $this->handler); - $this->bus->handle(new $this->commandName( - new WebPageId($dto->getId()), - $dto->getHeadline(), - $dto->getAbout(), - $dto->getText() - )); - } -} diff --git a/src/Black/Component/Page/Application/Specification/PageIsPublishedSpecification.php b/src/Black/Component/Page/Application/Specification/PageIsPublishedSpecification.php deleted file mode 100644 index bdd3d76..0000000 --- a/src/Black/Component/Page/Application/Specification/PageIsPublishedSpecification.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Application\Specification; - -use Black\Component\Page\Domain\Model\WebPage; - -/** - * Class PageIsPublishedSpecification - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -final class PageIsPublishedSpecification -{ - /** - * @param WebPage $webPage - * - * @return bool - */ - public function isSatisfiedBy(WebPage $webPage) - { - return (bool) true === $webPage->isPublished(); - } -} diff --git a/src/Black/Component/Page/Domain/Model/WebPageReadRepository.php b/src/Black/Component/Page/Domain/Model/WebPageReadRepository.php deleted file mode 100644 index 08f2eda..0000000 --- a/src/Black/Component/Page/Domain/Model/WebPageReadRepository.php +++ /dev/null @@ -1,22 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Infrastructure\CQRS\Command; - -use Black\Component\Page\Domain\Model\WebPage; -use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Command; - -/** - * Class RemoveWebPageCommand - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -final class RemoveWebPageCommand implements Command -{ - /** - * @var - */ - private $webPage; - - /** - * @param WebPage $webPage - */ - public function __construct(WebPage $webPage) - { - $this->webPage = $webPage; - } - - /** - * @return mixed - */ - public function getWebPage() - { - return $this->webPage; - } -} diff --git a/src/Black/Component/Page/Infrastructure/CQRS/Handler/CreateWebPageHandler.php b/src/Black/Component/Page/Infrastructure/CQRS/Handler/CreateWebPageHandler.php deleted file mode 100644 index 449d943..0000000 --- a/src/Black/Component/Page/Infrastructure/CQRS/Handler/CreateWebPageHandler.php +++ /dev/null @@ -1,71 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Infrastructure\CQRS\Handler; - -use Black\Component\Page\Domain\Model\WebPageWriteRepository; -use Black\Component\Page\Infrastructure\CQRS\Command\CreateWebPageCommand; -use Black\Component\Page\Domain\Event\WebPageCreatedEvent; -use Black\Component\Page\Infrastructure\Service\WebPageWriteService; -use Black\Component\Page\WebPageDomainEvents; -use Black\DDD\CQRSinPHP\Infrastructure\CQRS\CommandHandler; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; - -/** - * Class CreateWebPageHandler - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -final class CreateWebPageHandler implements CommandHandler -{ - /** - * @var WebPageWriteService - */ - protected $service; - - /** - * @var WebPageWriteRepository - */ - protected $repository; - - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * @param WebPageWriteService $service - * @param WebPageWriteRepository $repository - * @param EventDispatcherInterface $eventDispatcher - */ - public function __construct( - WebPageWriteService $service, - WebPageWriteRepository $repository, - EventDispatcherInterface $eventDispatcher - ) { - $this->service = $service; - $this->repository = $repository; - $this->eventDispatcher = $eventDispatcher; - } - - /** - * @param CreateWebPageCommand $command - * @return mixed - */ - public function handle(CreateWebPageCommand $command) - { - $page = $this->service->create($command->getWebPageId(), $command->getAuthor(), $command->getName()); - $this->repository->flush(); - - $event = new WebPageCreatedEvent($page->getWebPageId()->getValue(), $page->getName()); - $this->eventDispatcher->dispatch(WebPageDomainEvents::WEBPAGE_DOMAIN_CREATED, $event); - } -} diff --git a/src/Black/Component/Page/Infrastructure/CQRS/Handler/DepublishWebPageHandler.php b/src/Black/Component/Page/Infrastructure/CQRS/Handler/DepublishWebPageHandler.php deleted file mode 100644 index 35ba07f..0000000 --- a/src/Black/Component/Page/Infrastructure/CQRS/Handler/DepublishWebPageHandler.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Infrastructure\CQRS\Handler; - -use Black\Component\Page\Domain\Model\WebPageWriteRepository; -use Black\Component\Page\Infrastructure\CQRS\Command\DepublishWebPageCommand; -use Black\Component\Page\Domain\Event\WebPageDepublishedEvent; -use Black\Component\Page\Infrastructure\Service\WebPageWriteService; -use Black\Component\Page\WebPageDomainEvents; -use Black\DDD\CQRSinPHP\Infrastructure\CQRS\CommandHandler; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; - -/** - * Class DepublishWebPageHandler - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -final class DepublishWebPageHandler implements CommandHandler -{ - /** - * @var WebPageWriteService - */ - protected $service; - - /** - * @var - */ - protected $repository; - - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * @param WebPageWriteService $service - * @param WebPageWriteRepository $repository - * @param EventDispatcherInterface $eventDispatcher - */ - public function __construct( - WebPageWriteService $service, - WebPageWriteRepository $repository, - EventDispatcherInterface $eventDispatcher - ) { - $this->service = $service; - $this->repository = $repository; - $this->eventDispatcher = $eventDispatcher; - } - - /** - * @param DepublishWebPageCommand $command - * @return mixed - */ - public function handle(DepublishWebPageCommand $command) - { - $page = $this->service->depublish($command->getWebPage()); - - $this->repository->flush(); - - $event = new WebPageDepublishedEvent($page->getWebPageId()->getValue(), $page->getName()); - $this->eventDispatcher->dispatch(WebPageDomainEvents::WEBPAGE_DOMAIN_DEPUBLISHED, $event); - } -} diff --git a/src/Black/Component/Page/Infrastructure/CQRS/Handler/PublishWebPageHandler.php b/src/Black/Component/Page/Infrastructure/CQRS/Handler/PublishWebPageHandler.php deleted file mode 100644 index d1cf27d..0000000 --- a/src/Black/Component/Page/Infrastructure/CQRS/Handler/PublishWebPageHandler.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Infrastructure\CQRS\Handler; - -use Black\Component\Page\Domain\Model\WebPageWriteRepository; -use Black\Component\Page\Infrastructure\CQRS\Command\PublishWebPageCommand; -use Black\Component\Page\Domain\Event\WebPagePublishedEvent; -use Black\Component\Page\Infrastructure\Service\WebPageWriteService; -use Black\Component\Page\WebPageDomainEvents; -use Black\DDD\CQRSinPHP\Infrastructure\CQRS\CommandHandler; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; - -/** - * Class PublishWebPageHandler - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -final class PublishWebPageHandler implements CommandHandler -{ - /** - * @var WebPageWriteService - */ - protected $service; - - /** - * @var WebPageReadRepository - */ - protected $repository; - - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * @param WebPageWriteService $service - * @param WebPageReadRepository $repository - * @param EventDispatcherInterface $eventDispatcher - */ - public function __construct( - WebPageWriteService $service, - WebPageWriteRepository $repository, - EventDispatcherInterface $eventDispatcher - ) { - $this->service = $service; - $this->repository = $repository; - $this->eventDispatcher = $eventDispatcher; - } - - /** - * @param PublishWebPageCommand $command - * @return mixed - */ - public function handle(PublishWebPageCommand $command) - { - $page = $this->service->publish($command->getWebPage()); - - $this->repository->flush(); - - $event = new WebPagePublishedEvent($page->getWebPageId()->getValue(), $page->getName()); - $this->eventDispatcher->dispatch(WebPageDomainEvents::WEBPAGE_DOMAIN_PUBLISHED, $event); - } -} diff --git a/src/Black/Component/Page/Infrastructure/CQRS/Handler/RemoveWebPageHandler.php b/src/Black/Component/Page/Infrastructure/CQRS/Handler/RemoveWebPageHandler.php deleted file mode 100644 index 1e1059f..0000000 --- a/src/Black/Component/Page/Infrastructure/CQRS/Handler/RemoveWebPageHandler.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Infrastructure\CQRS\Handler; - -use Black\Component\Page\Domain\Model\WebPageWriteRepository; -use Black\Component\Page\Infrastructure\CQRS\Command\RemoveWebPageCommand; -use Black\Component\Page\Domain\Event\WebPageRemovedEvent; -use Black\Component\Page\Infrastructure\Service\WebPageWriteService; -use Black\Component\Page\WebPageDomainEvents; -use Black\DDD\CQRSinPHP\Infrastructure\CQRS\CommandHandler; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; - -/** - * Class RemoveWebPageHandler - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT - */ -final class RemoveWebPageHandler implements CommandHandler -{ - /** - * @var WebPageWriteService - */ - protected $service; - - /** - * @var WebPageWriteRepository - */ - protected $repository; - - /** - * @var EventDispatcherInterface - */ - protected $eventDispatcher; - - /** - * @param WebPageWriteService $service - * @param WebPageWriteRepository $repository - * @param EventDispatcherInterface $eventDispatcher - */ - public function __construct( - WebPageWriteService $service, - WebPageWriteRepository $repository, - EventDispatcherInterface $eventDispatcher - ) { - $this->service = $service; - $this->repository = $repository; - $this->eventDispatcher = $eventDispatcher; - } - - /** - * @param RemoveWebPageCommand $command - * @return mixed - */ - public function handle(RemoveWebPageCommand $command) - { - $page = $this->service->remove($command->getWebPage()); - - $this->repository->flush(); - - $event = new WebPageRemovedEvent($page->getWebPageId()->getValue(), $page->getName()); - $this->eventDispatcher->dispatch(WebPageDomainEvents::WEBPAGE_DOMAIN_REMOVED, $event); - } -} diff --git a/src/Black/Component/Page/Infrastructure/Persistence/MongoDB/WriteRepository.php b/src/Black/Component/Page/Infrastructure/Persistence/MongoDB/WriteRepository.php deleted file mode 100644 index 9c290cd..0000000 --- a/src/Black/Component/Page/Infrastructure/Persistence/MongoDB/WriteRepository.php +++ /dev/null @@ -1,39 +0,0 @@ -manager->persist($website); - } - - /** - * @param WebPage $website - */ - public function remove(WebPage $website) - { - $this->manager->remove($website); - } - - /** - * - */ - public function flush() - { - $this->manager->flush(); - } -} diff --git a/src/Black/Component/Page/Infrastructure/Persistence/ORM/WriteRepository.php b/src/Black/Component/Page/Infrastructure/Persistence/ORM/WriteRepository.php deleted file mode 100644 index 0ba5666..0000000 --- a/src/Black/Component/Page/Infrastructure/Persistence/ORM/WriteRepository.php +++ /dev/null @@ -1,41 +0,0 @@ -manager->persist($website); - } - - /** - * @param WebPage $website - */ - public function remove(WebPage $website) - { - $this->manager->remove($website); - } - - /** - * Flushes all changes to objects that have been queued up to now to the database. - * This effectively synchronizes the in-memory state of managed objects with the - * database. - */ - public function flush() - { - $this->manager->flush(); - } -} diff --git a/src/Black/Component/Page/WebPageDomainEvents.php b/src/Black/Component/Page/WebPageDomainEvents.php deleted file mode 100644 index fc3de08..0000000 --- a/src/Black/Component/Page/WebPageDomainEvents.php +++ /dev/null @@ -1,19 +0,0 @@ -bus = $bus; + $this->handler = $handler; + $this->commandName = $commandName; + } + + /** + * @param WebPageId $id + * @param $author + * @param $name + */ + public function __invoke(WebPageId $id, $author, $name) + { + $this->bus->register($this->commandName, $this->handler); + $this->bus->handle(new $this->commandName($id, $author, $name)); + } +} diff --git a/src/Page/Application/Action/PublishWebPage.php b/src/Page/Application/Action/PublishWebPage.php new file mode 100644 index 0000000..f98c632 --- /dev/null +++ b/src/Page/Application/Action/PublishWebPage.php @@ -0,0 +1,54 @@ +bus = $bus; + $this->handler = $handler; + $this->commandName = $commandName; + } + + /** + * @param WebPageId $id + */ + public function __invoke(WebPageId $id) + { + $this->bus->register($this->commandName, $this->handler); + $this->bus->handle(new $this->commandName($id)); + } +} diff --git a/src/Page/Application/Action/ReadWebPage.php b/src/Page/Application/Action/ReadWebPage.php new file mode 100644 index 0000000..b77c0bb --- /dev/null +++ b/src/Page/Application/Action/ReadWebPage.php @@ -0,0 +1,36 @@ +service = $service; + } + + /** + * @param WebPageId $id + * @return \Black\Page\Application\DTO\WebPageDTO + */ + public function __invoke(WebPageId $id) + { + $page = $this->service->read($id); + + return $page; + } +} diff --git a/src/Page/Application/Action/RemoveWebPage.php b/src/Page/Application/Action/RemoveWebPage.php new file mode 100644 index 0000000..dbb0178 --- /dev/null +++ b/src/Page/Application/Action/RemoveWebPage.php @@ -0,0 +1,55 @@ +bus = $bus; + $this->handler = $handler; + $this->commandName = $commandName; + } + + /** + * @param WebPage $page + */ + public function __invoke(WebPage $page) + { + $this->bus->register($this->commandName, $this->handler); + $this->bus->handle(new $this->commandName($page)); + } +} diff --git a/src/Page/Application/Action/WriteWebPage.php b/src/Page/Application/Action/WriteWebPage.php new file mode 100644 index 0000000..ce7dae5 --- /dev/null +++ b/src/Page/Application/Action/WriteWebPage.php @@ -0,0 +1,60 @@ +bus = $bus; + $this->handler = $handler; + $this->commandName = $commandName; + } + + /** + * @param WriteWebPageDTO $dto + */ + public function __invoke(WriteWebPageDTO $dto) + { + $this->bus->register($this->commandName, $this->handler); + $this->bus->handle(new $this->commandName( + new WebPageId($dto->getId()), + $dto->getHeadline(), + $dto->getAbout(), + $dto->getText() + )); + } +} diff --git a/src/Black/Component/Page/Application/DTO/CreateWebPageAssembler.php b/src/Page/Application/DTO/CreateWebPageAssembler.php similarity index 77% rename from src/Black/Component/Page/Application/DTO/CreateWebPageAssembler.php rename to src/Page/Application/DTO/CreateWebPageAssembler.php index 81cb1e1..a8e85ee 100644 --- a/src/Black/Component/Page/Application/DTO/CreateWebPageAssembler.php +++ b/src/Page/Application/DTO/CreateWebPageAssembler.php @@ -1,15 +1,12 @@ - * @license http://opensource.org/licenses/mit-license.php MIT */ class CreateWebPageAssembler { @@ -30,7 +27,7 @@ class CreateWebPageAssembler public function __construct($entityClass, $dtoClass) { $this->entityClass = $entityClass; - $this->dtoClass = $dtoClass; + $this->dtoClass = $dtoClass; } /** diff --git a/src/Black/Component/Page/Application/DTO/CreateWebPageDTO.php b/src/Page/Application/DTO/CreateWebPageDTO.php similarity index 66% rename from src/Black/Component/Page/Application/DTO/CreateWebPageDTO.php rename to src/Page/Application/DTO/CreateWebPageDTO.php index d605117..dd26a38 100644 --- a/src/Black/Component/Page/Application/DTO/CreateWebPageDTO.php +++ b/src/Page/Application/DTO/CreateWebPageDTO.php @@ -1,12 +1,9 @@ - * @license http://opensource.org/licenses/mit-license.php MIT */ final class CreateWebPageDTO { @@ -42,11 +39,9 @@ final class CreateWebPageDTO */ public function __construct($id, $author, $name) { - $this->id = $id; - $this->author = $author; - $this->name = $name; - $this->context = "http://schema.org"; - $this->type = "WebPage"; + $this->id = $id; + $this->author = $author; + $this->name = $name; } /** @@ -73,22 +68,6 @@ public function getName() return $this->name; } - /** - * @return string - */ - public function getContext() - { - return $this->context; - } - - /** - * @return string - */ - public function getType() - { - return $this->type; - } - /** * @return string */ @@ -98,8 +77,6 @@ public function serialize() $this->id, $this->author, $this->name, - $this->context, - $this->type, ]); } diff --git a/src/Black/Component/Page/Application/DTO/WebPageAssembler.php b/src/Page/Application/DTO/WebPageAssembler.php similarity index 74% rename from src/Black/Component/Page/Application/DTO/WebPageAssembler.php rename to src/Page/Application/DTO/WebPageAssembler.php index 7e21818..ac1aaeb 100644 --- a/src/Black/Component/Page/Application/DTO/WebPageAssembler.php +++ b/src/Page/Application/DTO/WebPageAssembler.php @@ -1,23 +1,12 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Application\DTO; +namespace Black\Page\Application\DTO; -use Black\Component\Page\Domain\Model\WebPage; -use Black\Component\Page\Domain\Model\WebPageId; +use Black\Page\Domain\Model\WebPage; +use Black\Page\Domain\Model\WebPageId; /** * Class WebPageAssembler - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ class WebPageAssembler { @@ -38,7 +27,7 @@ class WebPageAssembler public function __construct($entityClass, $dtoClass) { $this->entityClass = $entityClass; - $this->dtoClass = $dtoClass; + $this->dtoClass = $dtoClass; } /** diff --git a/src/Black/Component/Page/Application/DTO/WebPageDTO.php b/src/Page/Application/DTO/WebPageDTO.php similarity index 80% rename from src/Black/Component/Page/Application/DTO/WebPageDTO.php rename to src/Page/Application/DTO/WebPageDTO.php index 1c72010..c2cdd34 100644 --- a/src/Black/Component/Page/Application/DTO/WebPageDTO.php +++ b/src/Page/Application/DTO/WebPageDTO.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace Black\Component\Page\Application\DTO; +namespace Black\Page\Application\DTO; /** * Class WebPageDTO @@ -78,16 +78,14 @@ final class WebPageDTO */ public function __construct($id, $author, $name = 'New WebPage!', $headline = null, $about = null, $text = null) { - $this->id = $id; - $this->author = $author; - $this->name = $name; - $this->headline = $headline; - $this->about = $about; - $this->text = $text; - $this->creator = $author; - $this->editor = $author; - $this->context = "http://schema.org"; - $this->type = "WebPage"; + $this->id = $id; + $this->author = $author; + $this->name = $name; + $this->headline = $headline; + $this->about = $about; + $this->text = $text; + $this->creator = $author; + $this->editor = $author; } /** @@ -154,22 +152,6 @@ public function getEditor() return $this->editor; } - /** - * @return string - */ - public function getContext() - { - return $this->context; - } - - /** - * @return string - */ - public function getType() - { - return $this->type; - } - /** * @return string */ @@ -184,8 +166,6 @@ public function serialize() $this->text, $this->creator, $this->editor, - $this->context, - $this->type, ]); } diff --git a/src/Black/Component/Page/Application/DTO/WriteWebPageAssembler.php b/src/Page/Application/DTO/WriteWebPageAssembler.php similarity index 72% rename from src/Black/Component/Page/Application/DTO/WriteWebPageAssembler.php rename to src/Page/Application/DTO/WriteWebPageAssembler.php index 84f78ff..510f224 100644 --- a/src/Black/Component/Page/Application/DTO/WriteWebPageAssembler.php +++ b/src/Page/Application/DTO/WriteWebPageAssembler.php @@ -1,18 +1,13 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Application\DTO; +namespace Black\Page\Application\DTO; -use Black\Component\Page\Domain\Model\WebPage; -use Black\Component\Page\Domain\Model\WebPageId; +use Black\Page\Domain\Model\WebPage; +use Black\Page\Domain\Model\WebPageId; +/** + * Class WriteWebPageAssembler + */ class WriteWebPageAssembler { /** @@ -32,7 +27,7 @@ class WriteWebPageAssembler public function __construct($entityClass, $dtoClass) { $this->entityClass = $entityClass; - $this->dtoClass = $dtoClass; + $this->dtoClass = $dtoClass; } /** diff --git a/src/Black/Component/Page/Application/DTO/WriteWebPageDTO.php b/src/Page/Application/DTO/WriteWebPageDTO.php similarity index 62% rename from src/Black/Component/Page/Application/DTO/WriteWebPageDTO.php rename to src/Page/Application/DTO/WriteWebPageDTO.php index 43a7911..9fe4b89 100644 --- a/src/Black/Component/Page/Application/DTO/WriteWebPageDTO.php +++ b/src/Page/Application/DTO/WriteWebPageDTO.php @@ -1,20 +1,9 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Application\DTO; +namespace Black\Page\Application\DTO; /** * Class WriteWebPage - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WriteWebPageDTO { @@ -56,12 +45,10 @@ final class WriteWebPageDTO */ public function __construct($id, $headline, $about, $text) { - $this->id = $id; - $this->headline = $headline; - $this->about = $about; - $this->text = $text; - $this->context = "http://schema.org"; - $this->type = "WebPage"; + $this->id = $id; + $this->headline = $headline; + $this->about = $about; + $this->text = $text; } /** @@ -96,22 +83,6 @@ public function getText() return $this->text; } - /** - * @return string - */ - public function getContext() - { - return $this->context; - } - - /** - * @return string - */ - public function getType() - { - return $this->type; - } - /** * @return string */ @@ -122,8 +93,6 @@ public function serialize() $this->headline, $this->about, $this->text, - $this->context, - $this->type, ]); } diff --git a/src/Black/Component/Page/Application/Service/WebPageReadService.php b/src/Page/Application/Service/WebPageReadService.php similarity index 64% rename from src/Black/Component/Page/Application/Service/WebPageReadService.php rename to src/Page/Application/Service/WebPageReadService.php index d0f3ab1..8f29768 100644 --- a/src/Black/Component/Page/Application/Service/WebPageReadService.php +++ b/src/Page/Application/Service/WebPageReadService.php @@ -1,21 +1,13 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Application\Service; +namespace Black\Page\Application\Service; use Black\Component\Common\Application\Specification\Specification; -use Black\Component\Page\Application\DTO\WebPageAssembler; -use Black\Component\Page\Application\DTO\WebPageDTO; -use Black\Component\Page\Application\Specification\PageIsPublishedSpecification; -use Black\Component\Page\Domain\Model\WebPage; -use Black\Component\Page\Infrastructure\Service\WebPageReadService as InfrastructureService; +use Black\Page\Application\DTO\WebPageAssembler; +use Black\Page\Application\DTO\WebPageDTO; +use Black\Page\Application\Specification\PageIsPublishedSpecification; +use Black\Page\Domain\Model\WebPage; +use Black\Page\Infrastructure\Service\WebPageReadService as InfrastructureService; class WebPageReadService { @@ -32,7 +24,7 @@ class WebPageReadService /** * @var */ - protected $transformer; + protected $assembler; /** * @param PageIsPublishedSpecification $specification @@ -45,8 +37,8 @@ public function __construct( WebPageAssembler $assembler ) { $this->specification = $specification; - $this->service = $service; - $this->assembler = $assembler; + $this->service = $service; + $this->assembler = $assembler; } /** @@ -72,6 +64,10 @@ public function readBySlug($slug) return $this->checkSatisfaction($page); } + /** + * @param WebPage $page + * @return mixed + */ private function checkSatisfaction(WebPage $page) { if (true === $this->specification->isSatisfiedBy($page)) { diff --git a/src/Page/Application/Specification/PageIsPublishedSpecification.php b/src/Page/Application/Specification/PageIsPublishedSpecification.php new file mode 100644 index 0000000..6e29c61 --- /dev/null +++ b/src/Page/Application/Specification/PageIsPublishedSpecification.php @@ -0,0 +1,21 @@ +isPublished(); + } +} diff --git a/src/Black/Component/Page/Domain/Event/WebPageCreatedEvent.php b/src/Page/Domain/Event/WebPageCreatedEvent.php similarity index 56% rename from src/Black/Component/Page/Domain/Event/WebPageCreatedEvent.php rename to src/Page/Domain/Event/WebPageCreatedEvent.php index 310c4c8..b47d51e 100644 --- a/src/Black/Component/Page/Domain/Event/WebPageCreatedEvent.php +++ b/src/Page/Domain/Event/WebPageCreatedEvent.php @@ -1,22 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Domain\Event; +namespace Black\Page\Domain\Event; use Symfony\Component\EventDispatcher\Event; /** * Class WebPageCreatedEvent - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WebPageCreatedEvent extends Event { @@ -37,7 +26,7 @@ final class WebPageCreatedEvent extends Event public function __construct($webPageId, $name) { $this->webPageId = $webPageId; - $this->name = $name; + $this->name = $name; } /** diff --git a/src/Black/Component/Page/Domain/Event/WebPageDepublishedEvent.php b/src/Page/Domain/Event/WebPageDepublishedEvent.php similarity index 57% rename from src/Black/Component/Page/Domain/Event/WebPageDepublishedEvent.php rename to src/Page/Domain/Event/WebPageDepublishedEvent.php index d8d0133..040ce02 100644 --- a/src/Black/Component/Page/Domain/Event/WebPageDepublishedEvent.php +++ b/src/Page/Domain/Event/WebPageDepublishedEvent.php @@ -1,22 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Domain\Event; +namespace Black\Page\Domain\Event; use Symfony\Component\EventDispatcher\Event; /** * Class WebPageDepublishedEvent - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WebPageDepublishedEvent extends Event { @@ -37,7 +26,7 @@ final class WebPageDepublishedEvent extends Event public function __construct($webPageId, $name) { $this->webPageId = $webPageId; - $this->name = $name; + $this->name = $name; } /** diff --git a/src/Black/Component/Page/Domain/Event/WebPagePublishedEvent.php b/src/Page/Domain/Event/WebPagePublishedEvent.php similarity index 57% rename from src/Black/Component/Page/Domain/Event/WebPagePublishedEvent.php rename to src/Page/Domain/Event/WebPagePublishedEvent.php index 711add3..0788f4e 100644 --- a/src/Black/Component/Page/Domain/Event/WebPagePublishedEvent.php +++ b/src/Page/Domain/Event/WebPagePublishedEvent.php @@ -1,22 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Domain\Event; +namespace Black\Page\Domain\Event; use Symfony\Component\EventDispatcher\Event; /** * Class WebPagePublishedEvent - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WebPagePublishedEvent extends Event { @@ -37,7 +26,7 @@ final class WebPagePublishedEvent extends Event public function __construct($webPageId, $name) { $this->webPageId = $webPageId; - $this->name = $name; + $this->name = $name; } /** diff --git a/src/Black/Component/Page/Domain/Event/WebPageRemovedEvent.php b/src/Page/Domain/Event/WebPageRemovedEvent.php similarity index 56% rename from src/Black/Component/Page/Domain/Event/WebPageRemovedEvent.php rename to src/Page/Domain/Event/WebPageRemovedEvent.php index ef2b3d1..53ede35 100644 --- a/src/Black/Component/Page/Domain/Event/WebPageRemovedEvent.php +++ b/src/Page/Domain/Event/WebPageRemovedEvent.php @@ -1,22 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Domain\Event; +namespace Black\Page\Domain\Event; use Symfony\Component\EventDispatcher\Event; /** * Class WebPageRemovedEvent - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WebPageRemovedEvent extends Event { @@ -37,7 +26,7 @@ final class WebPageRemovedEvent extends Event public function __construct($webPageId, $name) { $this->webPageId = $webPageId; - $this->name = $name; + $this->name = $name; } /** diff --git a/src/Black/Component/Page/Domain/Event/WebPageWritedEvent.php b/src/Page/Domain/Event/WebPageWritedEvent.php similarity index 56% rename from src/Black/Component/Page/Domain/Event/WebPageWritedEvent.php rename to src/Page/Domain/Event/WebPageWritedEvent.php index 4ddec18..a0e3f65 100644 --- a/src/Black/Component/Page/Domain/Event/WebPageWritedEvent.php +++ b/src/Page/Domain/Event/WebPageWritedEvent.php @@ -1,22 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Domain\Event; +namespace Black\Page\Domain\Event; use Symfony\Component\EventDispatcher\Event; /** * Class WebPageWritedEvent - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WebPageWritedEvent extends Event { @@ -37,7 +26,7 @@ final class WebPageWritedEvent extends Event public function __construct($webPageId, $name) { $this->webPageId = $webPageId; - $this->name = $name; + $this->name = $name; } /** diff --git a/src/Black/Component/Page/Domain/Exception/WebPageNotFoundException.php b/src/Page/Domain/Exception/WebPageNotFoundException.php similarity index 58% rename from src/Black/Component/Page/Domain/Exception/WebPageNotFoundException.php rename to src/Page/Domain/Exception/WebPageNotFoundException.php index 2b2316e..fb77f7f 100644 --- a/src/Black/Component/Page/Domain/Exception/WebPageNotFoundException.php +++ b/src/Page/Domain/Exception/WebPageNotFoundException.php @@ -1,23 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Domain\Exception; +namespace Black\Page\Domain\Exception; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class WebPageNotFoundException - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WebPageNotFoundException extends NotFoundHttpException { diff --git a/src/Black/Component/Page/Domain/Listener/LoggerListener.php b/src/Page/Domain/Listener/LoggerListener.php similarity index 62% rename from src/Black/Component/Page/Domain/Listener/LoggerListener.php rename to src/Page/Domain/Listener/LoggerListener.php index 327c8ae..6b93463 100644 --- a/src/Black/Component/Page/Domain/Listener/LoggerListener.php +++ b/src/Page/Domain/Listener/LoggerListener.php @@ -1,8 +1,8 @@ 'addInfoLog', - WebPageDomainEvents::WEBPAGE_DOMAIN_DEPUBLISHED => 'addInfoLog', - WebPageDomainEvents::WEBPAGE_DOMAIN_PUBLISHED => 'addInfoLog', - WebPageDomainEvents::WEBPAGE_DOMAIN_REMOVED => 'addInfoLog', - WebPageDomainEvents::WEBPAGE_DOMAIN_WRITE => 'addInfoLog', + WebPageEvents::WEBPAGE_DOMAIN_CREATED => 'addInfoLog', + WebPageEvents::WEBPAGE_DOMAIN_DEPUBLISHED => 'addInfoLog', + WebPageEvents::WEBPAGE_DOMAIN_PUBLISHED => 'addInfoLog', + WebPageEvents::WEBPAGE_DOMAIN_REMOVED => 'addInfoLog', + WebPageEvents::WEBPAGE_DOMAIN_WRITE => 'addInfoLog', ]; } diff --git a/src/Black/Component/Page/Domain/Model/WebPage.php b/src/Page/Domain/Model/WebPage.php similarity index 75% rename from src/Black/Component/Page/Domain/Model/WebPage.php rename to src/Page/Domain/Model/WebPage.php index 6f9533b..d49cba1 100644 --- a/src/Black/Component/Page/Domain/Model/WebPage.php +++ b/src/Page/Domain/Model/WebPage.php @@ -1,23 +1,9 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Domain\Model; +namespace Black\Page\Domain\Model; /** * Class WebPage - * - * A web page. Every web page is implicitly assumed to be declared to be of type WebPage. - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ class WebPage { @@ -84,11 +70,11 @@ class WebPage */ public function __construct(WebPageId $id, $author, $name, $slug) { - $this->webPageId = $id; - $this->name = $name; - $this->slug = $slug; - $this->author = $author; - $this->dateCreated = new \DateTime(); + $this->webPageId = $id; + $this->name = $name; + $this->slug = $slug; + $this->author = $author; + $this->dateCreated = new \DateTime(); $this->dateModified = new \DateTime(); } @@ -187,9 +173,9 @@ public function isPublished() */ public function write($headline, $about, $text) { - $this->headline = $headline; - $this->about = $about; - $this->text = $text; + $this->headline = $headline; + $this->about = $about; + $this->text = $text; $this->dateModified = new \DateTime(); } @@ -217,10 +203,10 @@ public function depublish() */ public function edit($name, $headline, $about, $text) { - $this->name = $name; - $this->headline = $headline; - $this->about = $about; - $this->text = $text; + $this->name = $name; + $this->headline = $headline; + $this->about = $about; + $this->text = $text; $this->dateModified = new \DateTime(); } } diff --git a/src/Black/Component/Page/Domain/Model/WebPageId.php b/src/Page/Domain/Model/WebPageId.php similarity index 62% rename from src/Black/Component/Page/Domain/Model/WebPageId.php rename to src/Page/Domain/Model/WebPageId.php index 3b70840..c36de53 100644 --- a/src/Black/Component/Page/Domain/Model/WebPageId.php +++ b/src/Page/Domain/Model/WebPageId.php @@ -1,20 +1,9 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Domain\Model; +namespace Black\Page\Domain\Model; /** * Class WebPageId - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WebPageId { diff --git a/src/Page/Domain/Repository/WebPageRepository.php b/src/Page/Domain/Repository/WebPageRepository.php new file mode 100644 index 0000000..083e6c8 --- /dev/null +++ b/src/Page/Domain/Repository/WebPageRepository.php @@ -0,0 +1,23 @@ +getPath().'/Resources/config/doctrine/model') => 'Black\Page\Domain\Model', + ); + + $ormCompilerClass = 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass'; + + if (class_exists($ormCompilerClass)) { + $container->addCompilerPass( + DoctrineOrmMappingsPass::createXmlMappingDriver( + $mappings, + [], + 'black_page.backend_type_orm' + )); + } + + $mongoCompilerClass = 'Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass'; + + if (class_exists($mongoCompilerClass)) { + $container->addCompilerPass( + DoctrineMongoDBMappingsPass::createXmlMappingDriver( + $mappings, + [], + 'black_page.backend_type_mongodb' + )); + } + } + + /** + * {@inheritdoc} + */ + public function registerCommands(Application $application) + { + return; + } +} diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/DependencyInjection/BlackPageExtension.php b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/DependencyInjection/BlackPageExtension.php new file mode 100644 index 0000000..637676d --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/DependencyInjection/BlackPageExtension.php @@ -0,0 +1,112 @@ +getAlias()); + $config = $processor->processConfiguration($configuration, $configs); + + $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../Resources/config')); + + if (!isset($config['db_driver'])) { + throw new \InvalidArgumentException('You must provide the black_page.db_driver configuration'); + } + + try { + $loader->load(sprintf('%s.xml', $config['db_driver'])); + } catch (\InvalidArgumentException $e) { + throw new \InvalidArgumentException( + sprintf('The db_driver "%s" is not supported by engine', $config['db_driver']) + ); + } + + $container->setParameter($this->getAlias() . '.backend_type_' . $config['db_driver'], true); + + $this->remapParametersNamespaces($config, $container, [ + '' => [ + 'page_class' => 'black_page.webpage.model.class', + ] + ]); + + foreach ( + [ + 'application_service', + 'controller', + 'cqrs', + 'domain_event', + 'dto', + 'infrastructure_service', + 'specification', + ] as $basename + ) { + $loader->load(sprintf('%s.xml', $basename)); + } + } + + /** + * {@inheritdoc} + * + * @return string + */ + public function getAlias() + { + return 'black_page'; + } + + /** + * @param array $config + * @param ContainerBuilder $container + * @param array $map + */ + protected function remapParameters(array $config, ContainerBuilder $container, array $map) + { + foreach ($map as $name => $paramName) { + if (array_key_exists($name, $config)) { + $container->setParameter($paramName, $config[$name]); + } + } + } + + /** + * @param array $config + * @param ContainerBuilder $container + * @param array $namespaces + */ + protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces) + { + foreach ($namespaces as $ns => $map) { + if ($ns) { + if (!array_key_exists($ns, $config)) { + continue; + } + $namespaceConfig = $config[$ns]; + } else { + $namespaceConfig = $config; + } + + if (is_array($map)) { + $this->remapParameters($namespaceConfig, $container, $map); + } else { + foreach ($namespaceConfig as $name => $value) { + $container->setParameter(sprintf($map, $name), $value); + } + } + } + } +} diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/DependencyInjection/Configuration.php b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/DependencyInjection/Configuration.php new file mode 100644 index 0000000..8a17cd7 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/DependencyInjection/Configuration.php @@ -0,0 +1,52 @@ +alias = $alias; + } + + /** + * {@inheritDoc} + */ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root($this->alias); + + $supportedDrivers = ['mongodb', 'orm']; + + $rootNode + ->children() + + ->scalarNode('db_driver') + ->validate() + ->ifNotInArray($supportedDrivers) + ->thenInvalid('The database driver %s is not supported. Please choose one of ' . json_encode($supportedDrivers)) + ->end() + ->isRequired() + ->cannotBeOverwritten() + ->cannotBeEmpty() + ->end() + + ->scalarNode('page_class')->isRequired()->cannotBeEmpty()->end() + ->end(); + + return $treeBuilder; + } +} diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Listener/FlashNoticeListener.php b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Listener/FlashNoticeListener.php new file mode 100644 index 0000000..a23ea54 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Listener/FlashNoticeListener.php @@ -0,0 +1,84 @@ + 'black_page.flash.success.created', + WebPageDomainEvents::WEBPAGE_DOMAIN_DEPUBLISHED => 'black_page.flash.success.depublished', + WebPageDomainEvents::WEBPAGE_DOMAIN_PUBLISHED => 'black_page.flash.success.published', + WebPageDomainEvents::WEBPAGE_DOMAIN_REMOVED => 'black_page.flash.success.removed', + WebPageDomainEvents::WEBPAGE_DOMAIN_WRITE => 'black_page.flash.success.write', + ]; + + /** + * FlashNoticeListener constructor. + * + * @param Session $session + * @param TranslatorInterface $translator + */ + public function __construct(Session $session, TranslatorInterface $translator) + { + $this->session = $session; + $this->translator = $translator; + } + + /** + * @return array + */ + public static function getSubscribedEvents() + { + return [ + WebPageDomainEvents::WEBPAGE_DOMAIN_CREATED => 'addSuccessFlash', + WebPageDomainEvents::WEBPAGE_DOMAIN_DEPUBLISHED => 'addSuccessFlash', + WebPageDomainEvents::WEBPAGE_DOMAIN_PUBLISHED => 'addSuccessFlash', + WebPageDomainEvents::WEBPAGE_DOMAIN_REMOVED => 'addSuccessFlash', + WebPageDomainEvents::WEBPAGE_DOMAIN_WRITE => 'addSuccessFlash', + ]; + } + + /** + * @param Event $event + */ + public function addSuccessFlash(Event $event) + { + if (!isset(self::$successMessages[$event->getName()])) { + throw new \InvalidArgumentException('This event does not correspond to a known flash message'); + } + $this->session->getFlashBag()->add('success', $this->trans(self::$successMessages[$event->getName()])); + } + + /** + * @param $message + * @param array $params + * @return string + */ + private function trans($message, array $params = array()) + { + return $this->translator->trans($message, $params, 'flash'); + } +} diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/application_service.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/application_service.xml new file mode 100644 index 0000000..e5b01c6 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/application_service.xml @@ -0,0 +1,20 @@ + + + + + + Black\Page\Application\Service\WebPageReadService + + + + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/controller.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/controller.xml new file mode 100644 index 0000000..1ce9756 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/controller.xml @@ -0,0 +1,48 @@ + + + + + + Black\Page\Application\Controller\CreatePageController + Black\Page\Application\Controller\WritePageController + Black\Page\Application\Controller\ReadPageController + Black\Page\Application\Controller\PublishPageController + Black\Page\Application\Controller\RemovePageController + + + + + + + + + %black_page.infrastructure.cqrs.command.create_web_page.class% + + + + + + %black_page.infrastructure.cqrs.command.write_web_page.class% + + + + + + %black_page.infrastructure.cqrs.command.publish_web_page.class% + + + + + + %black_page.infrastructure.cqrs.command.remove_web_page.class% + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/cqrs.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/cqrs.xml new file mode 100644 index 0000000..12f3378 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/cqrs.xml @@ -0,0 +1,59 @@ + + + + + + Black\Page\Infrastructure\Persistence\CQRS\WriteRepository + Black\Page\Infrastructure\Persistence\CQRS\ReadRepository + + Black\Page\Infrastructure\CQRS\Handler\CreateWebPageHandler + Black\Page\Infrastructure\CQRS\Handler\WriteWebPageHandler + Black\Page\Infrastructure\CQRS\Handler\PublishWebPageHandler + Black\Page\Infrastructure\CQRS\Handler\DepublishWebPageHandler + Black\Page\Infrastructure\CQRS\Handler\RemoveWebPageHandler + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPage.mongodb.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPage.mongodb.xml new file mode 100644 index 0000000..cb28f5d --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPage.mongodb.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPage.orm.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPage.orm.xml new file mode 100644 index 0000000..6e9405e --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPage.orm.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPageId.mongodb.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPageId.mongodb.xml new file mode 100644 index 0000000..9a32506 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPageId.mongodb.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPageId.orm.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPageId.orm.xml new file mode 100644 index 0000000..a42fd4f --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/doctrine/model/WebPageId.orm.xml @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/domain_event.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/domain_event.xml new file mode 100644 index 0000000..a0bd7a2 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/domain_event.xml @@ -0,0 +1,28 @@ + + + + + + Black\Page\Domain\Listener\LoggerListener + Black\Bundle\PageBundle\Listener\FlashNoticeListener + + + + + + + + + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/dto.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/dto.xml new file mode 100644 index 0000000..75a92ab --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/dto.xml @@ -0,0 +1,37 @@ + + + + + + Black\Page\Application\DTO\WebPageDTO + Black\Page\Application\DTO\CreateWebPageDTO + Black\Page\Application\DTO\WriteWebPageDTO + Black\Page\Application\DTO\WebPageAssembler + Black\Page\Application\DTO\CreateWebPageAssembler + Black\Page\Application\DTO\WriteWebPageAssembler + + + + + + + + + %black_page.webpage.model.class% + %black_page.application.dto.webpage.class% + + + + %black_page.webpage.model.class% + %black_page.application.dto.create_webpage.class% + + + + %black_page.webpage.model.class% + %black_page.application.dto.write_webpage.class% + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/infrastructure_service.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/infrastructure_service.xml new file mode 100644 index 0000000..7ec8b2b --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/infrastructure_service.xml @@ -0,0 +1,23 @@ + + + + + + Black\Page\Infrastructure\Service\WebPageReadService + Black\Page\Infrastructure\Service\WebPageWriteService + + + + + + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/mongodb.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/mongodb.xml new file mode 100644 index 0000000..0e8255e --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/mongodb.xml @@ -0,0 +1,25 @@ + + + + + + Black\Page\Infrastructure\Persistence\DoctrineMongoDBRepository + + + + + + + %black_page.webpage.model.class% + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/orm.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/orm.xml new file mode 100644 index 0000000..64c209c --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/orm.xml @@ -0,0 +1,27 @@ + + + + + + Black\Page\Infrastructure\Persistence\DoctrineORMRepository + + + + + + + %black_page.webpage.model.class% + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/specification.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/specification.xml new file mode 100644 index 0000000..dc5dcd6 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/specification.xml @@ -0,0 +1,16 @@ + + + + + + Black\Page\Application\Specification\PageIsPublishedSpecification + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/validation.xml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/validation.xml new file mode 100644 index 0000000..ac2be71 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/config/validation.xml @@ -0,0 +1,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/dto.en.yml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/dto.en.yml new file mode 100644 index 0000000..2880f5d --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/dto.en.yml @@ -0,0 +1,37 @@ +black: + bundle: + page: + domain: + dto: + webPageDto: + + author: + validation: + message: + type: This value should be of type "{{ type }}" + length: This value is too long. It should have {{ limit }} characters or less + notblank: This value should not be blank + + name: + validation: + message: + type: This value should be of type "{{ type }}" + length: This value is too long. It should have {{ limit }} characters or less + notblank: This value should not be blank + + headline: + validation: + message: + type: This value should be of type "{{ type }}" + length: This value is too long. It should have {{ limit }} characters or less + notblank: This value should not be blank + + about: + validation: + message: + type: This value should be of type "{{ type }}" + + text: + validation: + message: + type: This value should be of type "{{ type }}" diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/dto.fr.yml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/dto.fr.yml new file mode 100644 index 0000000..e4ea291 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/dto.fr.yml @@ -0,0 +1,36 @@ +black: + bundle: + page: + domain: + dto: + webPageDto: + author: + validation: + message: + type: Cette valeur doit être de type "{{ type }}" + length: Le texte ne doit pas exceder {{ limit }} caractères + notblank: La valeur ne doit pas être vide ou null + + name: + validation: + message: + type: Cette valeur doit être de type "{{ type }}" + length: Le texte ne doit pas exceder {{ limit }} caractères + notblank: La valeur ne doit pas être vide ou null + + headline: + validation: + message: + type: Cette valeur doit être de type "{{ type }}" + length: Le texte ne doit pas exceder {{ limit }} caractères + notblank: La valeur ne doit pas être vide ou null + + about: + validation: + message: + type: Cette valeur doit être de type "{{ type }}" + + text: + validation: + message: + type: Cette valeur doit être de type "{{ type }}" diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/flash.en.yml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/flash.en.yml new file mode 100644 index 0000000..4d5fafe --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/flash.en.yml @@ -0,0 +1,5 @@ +black_page.flash.success.created: Page has been successfuly created +black_page.flash.success.depublished: Page has been successfuly depublished +black_page.flash.success.published: Page has been successfuly published +black_page.flash.success.removed: Page has been successfuly removed +black_page.flash.success.write: Page has been updated diff --git a/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/flash.fr.yml b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/flash.fr.yml new file mode 100644 index 0000000..3e23669 --- /dev/null +++ b/src/Page/Infrastructure/Bridge/Symfony/PageBundle/Resources/translations/flash.fr.yml @@ -0,0 +1,5 @@ +black_page.flash.success.created: La page a bien été créée +black_page.flash.success.depublished: La page est maintenant un brouillon +black_page.flash.success.published: La page a bien été publiée +black_page.flash.success.removed: La page a bien été suprimée +black_page.flash.success.write: La page a bien été modifié diff --git a/src/Black/Component/Page/Infrastructure/CQRS/Command/CreateWebPageCommand.php b/src/Page/Infrastructure/CQRS/Command/CreateWebPageCommand.php similarity index 58% rename from src/Black/Component/Page/Infrastructure/CQRS/Command/CreateWebPageCommand.php rename to src/Page/Infrastructure/CQRS/Command/CreateWebPageCommand.php index 6d8dbf5..92d7fc5 100644 --- a/src/Black/Component/Page/Infrastructure/CQRS/Command/CreateWebPageCommand.php +++ b/src/Page/Infrastructure/CQRS/Command/CreateWebPageCommand.php @@ -1,28 +1,17 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\CQRS\Command; +namespace Black\Page\Infrastructure\CQRS\Command; -use Black\Component\Page\Domain\Model\WebPageId; +use Black\Page\Domain\Model\WebPageId; use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Command; /** * Class CreateWebPageCommand - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class CreateWebPageCommand implements Command { /** - * @var \Black\Component\Page\Domain\Model\WebPageId + * @var WebPageId */ private $webPageId; @@ -44,8 +33,8 @@ final class CreateWebPageCommand implements Command public function __construct(WebPageId $webPageId, $author, $name) { $this->webPageId = $webPageId; - $this->author = $author; - $this->name = $name; + $this->author = $author; + $this->name = $name; } /** diff --git a/src/Black/Component/Page/Infrastructure/CQRS/Command/DepublishWebPageCommand.php b/src/Page/Infrastructure/CQRS/Command/DepublishWebPageCommand.php similarity index 50% rename from src/Black/Component/Page/Infrastructure/CQRS/Command/DepublishWebPageCommand.php rename to src/Page/Infrastructure/CQRS/Command/DepublishWebPageCommand.php index d704879..40306d1 100644 --- a/src/Black/Component/Page/Infrastructure/CQRS/Command/DepublishWebPageCommand.php +++ b/src/Page/Infrastructure/CQRS/Command/DepublishWebPageCommand.php @@ -1,23 +1,12 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\CQRS\Command; +namespace Black\Page\Infrastructure\CQRS\Command; -use Black\Component\Page\Domain\Model\WebPage; +use Black\Page\Domain\Model\WebPage; use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Command; /** * Class DepublishWebPageCommand - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class DepublishWebPageCommand implements Command { diff --git a/src/Black/Component/Page/Infrastructure/CQRS/Command/PublishWebPageCommand.php b/src/Page/Infrastructure/CQRS/Command/PublishWebPageCommand.php similarity index 50% rename from src/Black/Component/Page/Infrastructure/CQRS/Command/PublishWebPageCommand.php rename to src/Page/Infrastructure/CQRS/Command/PublishWebPageCommand.php index bd6b0b2..ddef3ef 100644 --- a/src/Black/Component/Page/Infrastructure/CQRS/Command/PublishWebPageCommand.php +++ b/src/Page/Infrastructure/CQRS/Command/PublishWebPageCommand.php @@ -1,23 +1,12 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\CQRS\Command; +namespace Black\Page\Infrastructure\CQRS\Command; -use Black\Component\Page\Domain\Model\WebPage; +use Black\Page\Domain\Model\WebPage; use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Command; /** * Class PublishWebPageCommand - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class PublishWebPageCommand implements Command { diff --git a/src/Page/Infrastructure/CQRS/Command/RemoveWebPageCommand.php b/src/Page/Infrastructure/CQRS/Command/RemoveWebPageCommand.php new file mode 100644 index 0000000..84bfb39 --- /dev/null +++ b/src/Page/Infrastructure/CQRS/Command/RemoveWebPageCommand.php @@ -0,0 +1,33 @@ +webPage = $webPage; + } + + /** + * @return mixed + */ + public function getWebPage() + { + return $this->webPage; + } +} diff --git a/src/Black/Component/Page/Infrastructure/CQRS/Command/WriteWebPageCommand.php b/src/Page/Infrastructure/CQRS/Command/WriteWebPageCommand.php similarity index 69% rename from src/Black/Component/Page/Infrastructure/CQRS/Command/WriteWebPageCommand.php rename to src/Page/Infrastructure/CQRS/Command/WriteWebPageCommand.php index bedbaca..2b98d7c 100644 --- a/src/Black/Component/Page/Infrastructure/CQRS/Command/WriteWebPageCommand.php +++ b/src/Page/Infrastructure/CQRS/Command/WriteWebPageCommand.php @@ -1,28 +1,17 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\CQRS\Command; +namespace Black\Page\Infrastructure\CQRS\Command; -use Black\Component\Page\Domain\Model\WebPageId; +use Black\Page\Domain\Model\WebPageId; use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Command; /** * Class WriteWebPageCommand - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WriteWebPageCommand implements Command { /** - * @var \Black\Component\Page\Domain\Model\WebPage + * @var WebPageId */ private $webPageId; @@ -43,6 +32,7 @@ final class WriteWebPageCommand implements Command /** * WriteWebPageCommand constructor. + * * @param WebPageId $webPageId * @param $headline * @param $about diff --git a/src/Page/Infrastructure/CQRS/Handler/CreateWebPageHandler.php b/src/Page/Infrastructure/CQRS/Handler/CreateWebPageHandler.php new file mode 100644 index 0000000..d9029ce --- /dev/null +++ b/src/Page/Infrastructure/CQRS/Handler/CreateWebPageHandler.php @@ -0,0 +1,60 @@ +service = $service; + $this->repository = $repository; + $this->eventDispatcher = $eventDispatcher; + } + + /** + * @param Command $command + */ + public function handle(Command $command) + { + $page = $this->service->create($command->getWebPageId(), $command->getAuthor(), $command->getName()); + + $event = new WebPageCreatedEvent($page->getWebPageId()->getValue(), $page->getName()); + $this->eventDispatcher->dispatch(WebPageEvents::WEBPAGE_DOMAIN_CREATED, $event); + } +} diff --git a/src/Page/Infrastructure/CQRS/Handler/DepublishWebPageHandler.php b/src/Page/Infrastructure/CQRS/Handler/DepublishWebPageHandler.php new file mode 100644 index 0000000..b1aaa77 --- /dev/null +++ b/src/Page/Infrastructure/CQRS/Handler/DepublishWebPageHandler.php @@ -0,0 +1,60 @@ +service = $service; + $this->repository = $repository; + $this->eventDispatcher = $eventDispatcher; + } + + /** + * @param Command $command + */ + public function handle(Command $command) + { + $page = $this->service->depublish($command->getWebPage()); + + $event = new WebPageDepublishedEvent($page->getWebPageId()->getValue(), $page->getName()); + $this->eventDispatcher->dispatch(WebPageEvents::WEBPAGE_DOMAIN_DEPUBLISHED, $event); + } +} diff --git a/src/Page/Infrastructure/CQRS/Handler/PublishWebPageHandler.php b/src/Page/Infrastructure/CQRS/Handler/PublishWebPageHandler.php new file mode 100644 index 0000000..945e0da --- /dev/null +++ b/src/Page/Infrastructure/CQRS/Handler/PublishWebPageHandler.php @@ -0,0 +1,60 @@ +service = $service; + $this->repository = $repository; + $this->eventDispatcher = $eventDispatcher; + } + + /** + * @param Command $command + */ + public function handle(Command $command) + { + $page = $this->service->publish($command->getWebPage()); + + $event = new WebPagePublishedEvent($page->getWebPageId()->getValue(), $page->getName()); + $this->eventDispatcher->dispatch(WebPageEvents::WEBPAGE_DOMAIN_PUBLISHED, $event); + } +} diff --git a/src/Page/Infrastructure/CQRS/Handler/RemoveWebPageHandler.php b/src/Page/Infrastructure/CQRS/Handler/RemoveWebPageHandler.php new file mode 100644 index 0000000..d975faa --- /dev/null +++ b/src/Page/Infrastructure/CQRS/Handler/RemoveWebPageHandler.php @@ -0,0 +1,60 @@ +service = $service; + $this->repository = $repository; + $this->eventDispatcher = $eventDispatcher; + } + + /** + * @param Command $command + */ + public function handle(Command $command) + { + $page = $this->service->remove($command->getWebPage()); + + $event = new WebPageRemovedEvent($page->getWebPageId()->getValue(), $page->getName()); + $this->eventDispatcher->dispatch(WebPageEvents::WEBPAGE_DOMAIN_REMOVED, $event); + } +} diff --git a/src/Black/Component/Page/Infrastructure/CQRS/Handler/WriteWebPageHandler.php b/src/Page/Infrastructure/CQRS/Handler/WriteWebPageHandler.php similarity index 52% rename from src/Black/Component/Page/Infrastructure/CQRS/Handler/WriteWebPageHandler.php rename to src/Page/Infrastructure/CQRS/Handler/WriteWebPageHandler.php index 871ba5b..8f238fc 100644 --- a/src/Black/Component/Page/Infrastructure/CQRS/Handler/WriteWebPageHandler.php +++ b/src/Page/Infrastructure/CQRS/Handler/WriteWebPageHandler.php @@ -1,30 +1,19 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\CQRS\Handler; +namespace Black\Page\Infrastructure\CQRS\Handler; -use Black\Component\Page\Domain\Model\WebPageId; -use Black\Component\Page\Domain\Model\WebPageWriteRepository; -use Black\Component\Page\Infrastructure\CQRS\Command\WriteWebPageCommand; -use Black\Component\Page\Domain\Event\WebPageWritedEvent; -use Black\Component\Page\Infrastructure\Service\WebPageReadService; -use Black\Component\Page\Infrastructure\Service\WebPageWriteService; -use Black\Component\Page\WebPageDomainEvents; +use Black\DDD\CQRSinPHP\Infrastructure\CQRS\Command; +use Black\Page\Domain\Model\WebPageId; +use Black\Page\Domain\Event\WebPageWritedEvent; +use Black\Page\Infrastructure\Persistence\CQRS\WriteRepository; +use Black\Page\Infrastructure\Service\WebPageReadService; +use Black\Page\Infrastructure\Service\WebPageWriteService; +use Black\Page\WebPageEvents; use Black\DDD\CQRSinPHP\Infrastructure\CQRS\CommandHandler; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Class WriteWebPageHandler - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ final class WriteWebPageHandler implements CommandHandler { @@ -39,7 +28,7 @@ final class WriteWebPageHandler implements CommandHandler protected $writeService; /** - * @var WebPageWriteRepository + * @var WriteRepository */ protected $repository; @@ -50,28 +39,28 @@ final class WriteWebPageHandler implements CommandHandler /** * WriteWebPageHandler constructor. + * * @param WebPageReadService $readService * @param WebPageWriteService $writeService - * @param WebPageWriteRepository $repository + * @param WriteRepository $repository * @param EventDispatcherInterface $eventDispatcher */ public function __construct( WebPageReadService $readService, WebPageWriteService $writeService, - WebPageWriteRepository $repository, + WriteRepository $repository, EventDispatcherInterface $eventDispatcher ) { $this->readService = $readService; $this->writeService = $writeService; - $this->repository = $repository; + $this->repository = $repository; $this->eventDispatcher = $eventDispatcher; } /** - * @param WriteWebPageCommand $command - * @return mixed + * @param Command $command */ - public function handle(WriteWebPageCommand $command) + public function handle(Command $command) { $page = $this->readService->read($command->getWebPageId()); $page = $this->writeService->write( @@ -81,9 +70,7 @@ public function handle(WriteWebPageCommand $command) $command->getText() ); - $this->repository->flush(); - $event = new WebPageWritedEvent($page->getWebPageId()->getValue(), $page->getName()); - $this->eventDispatcher->dispatch(WebPageDomainEvents::WEBPAGE_DOMAIN_WRITE, $event); + $this->eventDispatcher->dispatch(WebPageEvents::WEBPAGE_DOMAIN_WRITE, $event); } } diff --git a/src/Black/Component/Page/Infrastructure/Listener/WebPageCreatedListener.php b/src/Page/Infrastructure/Listener/WebPageCreatedListener.php similarity index 61% rename from src/Black/Component/Page/Infrastructure/Listener/WebPageCreatedListener.php rename to src/Page/Infrastructure/Listener/WebPageCreatedListener.php index da06f4d..fe819a8 100644 --- a/src/Black/Component/Page/Infrastructure/Listener/WebPageCreatedListener.php +++ b/src/Page/Infrastructure/Listener/WebPageCreatedListener.php @@ -1,27 +1,19 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\Listener; +namespace Black\Page\Infrastructure\Listener; -use Black\Component\Page\Domain\Event\WebPageCreatedEvent; +use Black\Page\Domain\Event\WebPageCreatedEvent; use Monolog\Logger; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Class WebPageCreatedListener - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ class WebPageCreatedListener implements EventSubscriberInterface { + /** + * @var Logger + */ protected $logger; /** diff --git a/src/Black/Component/Page/Infrastructure/Listener/WebPageDepublishedListener.php b/src/Page/Infrastructure/Listener/WebPageDepublishedListener.php similarity index 61% rename from src/Black/Component/Page/Infrastructure/Listener/WebPageDepublishedListener.php rename to src/Page/Infrastructure/Listener/WebPageDepublishedListener.php index 5de0488..2a0f46d 100644 --- a/src/Black/Component/Page/Infrastructure/Listener/WebPageDepublishedListener.php +++ b/src/Page/Infrastructure/Listener/WebPageDepublishedListener.php @@ -1,27 +1,21 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\Listener; +namespace Black\Page\Infrastructure\Listener; -use Black\Component\Page\Domain\Event\WebPageDepublishedEvent; +use Black\Page\Domain\Event\WebPageDepublishedEvent; use Monolog\Logger; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Class WebPageDepublishedListener - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ class WebPageDepublishedListener implements EventSubscriberInterface { + /** + * @var Logger + */ + protected $logger; + /** * @param Logger $logger */ diff --git a/src/Black/Component/Page/Infrastructure/Listener/WebPagePublishedListener.php b/src/Page/Infrastructure/Listener/WebPagePublishedListener.php similarity index 60% rename from src/Black/Component/Page/Infrastructure/Listener/WebPagePublishedListener.php rename to src/Page/Infrastructure/Listener/WebPagePublishedListener.php index 95badf5..5602026 100644 --- a/src/Black/Component/Page/Infrastructure/Listener/WebPagePublishedListener.php +++ b/src/Page/Infrastructure/Listener/WebPagePublishedListener.php @@ -1,27 +1,21 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\Listener; +namespace Black\Page\Infrastructure\Listener; -use Black\Component\Page\Domain\Event\WebPagePublishedEvent; +use Black\Page\Domain\Event\WebPagePublishedEvent; use Monolog\Logger; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Class WebPagePublishedListener - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ class WebPagePublishedListener implements EventSubscriberInterface { + /** + * @var Logger + */ + protected $logger; + /** * @param Logger $logger */ diff --git a/src/Black/Component/Page/Infrastructure/Listener/WebPageRemovedListener.php b/src/Page/Infrastructure/Listener/WebPageRemovedListener.php similarity index 60% rename from src/Black/Component/Page/Infrastructure/Listener/WebPageRemovedListener.php rename to src/Page/Infrastructure/Listener/WebPageRemovedListener.php index e596c59..25dc7cb 100644 --- a/src/Black/Component/Page/Infrastructure/Listener/WebPageRemovedListener.php +++ b/src/Page/Infrastructure/Listener/WebPageRemovedListener.php @@ -1,27 +1,21 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\Listener; +namespace Black\Page\Infrastructure\Listener; -use Black\Component\Page\Domain\Event\WebPageRemovedEvent; +use Black\Page\Domain\Event\WebPageRemovedEvent; use Monolog\Logger; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Class WebPageRemovedListener - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ class WebPageRemovedListener implements EventSubscriberInterface { + /** + * @var Logger + */ + protected $logger; + /** * @param Logger $logger */ diff --git a/src/Black/Component/Page/Infrastructure/Listener/WebPageWritedListener.php b/src/Page/Infrastructure/Listener/WebPageWritedListener.php similarity index 60% rename from src/Black/Component/Page/Infrastructure/Listener/WebPageWritedListener.php rename to src/Page/Infrastructure/Listener/WebPageWritedListener.php index 1371a6b..b62c93e 100644 --- a/src/Black/Component/Page/Infrastructure/Listener/WebPageWritedListener.php +++ b/src/Page/Infrastructure/Listener/WebPageWritedListener.php @@ -1,27 +1,21 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\Listener; +namespace Black\Page\Infrastructure\Listener; -use Black\Component\Page\Domain\Event\WebPageWritedEvent; +use Black\Page\Domain\Event\WebPageWritedEvent; use Monolog\Logger; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** * Class WebPageWritedListener - * - * @author Alexandre 'pocky' Balmes - * @license http://opensource.org/licenses/mit-license.php MIT */ class WebPageWritedListener implements EventSubscriberInterface { + /** + * @var Logger + */ + protected $logger; + /** * @param Logger $logger */ diff --git a/src/Page/Infrastructure/Persistence/CQRS/ReadRepository.php b/src/Page/Infrastructure/Persistence/CQRS/ReadRepository.php new file mode 100644 index 0000000..e072586 --- /dev/null +++ b/src/Page/Infrastructure/Persistence/CQRS/ReadRepository.php @@ -0,0 +1,44 @@ +repository = $repository; + } + + /** + * @param WebPageId $id + * @return mixed + */ + public function find(WebPageId $id) + { + return $this->repository->find($id); + } + + /** + * @return mixed + */ + public function findAll() + { + return $this->repository->findAll(); + } +} diff --git a/src/Page/Infrastructure/Persistence/CQRS/WriteRepository.php b/src/Page/Infrastructure/Persistence/CQRS/WriteRepository.php new file mode 100644 index 0000000..419733f --- /dev/null +++ b/src/Page/Infrastructure/Persistence/CQRS/WriteRepository.php @@ -0,0 +1,43 @@ +repository = $repository; + } + + /** + * @param WebPage $webpage + */ + public function add(WebPage $webpage) + { + $this->repository->add($webpage); + } + + /** + * @param WebPage $webpage + */ + public function update(WebPage $webpage) + { + $this->repository->update($webpage); + } +} diff --git a/src/Black/Component/Page/Infrastructure/Persistence/MongoDB/ReadRepository.php b/src/Page/Infrastructure/Persistence/DoctrineMongoDBRepository.php similarity index 50% rename from src/Black/Component/Page/Infrastructure/Persistence/MongoDB/ReadRepository.php rename to src/Page/Infrastructure/Persistence/DoctrineMongoDBRepository.php index de1eeef..a4c33d8 100644 --- a/src/Black/Component/Page/Infrastructure/Persistence/MongoDB/ReadRepository.php +++ b/src/Page/Infrastructure/Persistence/DoctrineMongoDBRepository.php @@ -1,17 +1,18 @@ getQueryBuilder() @@ -52,4 +57,31 @@ public function findAll() { return $this->getQueryBuilder()->getQuery(); } + + /** + * @param WebPage $webpage + */ + public function add(WebPage $webpage) + { + $this->manager->persist($webpage); + $this->update($webpage); + } + + /** + * @param WebPage $webpage + */ + public function remove(WebPage $webpage) + { + $this->manager->remove($webpage); + $this->update($webpage); + + } + + /** + * @param WebPage $webpage + */ + public function update(WebPage $webpage) + { + $this->manager->flush(); + } } diff --git a/src/Black/Component/Page/Infrastructure/Persistence/ORM/ReadRepository.php b/src/Page/Infrastructure/Persistence/DoctrineORMRepository.php similarity index 57% rename from src/Black/Component/Page/Infrastructure/Persistence/ORM/ReadRepository.php rename to src/Page/Infrastructure/Persistence/DoctrineORMRepository.php index 0711ef7..e8f90f4 100644 --- a/src/Black/Component/Page/Infrastructure/Persistence/ORM/ReadRepository.php +++ b/src/Page/Infrastructure/Persistence/DoctrineORMRepository.php @@ -1,17 +1,17 @@ getQueryBuilder()->getQuery()->execute(); } + + /** + * @param WebPage $webpage + */ + public function add(WebPage $webpage) + { + $this->manager->persist($webpage); + $this->update($webpage); + } + + /** + * @param WebPage $webpage + */ + public function remove(WebPage $webpage) + { + $this->manager->remove($webpage); + $this->update($webpage); + + } + + /** + * @param WebPage $webpage + */ + public function update(WebPage $webpage) + { + $this->manager->flush(); + } } diff --git a/src/Black/Component/Page/Infrastructure/Service/WebPageReadService.php b/src/Page/Infrastructure/Service/WebPageReadService.php similarity index 58% rename from src/Black/Component/Page/Infrastructure/Service/WebPageReadService.php rename to src/Page/Infrastructure/Service/WebPageReadService.php index 404eb81..32ab23c 100644 --- a/src/Black/Component/Page/Infrastructure/Service/WebPageReadService.php +++ b/src/Page/Infrastructure/Service/WebPageReadService.php @@ -1,30 +1,24 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -namespace Black\Component\Page\Infrastructure\Service; +namespace Black\Page\Infrastructure\Service; -use Black\Component\Page\Domain\Exception\WebPageNotFoundException; -use Black\Component\Page\Domain\Model\WebPageId; -use Black\Component\Page\Domain\Model\WebPageReadRepository; +use Black\Page\Domain\Exception\WebPageNotFoundException; +use Black\Page\Domain\Model\WebPageId; +use Black\Page\Infrastructure\Persistence\CQRS\ReadRepository; class WebPageReadService { /** - * @var WebPageReadRepository + * @var ReadRepository */ protected $repository; /** - * @param WebPageReadRepository $repository + * WebPageReadService constructor. + * + * @param ReadRepository $repository */ - public function __construct(WebPageReadRepository $repository) + public function __construct(ReadRepository $repository) { $this->repository = $repository; } diff --git a/src/Black/Component/Page/Infrastructure/Service/WebPageWriteService.php b/src/Page/Infrastructure/Service/WebPageWriteService.php similarity index 75% rename from src/Black/Component/Page/Infrastructure/Service/WebPageWriteService.php rename to src/Page/Infrastructure/Service/WebPageWriteService.php index f3867ba..1723e94 100644 --- a/src/Black/Component/Page/Infrastructure/Service/WebPageWriteService.php +++ b/src/Page/Infrastructure/Service/WebPageWriteService.php @@ -1,24 +1,17 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Black\Component\Page\Infrastructure\Service; - -use Black\Component\Page\Domain\Model\WebPage; -use Black\Component\Page\Domain\Model\WebPageId; -use Black\Component\Page\Domain\Model\WebPageWriteRepository; + +namespace Black\Page\Infrastructure\Service; + +use Black\Page\Domain\Model\WebPage; +use Black\Page\Domain\Model\WebPageId; +use Black\Page\Domain\Model\WebPageWriteRepository; +use Black\Page\Infrastructure\Persistence\CQRS\WriteRepository; use Cocur\Slugify\Slugify; class WebPageWriteService { /** - * @var WebPageWriteRepository + * @var WriteRepository */ protected $repository; @@ -28,9 +21,10 @@ class WebPageWriteService protected $class; /** - * @param WebPageWriteRepository $repository + * WebPageWriteService constructor. + * @param WriteRepository $repository */ - public function __construct(WebPageWriteRepository $repository) + public function __construct(WriteRepository $repository) { $this->repository = $repository; $this->class = $repository->getClassName();