1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace DoctrineORMModule\Service; |
21
|
|
|
|
22
|
|
|
use Doctrine\Common\EventSubscriber; |
23
|
|
|
use Doctrine\ORM\Events; |
24
|
|
|
use Doctrine\ORM\Tools\ResolveTargetEntityListener; |
25
|
|
|
use DoctrineModule\Service\AbstractFactory; |
26
|
|
|
use Interop\Container\ContainerInterface; |
27
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
28
|
|
|
|
29
|
|
|
class EntityResolverFactory extends AbstractFactory |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* {@inheritDoc} |
33
|
|
|
*/ |
34
|
56 |
|
public function __invoke(ContainerInterface $container, $requestedName, array $options = null) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
/* @var $options \DoctrineORMModule\Options\EntityResolver */ |
37
|
56 |
|
$options = $this->getOptions($container, 'entity_resolver'); |
|
|
|
|
38
|
56 |
|
$eventManager = $container->get($options->getEventManager()); |
39
|
56 |
|
$resolvers = $options->getResolvers(); |
40
|
|
|
|
41
|
56 |
|
$targetEntityListener = new ResolveTargetEntityListener(); |
42
|
|
|
|
43
|
56 |
|
foreach ($resolvers as $oldEntity => $newEntity) { |
44
|
56 |
|
$targetEntityListener->addResolveTargetEntity($oldEntity, $newEntity, array()); |
45
|
56 |
|
} |
46
|
|
|
|
47
|
|
|
// Starting from Doctrine ORM 2.5, the listener implements EventSubscriber |
48
|
56 |
|
if ($targetEntityListener instanceof EventSubscriber) { |
49
|
56 |
|
$eventManager->addEventSubscriber($targetEntityListener); |
50
|
56 |
|
} else { |
51
|
|
|
$eventManager->addEventListener(Events::loadClassMetadata, $targetEntityListener); |
52
|
|
|
} |
53
|
|
|
|
54
|
56 |
|
return $eventManager; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritDoc} |
59
|
|
|
*/ |
60
|
56 |
|
public function createService(ServiceLocatorInterface $container) |
61
|
|
|
{ |
62
|
56 |
|
return $this($container, \Zend\EventManager\EventManager::class); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the class name of the options associated with this factory. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
56 |
|
public function getOptionsClass() |
71
|
|
|
{ |
72
|
56 |
|
return 'DoctrineORMModule\Options\EntityResolver'; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.