1 | <?php |
||
7 | class Escaper extends BaseEscaper implements EscaperInterface |
||
8 | { |
||
9 | /** @var array The special escaping types */ |
||
10 | private $specialEscapingTypes = array('script', 'style'); |
||
11 | |||
12 | /** @var array The urls attributes */ |
||
13 | private $urlsAttributes = array('href', 'src'); |
||
14 | |||
15 | /** @var bool Determine if html is escaped or not */ |
||
16 | private $escapeHtml = true; |
||
17 | |||
18 | /** @var bool Determine if html attributes are escaped or not */ |
||
19 | private $escapeHtmlAttr = true; |
||
20 | |||
21 | /** @var bool Determine if javascript is escaped or not */ |
||
22 | private $escapeJs = true; |
||
23 | |||
24 | /** @var bool Determine if css is escaped or not */ |
||
25 | private $escapeCss = true; |
||
26 | |||
27 | /** @var bool Determine if urls parameters are escaped or not */ |
||
28 | private $escapeUrl = true; |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | public function escapeAttributes(array $attributes): array |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function escape(ElementInterface $element): ElementInterface |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function escapeUrlParameter(string $parameter): string |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function isEscapeHtml(): bool |
||
89 | |||
90 | /** |
||
91 | * {@inheritdoc} |
||
92 | */ |
||
93 | public function setEscapeHtml(bool $escapeHtml = true): EscaperInterface |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function isEscapeHtmlAttr(): bool |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | public function setEscapeHtmlAttr(bool $escapeHtmlAttr = true): EscaperInterface |
||
117 | |||
118 | /** |
||
119 | * {@inheritdoc} |
||
120 | */ |
||
121 | public function isEscapeJs(): bool |
||
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | public function setEscapeJs(bool $escapeJs = true): EscaperInterface |
||
135 | |||
136 | /** |
||
137 | * {@inheritdoc} |
||
138 | */ |
||
139 | public function isEscapeCss(): bool |
||
143 | |||
144 | /** |
||
145 | * {@inheritdoc} |
||
146 | */ |
||
147 | public function setEscapeCss(bool $escapeCss = true): EscaperInterface |
||
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | public function isEscapeUrl(): bool |
||
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | public function setEscapeUrl(bool $escapeUrl = true): EscaperInterface |
||
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | public function getUrlsAttributes(): array |
||
179 | } |
||
180 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.