1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DataFlowServer\Db\Controller; |
5
|
|
|
|
6
|
|
|
use Doctrine\ORM\ORMException; |
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
8
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
9
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
10
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
11
|
|
|
use Psr\Log\LoggerInterface; |
12
|
|
|
use SlayerBirden\DataFlowServer\Db\Entities\DbConfiguration; |
13
|
|
|
use SlayerBirden\DataFlowServer\Doctrine\Middleware\ResourceMiddlewareInterface; |
14
|
|
|
use SlayerBirden\DataFlowServer\Doctrine\Persistence\EntityManagerRegistry; |
15
|
|
|
use SlayerBirden\DataFlowServer\Stdlib\Validation\GeneralSuccessResponseFactory; |
16
|
|
|
use Zend\Hydrator\HydratorInterface; |
17
|
|
|
|
18
|
|
|
final class DeleteConfigAction implements MiddlewareInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var LoggerInterface |
22
|
|
|
*/ |
23
|
|
|
private $logger; |
24
|
|
|
/** |
25
|
|
|
* @var HydratorInterface |
26
|
|
|
*/ |
27
|
|
|
private $hydrator; |
28
|
|
|
/** |
29
|
|
|
* @var EntityManagerRegistry |
30
|
|
|
*/ |
31
|
|
|
private $managerRegistry; |
32
|
|
|
|
33
|
2 |
|
public function __construct( |
34
|
|
|
EntityManagerRegistry $managerRegistry, |
35
|
|
|
LoggerInterface $logger, |
36
|
|
|
HydratorInterface $hydrator |
37
|
|
|
) { |
38
|
2 |
|
$this->managerRegistry = $managerRegistry; |
39
|
2 |
|
$this->logger = $logger; |
40
|
2 |
|
$this->hydrator = $hydrator; |
41
|
2 |
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritdoc |
45
|
|
|
* @throws ORMException |
46
|
|
|
*/ |
47
|
2 |
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
48
|
|
|
{ |
49
|
2 |
|
$dbConfig = $request->getAttribute(ResourceMiddlewareInterface::DATA_RESOURCE); |
50
|
2 |
|
$em = $this->managerRegistry->getManagerForClass(DbConfiguration::class); |
51
|
2 |
|
$em->remove($dbConfig); |
52
|
2 |
|
$em->flush(); |
53
|
2 |
|
$msg = 'Configuration removed.'; |
54
|
2 |
|
return (new GeneralSuccessResponseFactory())($msg, 'configuration', $this->hydrator->extract($dbConfig)); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|