for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace SlayerBirden\DataFlowServer\Domain\Controller;
use Doctrine\ORM\ORMException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use SlayerBirden\DataFlowServer\Doctrine\Middleware\ResourceMiddlewareInterface;
use SlayerBirden\DataFlowServer\Doctrine\Persistence\EntityManagerRegistry;
use SlayerBirden\DataFlowServer\Domain\Entities\User;
use SlayerBirden\DataFlowServer\Stdlib\Validation\GeneralSuccessResponseFactory;
use Zend\Hydrator\HydratorInterface;
final class DeleteUserAction implements MiddlewareInterface
{
/**
* @var LoggerInterface
*/
private $logger;
* @var HydratorInterface
private $hydrator;
* @var EntityManagerRegistry
private $managerRegistry;
public function __construct(
EntityManagerRegistry $managerRegistry,
LoggerInterface $logger,
HydratorInterface $hydrator
) {
$this->managerRegistry = $managerRegistry;
$this->logger = $logger;
$this->hydrator = $hydrator;
}
* @inheritdoc
* @throws ORMException
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
$user = $request->getAttribute(ResourceMiddlewareInterface::DATA_RESOURCE);
$em = $this->managerRegistry->getManagerForClass(User::class);
$em->remove($user);
$em->flush();
return (new GeneralSuccessResponseFactory())('User was deleted', 'user', $this->hydrator->extract($user));