|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arp\LaminasEntity\Factory\Repository\Persistence; |
|
6
|
|
|
|
|
7
|
|
|
use Arp\DoctrineEntityRepository\Constant\ClearMode; |
|
8
|
|
|
use Arp\DoctrineEntityRepository\Constant\EntityEventOption; |
|
9
|
|
|
use Arp\DoctrineEntityRepository\Constant\TransactionMode; |
|
10
|
|
|
use Arp\DoctrineEntityRepository\Persistence\CascadeSaveService; |
|
11
|
|
|
use Arp\LaminasFactory\AbstractFactory; |
|
12
|
|
|
use Interop\Container\ContainerInterface; |
|
13
|
|
|
use Psr\Log\LoggerInterface; |
|
14
|
|
|
use Psr\Log\NullLogger; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Alex Patterson <[email protected]> |
|
18
|
|
|
* @package Arp\LaminasEntity\Factory\Repository\Persistence |
|
19
|
|
|
*/ |
|
20
|
|
|
final class CascadeSaveServiceFactory extends AbstractFactory |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @param ContainerInterface $container |
|
24
|
|
|
* @param string $requestedName |
|
25
|
|
|
* @param array|null $options |
|
26
|
|
|
* |
|
27
|
|
|
* @return CascadeSaveService |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): CascadeSaveService |
|
30
|
|
|
{ |
|
31
|
|
|
$options = $options ?? $this->getServiceOptions($container, $requestedName); |
|
32
|
|
|
|
|
33
|
|
|
/** @var LoggerInterface|string $logger */ |
|
34
|
|
|
$logger = $options['logger'] ?? NullLogger::class; |
|
35
|
|
|
if (is_string($logger)) { |
|
|
|
|
|
|
36
|
|
|
$logger = $this->getService($container, $logger, $requestedName); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return new CascadeSaveService( |
|
40
|
|
|
$logger, |
|
41
|
|
|
[ |
|
42
|
|
|
EntityEventOption::TRANSACTION_MODE => TransactionMode::DISABLED, |
|
43
|
|
|
EntityEventOption::FLUSH_MODE => TransactionMode::DISABLED, |
|
44
|
|
|
EntityEventOption::CLEAR_MODE => ClearMode::DISABLED, |
|
45
|
|
|
], |
|
46
|
|
|
[ |
|
47
|
|
|
EntityEventOption::TRANSACTION_MODE => TransactionMode::DISABLED, |
|
48
|
|
|
EntityEventOption::FLUSH_MODE => TransactionMode::DISABLED, |
|
49
|
|
|
EntityEventOption::CLEAR_MODE => ClearMode::DISABLED, |
|
50
|
|
|
] |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|