Initial commit

This commit is contained in:
2023-04-08 09:18:52 +02:00
commit 40e6fa63e5
34 changed files with 1060 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Command;
interface AsyncCommandInterface extends CommandInterface
{
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Command;
interface CommandBusInterface
{
public function dispatch(CommandInterface $command): void;
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Command;
interface CommandHandlerInterface
{
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Command;
interface CommandInterface
{
}

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Command;
use DigitalCraftsman\Ids\ValueObject\Id;
class CommandResponse
{
public Id $id;
public static function withValue(Id $id): CommandResponse
{
$response = new self();
$response->id = $id;
return $response;
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Command;
use Symfony\Component\Messenger\MessageBusInterface;
final class MessengerCommandBus implements CommandBusInterface
{
private MessageBusInterface $commandBus;
public function __construct(MessageBusInterface $commandBus)
{
$this->commandBus = $commandBus;
}
public function dispatch(CommandInterface $command): void
{
$this->commandBus->dispatch($command);
}
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Command;
interface SyncCommandInterface extends CommandInterface
{
}

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
final class SccCQRSExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$processor = new Processor();
// $configuration = new Configuration();
//
// $config = $processor->processConfiguration($configuration, $configs);
$loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.php');
}
}

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\DomainModel\Clock;
use Psr\Clock\ClockInterface;
final class Clock
{
public function __construct(
private ClockInterface $clock,
) {
$this->clock = $clock->withTimeZone('UTC');
}
public function now(): \DateTimeImmutable
{
return $this->clock->now();
}
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\DomainModel;
interface DomainEventInterface
{
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\DomainModel;
trait TriggerEventsTrait
{
/** @var DomainEventInterface[] */
private array $domainEvents = [];
/** @return DomainEventInterface[] */
public function domainEvents(): array
{
return $this->domainEvents;
}
public function notifyDomainEvent(DomainEventInterface $domainEvent): void
{
$this->domainEvents[] = $domainEvent;
}
public function resetDomainEvent(): void
{
$this->domainEvents = [];
}
}

View File

@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Event;
use Scc\CQRSBundle\DomainModel\DomainEventInterface;
interface EventBusInterface
{
public function notify(DomainEventInterface $event): void;
/** @param DomainEventInterface[] $domainEvents */
public function notifyAll(array $domainEvents): void;
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Event;
interface EventHandlerInterface
{
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Event;
use Scc\CQRSBundle\DomainModel\DomainEventInterface;
use Symfony\Component\Messenger\MessageBusInterface;
final class MessengerEventBus implements EventBusInterface
{
public function __construct(private MessageBusInterface $eventBus)
{
}
public function notify(DomainEventInterface $event): void
{
$this->eventBus->dispatch($event);
}
public function notifyAll(array $domainEvents): void
{
foreach ($domainEvents as $element) {
$this->notify($element);
}
}
}

79
src/MessageId.php Normal file
View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle;
use Symfony\Component\Uid\Uuid;
// snippet message-id
class MessageId
{
private string $value;
final private function __construct()
{
}
public function __toString()
{
return $this->value;
}
/** @return static */
public static function fromUuidRfc4122AsString(string $uuidAsString): self
{
self::checkIsValidUuid($uuidAsString);
return (new static())
->setValue($uuidAsString)
;
}
/** @return static */
final public static function nextId(): self
{
return static::fromUuidRfc4122AsString(
Uuid::v4()->toRfc4122()
);
}
public function equals(self $other): bool
{
return $this->value === $other->value;
}
public function toString(): string
{
return (string) $this;
}
public function id(): Uuid
{
return Uuid::fromRfc4122($this->value);
}
/** @return $this */
private function setValue(string $value): self
{
$this->value = $value;
return $this;
}
private static function checkIsValidUuid(string $uuidAsString): void
{
if (!Uuid::isValid($uuidAsString)) {
throw new \InvalidArgumentException('The value does not represent a valid identifier based in Uuid');
}
}
}
// end-snippet

83
src/MessageTrait.php Normal file
View File

@@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle;
// snippet message-trait
trait MessageTrait
{
protected ?MessageId $messageId = null;
protected ?MessageId $replyToId = null;
protected ?MessageId $correlationId = null;
public function stampIds(
?MessageId $messageId = null,
?MessageId $replyToId = null,
?MessageId $correlationId = null
): static {
$this->messageId = $messageId;
$this->replyToId = $replyToId;
$this->correlationId = $correlationId;
return $this;
}
public function stampAsNewMessage(): static
{
$messageId = MessageId::nextId();
return $this->stampIds(
$messageId,
null,
$messageId,
);
}
public function stampAsResponse(
?MessageId $replyTo,
?MessageId $correlationId
): static {
return $this->stampIds(
MessageId::nextId(),
$replyTo,
$correlationId,
);
}
/**
* @param MessageTrait $message
*/
public function stampAsResponseTo($message): static
{
return $this->stampIds(
MessageId::nextId(),
$message->messageId(),
$message->messageCorrelationId()
);
}
public function messageId(): ?MessageId
{
return $this->messageId;
}
public function messageReplyId(): ?MessageId
{
return $this->replyToId;
}
public function messageCorrelationId(): ?MessageId
{
return $this->correlationId;
}
}
// end-snippet

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Projection;
use Symfony\Component\Messenger\MessageBusInterface;
final class MessengerProjectionBus implements ProjectionBusInterface
{
public function __construct(private MessageBusInterface $projectionBus)
{
}
public function project(ProjectionInterface $projection): void
{
$this->projectionBus->dispatch($projection);
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Projection;
interface ProjectionBusInterface
{
public function project(ProjectionInterface $projection): void;
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Projection;
interface ProjectionHandlerInterface
{
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Projection;
interface ProjectionInterface
{
}

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Query;
use Symfony\Component\Messenger\HandleTrait;
use Symfony\Component\Messenger\MessageBusInterface;
final class MessengerQueryBus implements QueryBusInterface
{
use HandleTrait {
handle as handleQuery;
}
public function __construct(MessageBusInterface $queryBus)
{
$this->messageBus = $queryBus;
}
public function ask(QueryInterface $query): mixed
{
return $this->handleQuery($query);
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Query;
interface QueryBusInterface
{
public function ask(QueryInterface $query): mixed;
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Query;
interface QueryHandlerInterface
{
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle\Query;
interface QueryInterface
{
}

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Psr\Log\LoggerAwareInterface;
use Scc\VotingBundle\Collection\VotingMethodCollection;
use Scc\VotingBundle\Contract\ElectionMethodAdapterInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function symfony\component\dependencyinjection\loader\configurator\service;
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_iterator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->defaults()
->public()
->autowire(true)
->autoconfigure()
;
// $services
// ->instanceof(LoggerAwareInterface::class)
// ->call('setLogger', [service('logger')]);
//
// $services
// ->instanceof(ElectionMethodAdapterInterface::class)
// ->tag('scc_voting.method');
$services->load('Scc\CQRSBundle\\', __DIR__ . '/../../../src')
->exclude([
__DIR__,
__DIR__ . '/../../../src/SccCQRSBundle.php',
__DIR__ . '/../../../src/{DependencyInjection}',
])
;
// $services->set(VotingMethodCollection::class)
// ->args([tagged_iterator('scc_voting.method')]);
// $services->alias('scc_voting.method.collection', VotingMethodCollection::class);
};

19
src/SccCQRSBundle.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
final class SccCQRSBundle extends Bundle
{
}

17
src/ValueObject.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
/**
* This file is part of the zapoyok.info project.
* (c) <zapoyok.info> <jerome.fix@zapoyok.info>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Zapoyok\CQRSBundle;
abstract class ValueObject
{
}