1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Synapse\Cmf\Framework\Theme\Zone\Repository\Doctrine; |
4
|
|
|
|
5
|
|
|
use Synapse\Cmf\Framework\Theme\Zone\Entity\Zone; |
6
|
|
|
use Synapse\Cmf\Framework\Theme\Zone\Event\Event as ZoneEvent; |
7
|
|
|
use Synapse\Cmf\Framework\Theme\Zone\Event\Events as ZoneEvents; |
8
|
|
|
use Synapse\Cmf\Framework\Theme\Zone\Repository\RepositoryInterface; |
9
|
|
|
use Majora\Framework\Repository\Doctrine\BaseDoctrineRepository as MajoraDoctrineRepository; |
10
|
|
|
use Majora\Framework\Repository\Doctrine\DoctrineRepositoryTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Zone persistence implementation using Doctrine Orm. |
14
|
|
|
*/ |
15
|
|
|
class DoctrineRepository extends MajoraDoctrineRepository implements RepositoryInterface |
16
|
|
|
{ |
17
|
|
|
use DoctrineRepositoryTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @see EventSubscriberInterface::getSubscribedEvents() |
21
|
|
|
* @codeCoverageIgnore : configuration method |
22
|
|
|
*/ |
23
|
|
|
public static function getSubscribedEvents() |
24
|
|
|
{ |
25
|
|
|
return array( |
26
|
|
|
ZoneEvents::ZONE_CREATED => array('onCreateZone', -100), |
27
|
|
|
ZoneEvents::ZONE_EDITED => array('onWriteZone', -100), |
28
|
|
|
ZoneEvents::ZONE_DELETED => array('onDeleteZone', -100), |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Zone creation event handler. |
34
|
|
|
* Triggers persistence call only if component was defined into it. |
35
|
|
|
* |
36
|
|
|
* @param ZoneEvent $event |
37
|
|
|
*/ |
38
|
|
|
public function onCreateZone(ZoneEvent $event) |
39
|
|
|
{ |
40
|
|
|
$zone = $event->getZone(); |
41
|
|
|
if ($zone->getComponents()->isEmpty()) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->save($zone); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Zone writting event handler. |
50
|
|
|
* |
51
|
|
|
* @param ZoneEvent $event |
52
|
|
|
*/ |
53
|
2 |
|
public function onWriteZone(ZoneEvent $event) |
54
|
|
|
{ |
55
|
2 |
|
$this->save($event->getZone()); |
56
|
2 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Zone deletion event handler. |
60
|
|
|
* |
61
|
|
|
* @param ZoneEvent $event |
62
|
|
|
*/ |
63
|
2 |
|
public function onDeleteZone(ZoneEvent $event) |
64
|
|
|
{ |
65
|
2 |
|
$this->delete($event->getZone()); |
66
|
2 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Proxy for persist() repository general method. |
70
|
|
|
* |
71
|
|
|
* @see RepositoryInterface::save() |
72
|
|
|
*/ |
73
|
4 |
|
public function save(Zone $zone) |
74
|
|
|
{ |
75
|
4 |
|
return $this->persist($zone); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Proxy for remove() repository general method. |
80
|
|
|
* |
81
|
|
|
* @see RepositoryInterface::delete() |
82
|
|
|
*/ |
83
|
4 |
|
public function delete(Zone $zone) |
84
|
|
|
{ |
85
|
4 |
|
return $this->remove($zone); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|