|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Adlogix package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Allan Segebarth <[email protected]> |
|
6
|
|
|
* (c) Jean-Jacques Courtens <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Adlogix\Zf2Rollout\Service\Factory; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
use Adlogix\Zf2Rollout\Storage\Doctrine\DoctrineORMStorage; |
|
16
|
|
|
use Doctrine\ORM\EntityManager; |
|
17
|
|
|
use Interop\Container\ContainerInterface; |
|
18
|
|
|
use Zend\ServiceManager\FactoryInterface; |
|
19
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
20
|
|
|
|
|
21
|
|
|
class DoctrineORMStorageFactory implements FactoryInterface |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
|
28
|
|
|
{ |
|
29
|
|
|
return $this($serviceLocator, null); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var EntityManager $em */ |
|
38
|
|
|
$em = $container->get('doctrine.entitymanager.orm_default'); |
|
39
|
|
|
|
|
40
|
|
|
/** @var array $rolloutConfig */ |
|
41
|
|
|
$rolloutConfig = $container->get('zf2_rollout_config'); |
|
42
|
|
|
|
|
43
|
|
|
if (!isset($rolloutConfig['doctrine_storage']['class_name'])) { |
|
44
|
|
|
throw new \RuntimeException('No "[ doctrine_storage => class_name => "some_class"]" defined in the rollout configuration!"'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$class = $em->getMetadataFactory()->getMetadataFor($rolloutConfig['doctrine_storage']['class_name']); |
|
48
|
|
|
|
|
49
|
|
|
/** @noinspection PhpParamsInspection */ |
|
50
|
|
|
return new DoctrineORMStorage($em, $class); |
|
51
|
|
|
} |
|
52
|
|
|
} |