1
|
|
|
<?php |
2
|
|
|
namespace AcMailer\Options; |
3
|
|
|
|
4
|
|
|
use Zend\Stdlib\AbstractOptions; |
5
|
|
|
use Zend\View\Model\ViewModel; |
6
|
|
|
use AcMailer\View\ViewModelConvertibleInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Template specific options |
10
|
|
|
* @author Alejandro Celaya Alastrué |
11
|
|
|
* @link http://www.alejandrocelaya.com |
12
|
|
|
*/ |
13
|
|
|
class TemplateOptions extends AbstractOptions implements ViewModelConvertibleInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $path = 'ac-mailer/mail-templates/mail'; |
19
|
|
|
/** |
20
|
|
|
* @var array |
21
|
|
|
*/ |
22
|
|
|
protected $params = []; |
23
|
|
|
/** |
24
|
|
|
* @var TemplateOptions[] |
25
|
|
|
*/ |
26
|
|
|
protected $children = []; |
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $defaultLayout = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param $params |
34
|
|
|
* @return $this |
35
|
|
|
*/ |
36
|
1 |
|
public function setParams($params) |
37
|
|
|
{ |
38
|
1 |
|
$this->params = $params; |
39
|
1 |
|
return $this; |
40
|
|
|
} |
41
|
|
|
/** |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
3 |
|
public function getParams() |
45
|
|
|
{ |
46
|
3 |
|
return $this->params; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param $path |
51
|
|
|
* @return $this |
52
|
|
|
*/ |
53
|
3 |
|
public function setPath($path) |
54
|
|
|
{ |
55
|
3 |
|
$this->path = $path; |
56
|
3 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
/** |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
3 |
|
public function getPath() |
62
|
|
|
{ |
63
|
3 |
|
return $this->path; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param array $children |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
2 |
|
public function setChildren($children) |
71
|
|
|
{ |
72
|
2 |
|
$children = (array) $children; |
73
|
2 |
|
$this->children = []; |
74
|
|
|
// Cast each child to a TemplateOptions object |
75
|
2 |
|
foreach ($children as $captureTo => $child) { |
76
|
2 |
|
$this->children[$captureTo] = new TemplateOptions($child); |
77
|
|
|
// Recursively add childs |
78
|
2 |
|
if (array_key_exists('children', $child)) { |
79
|
1 |
|
$this->children[$captureTo]->setChildren($child['children']); |
80
|
1 |
|
} |
81
|
2 |
|
} |
82
|
|
|
|
83
|
2 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
/** |
86
|
|
|
* @return TemplateOptions[] |
87
|
|
|
*/ |
88
|
4 |
|
public function getChildren() |
89
|
|
|
{ |
90
|
4 |
|
return $this->children; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return ViewModel |
95
|
|
|
*/ |
96
|
2 |
|
public function toViewModel() |
97
|
|
|
{ |
98
|
|
|
// Create the base ViewModel |
99
|
2 |
|
$model = new ViewModel($this->getParams()); |
100
|
2 |
|
$model->setTemplate($this->getPath()); |
101
|
|
|
|
102
|
|
|
// Add childs recursively |
103
|
|
|
/* @var TemplateOptions $child */ |
104
|
2 |
|
foreach ($this->getChildren() as $captureTo => $child) { |
105
|
1 |
|
$model->addChild($child->toViewModel(), $captureTo); |
106
|
2 |
|
} |
107
|
|
|
|
108
|
2 |
|
return $model; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return array |
113
|
|
|
*/ |
114
|
4 |
|
public function getDefaultLayout() |
115
|
|
|
{ |
116
|
4 |
|
return $this->defaultLayout; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param array $defaultLayout |
121
|
|
|
* @return $this |
122
|
|
|
*/ |
123
|
2 |
|
public function setDefaultLayout(array $defaultLayout) |
124
|
|
|
{ |
125
|
2 |
|
$this->defaultLayout = $defaultLayout; |
126
|
2 |
|
return $this; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|