|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Core\Repository\DoctrineMongoODM\Event; |
|
11
|
|
|
|
|
12
|
|
|
use Doctrine\Common\EventSubscriber; |
|
13
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
14
|
|
|
use Core\Repository\RepositoryInterface; |
|
15
|
|
|
|
|
16
|
|
|
class RepositoryEventsSubscriber implements EventSubscriber |
|
17
|
|
|
{ |
|
18
|
|
|
const postConstruct = 'postRepositoryConstruct'; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var ServiceLocatorInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $services; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(ServiceLocatorInterface $serviceLocator) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->services = $serviceLocator; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function postRepositoryConstruct($eventArgs) |
|
34
|
|
|
{ |
|
35
|
|
|
$repo = $eventArgs->getRepository(); |
|
36
|
|
|
if ($repo instanceof RepositoryInterface) { |
|
37
|
|
|
$documentName = $repo->getDocumentName(); |
|
38
|
|
|
$entity = new $documentName(); |
|
39
|
|
|
//if ($entity instanceof ) { |
|
|
|
|
|
|
40
|
|
|
// $entity->setRepository($repo); |
|
|
|
|
|
|
41
|
|
|
//} |
|
42
|
|
|
$repo->setEntityPrototype($entity); |
|
43
|
|
|
$repo->init($this->services); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @see \Doctrine\Common\EventSubscriber::getSubscribedEvents() |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getSubscribedEvents() |
|
51
|
|
|
{ |
|
52
|
|
|
return array(self::postConstruct); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
|
57
|
|
|
* @return RepositoryEventsSubscriber |
|
58
|
|
|
*/ |
|
59
|
|
|
public static function factory(ServiceLocatorInterface $serviceLocator) |
|
60
|
|
|
{ |
|
61
|
|
|
return new static($serviceLocator); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|