1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ____ _ _ _ _ |
5
|
|
|
* | _ \| |__ | |_ ___ _ __ ___ __ _(_) | |
6
|
|
|
* | |_) | '_ \| __/ _ \ '_ ` _ \ / _` | | | |
7
|
|
|
* | __/| | | | || __/ | | | | | (_| | | | |
8
|
|
|
* |_| |_| |_|\__\___|_| |_| |_|\__,_|_|_| |
9
|
|
|
* |
10
|
|
|
* This file is part of Kristuff\Phtemail. |
11
|
|
|
* |
12
|
|
|
* (c) Kristuff <[email protected]> |
13
|
|
|
* |
14
|
|
|
* For the full copyright and license information, please view the LICENSE |
15
|
|
|
* file that was distributed with this source code. |
16
|
|
|
* |
17
|
|
|
* @version 0.2.0 |
18
|
|
|
* @copyright 2017-2020 Kristuff |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Kristuff\Phtemail\Core; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class StylyzedElement |
25
|
|
|
* Abstract base class for Html elements |
26
|
|
|
* |
27
|
|
|
* That class allow to define the following styles: |
28
|
|
|
* - Color |
29
|
|
|
* - FontFamily |
30
|
|
|
* - FontSize |
31
|
|
|
* - ... |
32
|
|
|
* |
33
|
|
|
* Containers elements that extends that class will apply other 'container styles' (ie: align, ...todo) |
34
|
|
|
*/ |
35
|
|
|
abstract class StylizedElement |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* The mandatory styles list. Html elements with mandarory styles will recieve an inline style for each style. |
39
|
|
|
* |
40
|
|
|
* @access private |
41
|
|
|
* @var array $mandatoryStyles |
42
|
|
|
*/ |
43
|
|
|
protected $mandatoryStyles = array(); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The known styles list. |
47
|
|
|
* |
48
|
|
|
* @access private |
49
|
|
|
* @var array $knowStyles |
50
|
|
|
*/ |
51
|
|
|
protected $knowStyles = array( |
52
|
|
|
'color' , |
53
|
|
|
'background-color', |
54
|
|
|
'font-family', |
55
|
|
|
'font-size', |
56
|
|
|
'font-weight', |
57
|
|
|
'line-height', |
58
|
|
|
'padding-top' , |
59
|
|
|
'padding-left' , |
60
|
|
|
'padding-bottom', |
61
|
|
|
'padding-right', |
62
|
|
|
'text-align', |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* The current html element styles |
67
|
|
|
* |
68
|
|
|
* @access private |
69
|
|
|
* @var array $styles |
70
|
|
|
*/ |
71
|
|
|
protected $styles = array(); |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Sets inline styles |
75
|
|
|
* |
76
|
|
|
* @access public |
77
|
|
|
* @param array $styles An indexed array of inline styles=>value |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
public function setStyles(array $styles = []) |
82
|
|
|
{ |
83
|
|
|
foreach ($styles as $key => $value){ |
84
|
|
|
if (in_array($key, $this->knowStyles)){ |
85
|
|
|
$this->styles[$key] = $value; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Sets the font family |
92
|
|
|
* |
93
|
|
|
* @access public |
94
|
|
|
* @param string $value |
95
|
|
|
* |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
public function setFont(string $value) |
99
|
|
|
{ |
100
|
|
|
$this->styles['font'] = $value; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Sets the font size. |
105
|
|
|
* |
106
|
|
|
* @access public |
107
|
|
|
* @param string $value The font size in pixels. Value must have the 'px' extension |
108
|
|
|
* |
109
|
|
|
* @return void |
110
|
|
|
*/ |
111
|
|
|
public function setFontSize(string $value) |
112
|
|
|
{ |
113
|
|
|
$this->styles['font-size'] = $value; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Sets the text color |
118
|
|
|
* |
119
|
|
|
* @access public |
120
|
|
|
* @param string $value |
121
|
|
|
* |
122
|
|
|
* @return void |
123
|
|
|
* @throws \InvalidArgumentException if the color is not a valid hex color |
124
|
|
|
*/ |
125
|
|
|
public function setColor(string $value) |
126
|
|
|
{ |
127
|
|
|
$this->styles['color'] = HtmlBuilder::validateColor($value); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Sets the background color |
132
|
|
|
* |
133
|
|
|
* @access public |
134
|
|
|
* @param string $value |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
* @throws \InvalidArgumentException if the color is not a valid hex color |
138
|
|
|
*/ |
139
|
|
|
public function setBackground(string $value) |
140
|
|
|
{ |
141
|
|
|
$this->styles['background-color'] = HtmlBuilder::validateColor($value); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
} |