1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Arp\LaminasEntity\Factory\Repository\Query; |
6
|
|
|
|
7
|
|
|
use Arp\DoctrineEntityRepository\Query\QueryService; |
8
|
|
|
use Arp\DoctrineEntityRepository\Query\QueryServiceInterface; |
9
|
|
|
use Arp\LaminasFactory\AbstractFactory; |
10
|
|
|
use Arp\LaminasFactory\Exception\ServiceNotCreatedException; |
11
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
12
|
|
|
use Interop\Container\ContainerInterface; |
13
|
|
|
use Psr\Log\NullLogger; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Alex Patterson <[email protected]> |
17
|
|
|
* @package Arp\LaminasEntity\Factory\Repository\Query |
18
|
|
|
*/ |
19
|
|
|
final class QueryServiceFactory extends AbstractFactory |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $defaultClassName = QueryService::class; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param ContainerInterface $container |
28
|
|
|
* @param string $requestedName |
29
|
|
|
* @param array|null $options |
30
|
|
|
* |
31
|
|
|
* @return QueryServiceInterface |
32
|
|
|
* |
33
|
|
|
* @throws ServiceNotCreatedException If the query service cannot be created. |
34
|
|
|
*/ |
35
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
36
|
|
|
{ |
37
|
|
|
$options = $options ?? $this->getServiceOptions($container, $requestedName); |
38
|
|
|
|
39
|
|
|
$className = $options['class_name'] ?? $this->defaultClassName; |
40
|
|
|
$entityName = $options['entity_name'] ?? null; |
41
|
|
|
|
42
|
|
|
if (null === $entityName || ! is_string($entityName)) { |
43
|
|
|
throw new ServiceNotCreatedException( |
44
|
|
|
sprintf('The required \'entity_name\' configuration option is missing for service %s', $requestedName) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** @var EntityManagerInterface $entityManager */ |
49
|
|
|
$entityManager = $this->getService($container, 'doctrine.entitymanager.orm_default', $requestedName); |
50
|
|
|
|
51
|
|
|
$logger = new NullLogger(); |
52
|
|
|
|
53
|
|
|
return new $className($entityName, $entityManager, $logger); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|