1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
declare(strict_types=1);
|
4
|
|
|
|
5
|
|
|
namespace Arp\LaminasDoctrineFixtures\Factory\Service;
|
6
|
|
|
|
7
|
|
|
use Arp\LaminasDoctrineFixtures\Service\Executor;
|
8
|
|
|
use Arp\LaminasDoctrineFixtures\Service\Repository\ReferenceRepository;
|
9
|
|
|
use Arp\LaminasFactory\AbstractFactory;
|
10
|
|
|
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
|
11
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
12
|
|
|
use Interop\Container\ContainerInterface;
|
13
|
|
|
|
14
|
|
|
/**
|
15
|
|
|
* @author Alex Patterson <[email protected]>
|
16
|
|
|
* @package Arp\LaminasDoctrineFixtures\Factory\Service
|
17
|
|
|
*/
|
18
|
|
|
final class ExecutorFactory extends AbstractFactory
|
19
|
|
|
{
|
20
|
|
|
/**
|
21
|
|
|
* @param ContainerInterface $container
|
22
|
|
|
* @param string $requestedName
|
23
|
|
|
* @param array|null $options
|
24
|
|
|
*
|
25
|
|
|
* @return object|void
|
26
|
|
|
*/
|
27
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
|
28
|
|
|
{
|
29
|
|
|
$options = $options ?? $this->getServiceOptions($container, $requestedName);
|
30
|
|
|
|
31
|
|
|
$entityManager = $options['entity_manager'] ?? EntityManagerInterface::class;
|
32
|
|
|
$purger = $options['purger'] ?? ORMPurger::class;
|
33
|
|
|
|
34
|
|
|
/** @var EntityManagerInterface|string */
|
35
|
|
|
if (is_string($entityManager)) {
|
36
|
|
|
$entityManager = $this->getService($container, $entityManager, $requestedName);
|
37
|
|
|
}
|
38
|
|
|
|
39
|
|
|
if (null !== $purger && is_string($purger)) {
|
40
|
|
|
$purger = $this->getService($container, $purger, $requestedName);
|
41
|
|
|
}
|
42
|
|
|
|
43
|
|
|
$executor = new Executor($entityManager, $purger);
|
44
|
|
|
$executor->setReferenceRepository(new ReferenceRepository($entityManager));
|
45
|
|
|
|
46
|
|
|
return $executor;
|
47
|
|
|
}
|
48
|
|
|
}
|
49
|
|
|
|