Basic functionality
This commit is contained in:
25
app/domain/Order/Event/OrderCreated.php
Executable file
25
app/domain/Order/Event/OrderCreated.php
Executable file
@@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Domain\Order\Event;
|
||||
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
final class OrderCreated extends Event
|
||||
{
|
||||
|
||||
public const NAME = 'order.created';
|
||||
|
||||
/** @var string */
|
||||
private $order;
|
||||
|
||||
public function __construct(string $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
public function getOrder(): string
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
}
|
||||
42
app/domain/Order/OrderLogSubscriber.php
Executable file
42
app/domain/Order/OrderLogSubscriber.php
Executable file
@@ -0,0 +1,42 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Domain\Order;
|
||||
|
||||
use App\Domain\Order\Event\OrderCreated;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Tracy\Debugger;
|
||||
|
||||
class OrderLogSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [
|
||||
OrderCreated::NAME => [
|
||||
['onOrderCreatedBefore', 100],
|
||||
['onOrderCreated', 0],
|
||||
['onOrderCreatedAfter', -100],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function onOrderCreatedBefore(OrderCreated $event): void
|
||||
{
|
||||
Debugger::barDump('BEFORE');
|
||||
}
|
||||
|
||||
public function onOrderCreated(OrderCreated $event): void
|
||||
{
|
||||
Debugger::log($event, 'info');
|
||||
Debugger::barDump($event);
|
||||
}
|
||||
|
||||
public function onOrderCreatedAfter(OrderCreated $event): void
|
||||
{
|
||||
Debugger::barDump('AFTER');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user