1 | <?php |
||
15 | abstract class CreateCommand extends AbstractCommand |
||
16 | { |
||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | private $templateClass; |
||
21 | |||
22 | /** |
||
23 | * @var ZoneDomain |
||
24 | */ |
||
25 | private $zoneDomain; |
||
26 | |||
27 | /** |
||
28 | * @var TemplateTypeInterface |
||
29 | */ |
||
30 | protected $templateType; |
||
31 | |||
32 | /** |
||
33 | * Construct. |
||
34 | * |
||
35 | * @param ZoneDomain $zoneDomain |
||
36 | * @param string $templateClass |
||
37 | */ |
||
38 | 2 | public function __construct(ZoneDomain $zoneDomain, $templateClass = Template::class) |
|
44 | |||
45 | /** |
||
46 | * Template object creation method. |
||
47 | * |
||
48 | * @param string $templateClass |
||
49 | * |
||
50 | * @return TemplateInterface |
||
51 | */ |
||
52 | abstract protected function createTemplate($templateClass); |
||
53 | |||
54 | /** |
||
55 | * Template creation event handler. |
||
56 | * |
||
57 | * @param TemplateEvent $event |
||
58 | */ |
||
59 | public function onTemplateCreated(TemplateEvent $event) |
||
60 | { |
||
61 | $template = $event->getTemplate(); |
||
62 | $zones = $template->getZones(); |
||
63 | foreach ($template->getTemplateType()->getZoneTypes() as $zoneType) { |
||
64 | if ($zones->search(array('zoneType' => $zoneType))->isEmpty()) { |
||
65 | $zones->add($this->zoneDomain->create($zoneType)); |
||
66 | } |
||
67 | } |
||
68 | $template->setZones($zones); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Template creation method. |
||
73 | * |
||
74 | * @return Template |
||
75 | */ |
||
76 | 2 | public function resolve() |
|
77 | { |
||
78 | 2 | $this->template = $this->createTemplate($this->templateClass); |
|
|
|||
79 | 2 | $this->template->setZones($this->zones); |
|
80 | |||
81 | 2 | $this->assertEntityIsValid($this->template, array('Template', 'creation')); |
|
82 | |||
83 | 2 | $this->eventDispatcher->addListener( |
|
84 | 2 | TemplateEvents::TEMPLATE_CREATED, |
|
85 | 2 | $handler = array($this, 'onTemplateCreated') |
|
86 | ); |
||
87 | 2 | $this->fireEvent( |
|
88 | 2 | TemplateEvents::TEMPLATE_CREATED, |
|
89 | 2 | new TemplateEvent($this->template, $this) |
|
90 | ); |
||
91 | 2 | $this->eventDispatcher->removeListener(TemplateEvents::TEMPLATE_CREATED, $handler); |
|
92 | |||
93 | 2 | return $this->template; |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Define action template type. |
||
98 | * |
||
99 | * @param TemplateTypeInterface $templateType |
||
100 | * |
||
101 | * @return self |
||
102 | */ |
||
103 | 2 | public function setTemplateType(TemplateTypeInterface $templateType) |
|
109 | } |
||
110 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..