|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Synapse\Cmf\Framework\Theme\Template\Domain\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Synapse\Cmf\Framework\Theme\TemplateType\Model\TemplateTypeInterface; |
|
6
|
|
|
use Synapse\Cmf\Framework\Theme\Template\Entity\Template; |
|
7
|
|
|
use Synapse\Cmf\Framework\Theme\Template\Event\Event as TemplateEvent; |
|
8
|
|
|
use Synapse\Cmf\Framework\Theme\Template\Event\Events as TemplateEvents; |
|
9
|
|
|
use Synapse\Cmf\Framework\Theme\Zone\Entity\ZoneCollection; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Template creation command representation. |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class CreateCommand extends AbstractCommand |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
private $templateClass; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var TemplateTypeInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $templateType; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Construct. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $templateClass |
|
30
|
|
|
*/ |
|
31
|
2 |
|
public function __construct($templateClass = Template::class) |
|
32
|
|
|
{ |
|
33
|
2 |
|
$this->templateClass = $templateClass; |
|
34
|
2 |
|
$this->zones = new ZoneCollection(); |
|
35
|
2 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Template object creation method. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $templateClass |
|
41
|
|
|
* |
|
42
|
|
|
* @return TemplateInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
abstract protected function createTemplate($templateClass); |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Template creation method. |
|
48
|
|
|
* |
|
49
|
|
|
* @return Template |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function resolve() |
|
52
|
|
|
{ |
|
53
|
2 |
|
$this->template = $this->createTemplate($this->templateClass); |
|
|
|
|
|
|
54
|
2 |
|
$this->template->setZones($this->zones); |
|
55
|
|
|
|
|
56
|
2 |
|
$this->assertEntityIsValid($this->template, array('Template', 'creation')); |
|
57
|
|
|
|
|
58
|
2 |
|
$this->eventDispatcher->addListener( |
|
59
|
2 |
|
TemplateEvents::TEMPLATE_CREATED, |
|
60
|
2 |
|
$handler = array($this, 'onTemplateCreated') |
|
61
|
1 |
|
); |
|
62
|
2 |
|
$this->fireEvent( |
|
63
|
2 |
|
TemplateEvents::TEMPLATE_CREATED, |
|
64
|
2 |
|
new TemplateEvent($this->template, $this) |
|
65
|
1 |
|
); |
|
66
|
2 |
|
$this->eventDispatcher->removeListener(TemplateEvents::TEMPLATE_CREATED, $handler); |
|
67
|
|
|
|
|
68
|
2 |
|
return $this->template; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Define action template type. |
|
73
|
|
|
* |
|
74
|
|
|
* @param TemplateTypeInterface $templateType |
|
75
|
|
|
* |
|
76
|
|
|
* @return self |
|
77
|
|
|
*/ |
|
78
|
2 |
|
public function setTemplateType(TemplateTypeInterface $templateType) |
|
79
|
|
|
{ |
|
80
|
2 |
|
$this->templateType = $templateType; |
|
81
|
|
|
|
|
82
|
2 |
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
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..