Init
This commit is contained in:
25
app/domain/Http/RequestLoggerSubscriber.php
Normal file
25
app/domain/Http/RequestLoggerSubscriber.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Domain\Http;
|
||||
|
||||
use Contributte\Events\Extra\Event\Application\RequestEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Tracy\Debugger;
|
||||
|
||||
class RequestLoggerSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [RequestEvent::class => 'onRequest'];
|
||||
}
|
||||
|
||||
public function onRequest(RequestEvent $event): void
|
||||
{
|
||||
Debugger::barDump($event->getRequest());
|
||||
}
|
||||
|
||||
}
|
||||
25
app/domain/Order/Event/OrderCreated.php
Normal file
25
app/domain/Order/Event/OrderCreated.php
Normal 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
Normal file
42
app/domain/Order/OrderLogSubscriber.php
Normal 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');
|
||||
}
|
||||
|
||||
}
|
||||
48
app/domain/User/CreateUserFacade.php
Normal file
48
app/domain/User/CreateUserFacade.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace App\Domain\User;
|
||||
|
||||
use App\Model\Database\Entity\User;
|
||||
use App\Model\Database\EntityManager;
|
||||
use App\Model\Security\Passwords;
|
||||
|
||||
class CreateUserFacade
|
||||
{
|
||||
|
||||
/** @var EntityManager */
|
||||
private $em;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $em
|
||||
)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data
|
||||
*/
|
||||
public function createUser(array $data): User
|
||||
{
|
||||
// Create User
|
||||
$user = new User(
|
||||
$data['name'],
|
||||
$data['surname'],
|
||||
$data['email'],
|
||||
$data['username'],
|
||||
Passwords::create()->hash($data['password'] ?? md5(microtime()))
|
||||
);
|
||||
|
||||
// Set role
|
||||
if (isset($data['role'])) {
|
||||
$user->setRole($data['role']);
|
||||
}
|
||||
|
||||
// Save user
|
||||
$this->em->persist($user);
|
||||
$this->em->flush();
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user