1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Synapse\Cmf\Framework\Theme\Template\Domain\Command; |
4
|
|
|
|
5
|
|
|
use Majora\Framework\Domain\Action\ActionInterface; |
6
|
|
|
use Majora\Framework\Domain\Action\Dal\DalActionTrait; |
7
|
|
|
use Synapse\Cmf\Framework\Theme\Template\Entity\Template; |
8
|
|
|
use Synapse\Cmf\Framework\Theme\Template\Model\TemplateInterface; |
9
|
|
|
use Synapse\Cmf\Framework\Theme\Zone\Entity\ZoneCollection; |
10
|
|
|
use Synapse\Cmf\Framework\Theme\Zone\Domain\DomainInterface as ZoneDomain; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Base class for Template commands. |
14
|
|
|
*/ |
15
|
|
|
abstract class AbstractCommand implements ActionInterface |
16
|
|
|
{ |
17
|
|
|
use DalActionTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var TemplateInterface |
21
|
|
|
*/ |
22
|
|
|
protected $template; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ZoneCollection |
26
|
|
|
*/ |
27
|
|
|
protected $zones; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ZoneDomain |
31
|
|
|
*/ |
32
|
|
|
protected $zoneDomain; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Template creation event handler. |
36
|
|
|
* |
37
|
|
|
* @param TemplateEvent $event |
38
|
|
|
*/ |
39
|
|
|
public function onTemplateCreated(TemplateEvent $event) |
40
|
|
|
{ |
41
|
|
|
$template = $event->getTemplate(); |
42
|
|
|
$zones = $template->getZones(); |
43
|
|
|
foreach ($template->getTemplateType()->getZoneTypes() as $zoneType) { |
44
|
|
|
if ($zones->search(array('zoneType' => $zoneType))->isEmpty()) { |
45
|
|
|
if (null === $this->zoneDomain) { |
46
|
|
|
throw new \DomainException('No zoneDomain was set, you are unable to update your configuration.'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$zones->add($this->zoneDomain->create($zoneType)); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
$template->setZones($zones); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return related Template if defined. |
57
|
|
|
* |
58
|
|
|
* @return TemplateInterface $template |
59
|
|
|
*/ |
60
|
|
|
public function getTemplate() |
61
|
|
|
{ |
62
|
|
|
return $this->template; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Define Command zones. |
67
|
|
|
* |
68
|
|
|
* @param ZoneCollection $zones |
69
|
|
|
* |
70
|
|
|
* @return self |
71
|
|
|
*/ |
72
|
2 |
|
public function setZones(ZoneCollection $zones) |
73
|
|
|
{ |
74
|
2 |
|
$this->zones = $zones; |
75
|
|
|
|
76
|
2 |
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns Command zones. |
81
|
|
|
* |
82
|
|
|
* @return ZoneCollection |
83
|
|
|
*/ |
84
|
|
|
public function getZones() |
85
|
|
|
{ |
86
|
|
|
return $this->zones; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Set zoneDomain. |
91
|
|
|
* |
92
|
|
|
* @param ZoneDomain $zoneDomain |
93
|
|
|
*/ |
94
|
2 |
|
public function setZoneDomain(ZoneDomain $zoneDomain) |
95
|
|
|
{ |
96
|
2 |
|
$this->zoneDomain = $zoneDomain; |
97
|
2 |
|
} |
98
|
|
|
} |
99
|
|
|
|