@@ -36,19 +36,19 @@ discard block |
||
36 | 36 | { |
37 | 37 | const ERROR_STRING_ALREADY_HAS_BODY_TAG = 57001; |
38 | 38 | |
39 | - /** |
|
40 | - * @var \DOMElement |
|
41 | - */ |
|
39 | + /** |
|
40 | + * @var \DOMElement |
|
41 | + */ |
|
42 | 42 | private $bodyNode; |
43 | 43 | |
44 | - /** |
|
45 | - * @var XMLHelper_DOMErrors |
|
46 | - */ |
|
44 | + /** |
|
45 | + * @var XMLHelper_DOMErrors |
|
46 | + */ |
|
47 | 47 | private $errors; |
48 | 48 | |
49 | - /** |
|
50 | - * @var string |
|
51 | - */ |
|
49 | + /** |
|
50 | + * @var string |
|
51 | + */ |
|
52 | 52 | private static $htmlTemplate = |
53 | 53 | '<!DOCTYPE html>'. |
54 | 54 | '<html>'. |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | '</body>'. |
61 | 61 | '</html>'; |
62 | 62 | |
63 | - /** |
|
64 | - * @var \DOMDocument |
|
65 | - */ |
|
63 | + /** |
|
64 | + * @var \DOMDocument |
|
65 | + */ |
|
66 | 66 | private $dom; |
67 | 67 | |
68 | 68 | private function __construct(string $html) |
@@ -70,13 +70,13 @@ discard block |
||
70 | 70 | $this->load($html); |
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * Creates an HTML loader from an HTML fragment (without |
|
75 | - * doctype, head and body elements). |
|
76 | - * |
|
77 | - * @param string $fragment |
|
78 | - * @return XMLHelper_HTMLLoader |
|
79 | - */ |
|
73 | + /** |
|
74 | + * Creates an HTML loader from an HTML fragment (without |
|
75 | + * doctype, head and body elements). |
|
76 | + * |
|
77 | + * @param string $fragment |
|
78 | + * @return XMLHelper_HTMLLoader |
|
79 | + */ |
|
80 | 80 | public static function loadFragment(string $fragment) : XMLHelper_HTMLLoader |
81 | 81 | { |
82 | 82 | self::checkFragment($fragment); |
@@ -87,24 +87,24 @@ discard block |
||
87 | 87 | return new XMLHelper_HTMLLoader($pseudoHTML); |
88 | 88 | } |
89 | 89 | |
90 | - /** |
|
91 | - * Creates an HTML loader from a full HTML document (including |
|
92 | - * doctype, head and body elements). |
|
93 | - * |
|
94 | - * @param string $html |
|
95 | - * @return XMLHelper_HTMLLoader |
|
96 | - */ |
|
90 | + /** |
|
91 | + * Creates an HTML loader from a full HTML document (including |
|
92 | + * doctype, head and body elements). |
|
93 | + * |
|
94 | + * @param string $html |
|
95 | + * @return XMLHelper_HTMLLoader |
|
96 | + */ |
|
97 | 97 | public static function loadHTML(string $html) : XMLHelper_HTMLLoader |
98 | 98 | { |
99 | 99 | return new XMLHelper_HTMLLoader($html); |
100 | 100 | } |
101 | 101 | |
102 | - /** |
|
103 | - * Verifies that the fragment does not already contain a body element or doctype. |
|
104 | - * |
|
105 | - * @param string $fragment |
|
106 | - * @throws XMLHelper_Exception |
|
107 | - */ |
|
102 | + /** |
|
103 | + * Verifies that the fragment does not already contain a body element or doctype. |
|
104 | + * |
|
105 | + * @param string $fragment |
|
106 | + * @throws XMLHelper_Exception |
|
107 | + */ |
|
108 | 108 | private static function checkFragment(string $fragment) : void |
109 | 109 | { |
110 | 110 | if(!stristr($fragment, '<body') && !stristr($fragment, 'doctype')) |
@@ -142,65 +142,65 @@ discard block |
||
142 | 142 | return $this->bodyNode; |
143 | 143 | } |
144 | 144 | |
145 | - /** |
|
146 | - * Retrieves the document's `<body>` tag node. |
|
147 | - * |
|
148 | - * @return \DOMDocument |
|
149 | - */ |
|
145 | + /** |
|
146 | + * Retrieves the document's `<body>` tag node. |
|
147 | + * |
|
148 | + * @return \DOMDocument |
|
149 | + */ |
|
150 | 150 | public function getDOM() : \DOMDocument |
151 | 151 | { |
152 | 152 | return $this->dom; |
153 | 153 | } |
154 | 154 | |
155 | - /** |
|
156 | - * Retrieves all nodes from the HTML fragment (= child nodes |
|
157 | - * of the `<body>` element). |
|
158 | - * |
|
159 | - * @return \DOMNodeList |
|
160 | - */ |
|
155 | + /** |
|
156 | + * Retrieves all nodes from the HTML fragment (= child nodes |
|
157 | + * of the `<body>` element). |
|
158 | + * |
|
159 | + * @return \DOMNodeList |
|
160 | + */ |
|
161 | 161 | public function getFragmentNodes() : \DOMNodeList |
162 | 162 | { |
163 | 163 | return $this->bodyNode->childNodes; |
164 | 164 | } |
165 | 165 | |
166 | - /** |
|
167 | - * Retrieves the LibXML HTML parsing errors collection, which |
|
168 | - * can be used to review any errors that occurred while loading |
|
169 | - * the HTML document. |
|
170 | - * |
|
171 | - * @return XMLHelper_DOMErrors |
|
172 | - */ |
|
166 | + /** |
|
167 | + * Retrieves the LibXML HTML parsing errors collection, which |
|
168 | + * can be used to review any errors that occurred while loading |
|
169 | + * the HTML document. |
|
170 | + * |
|
171 | + * @return XMLHelper_DOMErrors |
|
172 | + */ |
|
173 | 173 | public function getErrors() : XMLHelper_DOMErrors |
174 | 174 | { |
175 | 175 | return $this->errors; |
176 | 176 | } |
177 | 177 | |
178 | - /** |
|
179 | - * Returns a valid HTML string. |
|
180 | - * |
|
181 | - * @return string |
|
182 | - */ |
|
178 | + /** |
|
179 | + * Returns a valid HTML string. |
|
180 | + * |
|
181 | + * @return string |
|
182 | + */ |
|
183 | 183 | public function toHTML() : string |
184 | 184 | { |
185 | 185 | return $this->dom->saveHTML(); |
186 | 186 | } |
187 | 187 | |
188 | - /** |
|
189 | - * Returns a valid XML string. |
|
190 | - * |
|
191 | - * @return string |
|
192 | - */ |
|
188 | + /** |
|
189 | + * Returns a valid XML string. |
|
190 | + * |
|
191 | + * @return string |
|
192 | + */ |
|
193 | 193 | public function toXML() : string |
194 | 194 | { |
195 | 195 | return $this->dom->saveXML(); |
196 | 196 | } |
197 | 197 | |
198 | - /** |
|
199 | - * Converts the HTML fragment to valid XML (= all |
|
200 | - * child nodes of the `<body>` element). |
|
201 | - * |
|
202 | - * @return string |
|
203 | - */ |
|
198 | + /** |
|
199 | + * Converts the HTML fragment to valid XML (= all |
|
200 | + * child nodes of the `<body>` element). |
|
201 | + * |
|
202 | + * @return string |
|
203 | + */ |
|
204 | 204 | public function fragmentToXML() : string |
205 | 205 | { |
206 | 206 | $nodes = $this->getFragmentNodes(); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | private static function checkFragment(string $fragment) : void |
109 | 109 | { |
110 | - if(!stristr($fragment, '<body') && !stristr($fragment, 'doctype')) |
|
110 | + if (!stristr($fragment, '<body') && !stristr($fragment, 'doctype')) |
|
111 | 111 | { |
112 | 112 | return; |
113 | 113 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | |
208 | 208 | // capture all elements except the body tag itself |
209 | 209 | $xml = ''; |
210 | - foreach($nodes as $child) |
|
210 | + foreach ($nodes as $child) |
|
211 | 211 | { |
212 | 212 | $xml .= $this->dom->saveXML($child); |
213 | 213 | } |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | { |
24 | 24 | const SERIALIZE_SEPARATOR = '__SERSEP__'; |
25 | 25 | |
26 | - /** |
|
27 | - * @var XMLHelper_DOMErrors_Error[] |
|
28 | - */ |
|
26 | + /** |
|
27 | + * @var XMLHelper_DOMErrors_Error[] |
|
28 | + */ |
|
29 | 29 | private $errors; |
30 | 30 | |
31 | - /** |
|
32 | - * @param \LibXMLError[]|XMLHelper_DOMErrors_Error[] $libxmlErrors |
|
33 | - */ |
|
31 | + /** |
|
32 | + * @param \LibXMLError[]|XMLHelper_DOMErrors_Error[] $libxmlErrors |
|
33 | + */ |
|
34 | 34 | public function __construct(array $libxmlErrors) |
35 | 35 | { |
36 | 36 | foreach($libxmlErrors as $error) |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | return $this->errors; |
57 | 57 | } |
58 | 58 | |
59 | - /** |
|
60 | - * Retrieves all warnings, if any. |
|
61 | - * |
|
62 | - * @return XMLHelper_DOMErrors_Error[] |
|
63 | - */ |
|
59 | + /** |
|
60 | + * Retrieves all warnings, if any. |
|
61 | + * |
|
62 | + * @return XMLHelper_DOMErrors_Error[] |
|
63 | + */ |
|
64 | 64 | public function getWarnings() |
65 | 65 | { |
66 | 66 | return $this->getByLevel(LIBXML_ERR_WARNING); |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | } |
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * Retrieves all errors by the specified libxml error level. |
|
112 | - * |
|
113 | - * @param int $level |
|
114 | - * @return \AppUtils\XMLHelper_DOMErrors_Error[] |
|
115 | - */ |
|
110 | + /** |
|
111 | + * Retrieves all errors by the specified libxml error level. |
|
112 | + * |
|
113 | + * @param int $level |
|
114 | + * @return \AppUtils\XMLHelper_DOMErrors_Error[] |
|
115 | + */ |
|
116 | 116 | public function getByLevel(int $level) |
117 | 117 | { |
118 | 118 | $result = array(); |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | return $result; |
129 | 129 | } |
130 | 130 | |
131 | - /** |
|
132 | - * Retrieves all errors by the specified libxml error code. |
|
133 | - * |
|
134 | - * @param int $code |
|
135 | - * @return \AppUtils\XMLHelper_DOMErrors_Error[] |
|
136 | - */ |
|
131 | + /** |
|
132 | + * Retrieves all errors by the specified libxml error code. |
|
133 | + * |
|
134 | + * @param int $code |
|
135 | + * @return \AppUtils\XMLHelper_DOMErrors_Error[] |
|
136 | + */ |
|
137 | 137 | public function getByCode(int $code) |
138 | 138 | { |
139 | 139 | $result = array(); |
@@ -149,12 +149,12 @@ discard block |
||
149 | 149 | return $result; |
150 | 150 | } |
151 | 151 | |
152 | - /** |
|
153 | - * Checks whether there are errors matching the libxml error level. |
|
154 | - * |
|
155 | - * @param int $level |
|
156 | - * @return bool |
|
157 | - */ |
|
152 | + /** |
|
153 | + * Checks whether there are errors matching the libxml error level. |
|
154 | + * |
|
155 | + * @param int $level |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | 158 | public function hasErrorsByLevel(int $level) : bool |
159 | 159 | { |
160 | 160 | foreach($this->errors as $error) |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | |
171 | - /** |
|
172 | - * Checks whether there are any errors matching the libxml error code. |
|
173 | - * |
|
174 | - * @param int $code |
|
175 | - * @return bool |
|
176 | - */ |
|
171 | + /** |
|
172 | + * Checks whether there are any errors matching the libxml error code. |
|
173 | + * |
|
174 | + * @param int $code |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | 177 | public function hasErrorsByCode(int $code) : bool |
178 | 178 | { |
179 | 179 | foreach($this->errors as $error) |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | return $result; |
200 | 200 | } |
201 | 201 | |
202 | - /** |
|
203 | - * Serializes the errors collection, so it can be stored and |
|
204 | - * restored as needed, using the `fromSerialized()` method. |
|
205 | - * |
|
206 | - * @return string |
|
207 | - * @see XMLHelper_DOMErrors::fromSerialized() |
|
208 | - */ |
|
202 | + /** |
|
203 | + * Serializes the errors collection, so it can be stored and |
|
204 | + * restored as needed, using the `fromSerialized()` method. |
|
205 | + * |
|
206 | + * @return string |
|
207 | + * @see XMLHelper_DOMErrors::fromSerialized() |
|
208 | + */ |
|
209 | 209 | public function serialize() : string |
210 | 210 | { |
211 | 211 | $data = array(); |
@@ -218,14 +218,14 @@ discard block |
||
218 | 218 | return implode(self::SERIALIZE_SEPARATOR, $data); |
219 | 219 | } |
220 | 220 | |
221 | - /** |
|
222 | - * Restores the errors collection from a previously serialized |
|
223 | - * collection, using `serialize()`. |
|
224 | - * |
|
225 | - * @param string $serialized |
|
226 | - * @return XMLHelper_DOMErrors |
|
227 | - * @see XMLHelper_DOMErrors::serialize() |
|
228 | - */ |
|
221 | + /** |
|
222 | + * Restores the errors collection from a previously serialized |
|
223 | + * collection, using `serialize()`. |
|
224 | + * |
|
225 | + * @param string $serialized |
|
226 | + * @return XMLHelper_DOMErrors |
|
227 | + * @see XMLHelper_DOMErrors::serialize() |
|
228 | + */ |
|
229 | 229 | public static function fromSerialized(string $serialized) : XMLHelper_DOMErrors |
230 | 230 | { |
231 | 231 | $parts = explode(self::SERIALIZE_SEPARATOR, $serialized); |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | */ |
34 | 34 | public function __construct(array $libxmlErrors) |
35 | 35 | { |
36 | - foreach($libxmlErrors as $error) |
|
36 | + foreach ($libxmlErrors as $error) |
|
37 | 37 | { |
38 | - if($error instanceof XMLHelper_DOMErrors_Error) |
|
38 | + if ($error instanceof XMLHelper_DOMErrors_Error) |
|
39 | 39 | { |
40 | 40 | $this->errors[] = $error; |
41 | 41 | } |
42 | - else if($error instanceof \LibXMLError) |
|
42 | + else if ($error instanceof \LibXMLError) |
|
43 | 43 | { |
44 | 44 | $this->errors[] = new XMLHelper_DOMErrors_Error($error); |
45 | 45 | } |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | { |
118 | 118 | $result = array(); |
119 | 119 | |
120 | - foreach($this->errors as $error) |
|
120 | + foreach ($this->errors as $error) |
|
121 | 121 | { |
122 | - if($error->isLevel($level)) |
|
122 | + if ($error->isLevel($level)) |
|
123 | 123 | { |
124 | 124 | $result[] = $error; |
125 | 125 | } |
@@ -138,9 +138,9 @@ discard block |
||
138 | 138 | { |
139 | 139 | $result = array(); |
140 | 140 | |
141 | - foreach($this->errors as $error) |
|
141 | + foreach ($this->errors as $error) |
|
142 | 142 | { |
143 | - if($error->isCode($code)) |
|
143 | + if ($error->isCode($code)) |
|
144 | 144 | { |
145 | 145 | $result[] = $error; |
146 | 146 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function hasErrorsByLevel(int $level) : bool |
159 | 159 | { |
160 | - foreach($this->errors as $error) |
|
160 | + foreach ($this->errors as $error) |
|
161 | 161 | { |
162 | - if($error->isLevel($level)) |
|
162 | + if ($error->isLevel($level)) |
|
163 | 163 | { |
164 | 164 | return true; |
165 | 165 | } |
@@ -176,9 +176,9 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function hasErrorsByCode(int $code) : bool |
178 | 178 | { |
179 | - foreach($this->errors as $error) |
|
179 | + foreach ($this->errors as $error) |
|
180 | 180 | { |
181 | - if($error->isCode($code)) |
|
181 | + if ($error->isCode($code)) |
|
182 | 182 | { |
183 | 183 | return true; |
184 | 184 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | { |
192 | 192 | $result = array(); |
193 | 193 | |
194 | - foreach($this->errors as $error) |
|
194 | + foreach ($this->errors as $error) |
|
195 | 195 | { |
196 | 196 | $result[] = $error->toArray(); |
197 | 197 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | { |
211 | 211 | $data = array(); |
212 | 212 | |
213 | - foreach($this->errors as $error) |
|
213 | + foreach ($this->errors as $error) |
|
214 | 214 | { |
215 | 215 | $data[] = $error->serialize(); |
216 | 216 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | $parts = explode(self::SERIALIZE_SEPARATOR, $serialized); |
232 | 232 | $list = array(); |
233 | 233 | |
234 | - foreach($parts as $part) |
|
234 | + foreach ($parts as $part) |
|
235 | 235 | { |
236 | 236 | $list[] = XMLHelper_DOMErrors_Error::fromSerialized($part); |
237 | 237 | } |
@@ -38,8 +38,7 @@ |
||
38 | 38 | if($error instanceof XMLHelper_DOMErrors_Error) |
39 | 39 | { |
40 | 40 | $this->errors[] = $error; |
41 | - } |
|
42 | - else if($error instanceof \LibXMLError) |
|
41 | + } else if($error instanceof \LibXMLError) |
|
43 | 42 | { |
44 | 43 | $this->errors[] = new XMLHelper_DOMErrors_Error($error); |
45 | 44 | } |
@@ -14,9 +14,9 @@ |
||
14 | 14 | * @see http://www.xmlsoft.org/html/libxml-xmlerror.html |
15 | 15 | */ |
16 | 16 | |
17 | - /** |
|
18 | - * @var string $list |
|
19 | - */ |
|
17 | + /** |
|
18 | + * @var string $list |
|
19 | + */ |
|
20 | 20 | $list = file_get_contents('libxmlerrors.txt'); |
21 | 21 | $outputFile = 'LibXML.php'; |
22 | 22 | $lines = explode("\n", $list); |
@@ -22,7 +22,7 @@ |
||
22 | 22 | $lines = explode("\n", $list); |
23 | 23 | $reverseArray = array(); |
24 | 24 | |
25 | - foreach($lines as $line) |
|
25 | + foreach ($lines as $line) |
|
26 | 26 | { |
27 | 27 | $parts = explode('=', $line); |
28 | 28 | $name = trim(str_replace('XML_ERR_', '', $parts[0])); |
@@ -32,46 +32,46 @@ discard block |
||
32 | 32 | const TYPE_ERROR = 'error'; |
33 | 33 | const TYPE_SUCCESS = 'success'; |
34 | 34 | |
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | 38 | protected $message = ''; |
39 | 39 | |
40 | - /** |
|
41 | - * @var bool |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | 43 | protected $valid = true; |
44 | 44 | |
45 | - /** |
|
46 | - * @var object |
|
47 | - */ |
|
45 | + /** |
|
46 | + * @var object |
|
47 | + */ |
|
48 | 48 | protected $subject; |
49 | 49 | |
50 | - /** |
|
51 | - * @var integer |
|
52 | - */ |
|
50 | + /** |
|
51 | + * @var integer |
|
52 | + */ |
|
53 | 53 | protected $code = 0; |
54 | 54 | |
55 | - /** |
|
56 | - * @var string |
|
57 | - */ |
|
55 | + /** |
|
56 | + * @var string |
|
57 | + */ |
|
58 | 58 | protected $type = ''; |
59 | 59 | |
60 | - /** |
|
61 | - * @var integer |
|
62 | - */ |
|
60 | + /** |
|
61 | + * @var integer |
|
62 | + */ |
|
63 | 63 | private static $counter = 0; |
64 | 64 | |
65 | - /** |
|
66 | - * @var int |
|
67 | - */ |
|
65 | + /** |
|
66 | + * @var int |
|
67 | + */ |
|
68 | 68 | private $id; |
69 | 69 | |
70 | - /** |
|
71 | - * The subject being validated. |
|
72 | - * |
|
73 | - * @param object $subject |
|
74 | - */ |
|
70 | + /** |
|
71 | + * The subject being validated. |
|
72 | + * |
|
73 | + * @param object $subject |
|
74 | + */ |
|
75 | 75 | public function __construct(object $subject) |
76 | 76 | { |
77 | 77 | $this->subject = $subject; |
@@ -81,21 +81,21 @@ discard block |
||
81 | 81 | $this->id = self::$counter; |
82 | 82 | } |
83 | 83 | |
84 | - /** |
|
85 | - * Retrieves the ID of the result, which is unique within a request. |
|
86 | - * |
|
87 | - * @return int |
|
88 | - */ |
|
84 | + /** |
|
85 | + * Retrieves the ID of the result, which is unique within a request. |
|
86 | + * |
|
87 | + * @return int |
|
88 | + */ |
|
89 | 89 | public function getID() : int |
90 | 90 | { |
91 | 91 | return $this->id; |
92 | 92 | } |
93 | 93 | |
94 | - /** |
|
95 | - * Whether the validation was successful. |
|
96 | - * |
|
97 | - * @return bool |
|
98 | - */ |
|
94 | + /** |
|
95 | + * Whether the validation was successful. |
|
96 | + * |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | 99 | public function isValid() : bool |
100 | 100 | { |
101 | 101 | return $this->valid; |
@@ -126,33 +126,33 @@ discard block |
||
126 | 126 | return $this->type === $type; |
127 | 127 | } |
128 | 128 | |
129 | - /** |
|
130 | - * Retrieves the subject that was validated. |
|
131 | - * |
|
132 | - * @return object |
|
133 | - */ |
|
129 | + /** |
|
130 | + * Retrieves the subject that was validated. |
|
131 | + * |
|
132 | + * @return object |
|
133 | + */ |
|
134 | 134 | public function getSubject() : object |
135 | 135 | { |
136 | 136 | return $this->subject; |
137 | 137 | } |
138 | 138 | |
139 | - /** |
|
140 | - * Makes the result a succes, with the specified message. |
|
141 | - * |
|
142 | - * @param string $message Should not contain a date, just the system specific info. |
|
143 | - * @return OperationResult |
|
144 | - */ |
|
139 | + /** |
|
140 | + * Makes the result a succes, with the specified message. |
|
141 | + * |
|
142 | + * @param string $message Should not contain a date, just the system specific info. |
|
143 | + * @return OperationResult |
|
144 | + */ |
|
145 | 145 | public function makeSuccess(string $message, int $code=0) : OperationResult |
146 | 146 | { |
147 | 147 | return $this->setMessage(self::TYPE_SUCCESS, $message, $code, true); |
148 | 148 | } |
149 | 149 | |
150 | - /** |
|
151 | - * Sets the result as an error. |
|
152 | - * |
|
153 | - * @param string $message Should be as detailed as possible. |
|
154 | - * @return OperationResult |
|
155 | - */ |
|
150 | + /** |
|
151 | + * Sets the result as an error. |
|
152 | + * |
|
153 | + * @param string $message Should be as detailed as possible. |
|
154 | + * @return OperationResult |
|
155 | + */ |
|
156 | 156 | public function makeError(string $message, int $code=0) : OperationResult |
157 | 157 | { |
158 | 158 | return $this->setMessage(self::TYPE_ERROR, $message, $code, false); |
@@ -183,21 +183,21 @@ discard block |
||
183 | 183 | return $this->type; |
184 | 184 | } |
185 | 185 | |
186 | - /** |
|
187 | - * Retrieves the error message, if an error occurred. |
|
188 | - * |
|
189 | - * @return string The error message, or an empty string if no error occurred. |
|
190 | - */ |
|
186 | + /** |
|
187 | + * Retrieves the error message, if an error occurred. |
|
188 | + * |
|
189 | + * @return string The error message, or an empty string if no error occurred. |
|
190 | + */ |
|
191 | 191 | public function getErrorMessage() : string |
192 | 192 | { |
193 | 193 | return $this->getMessage(self::TYPE_ERROR); |
194 | 194 | } |
195 | 195 | |
196 | - /** |
|
197 | - * Retrieves the success message, if one has been provided. |
|
198 | - * |
|
199 | - * @return string |
|
200 | - */ |
|
196 | + /** |
|
197 | + * Retrieves the success message, if one has been provided. |
|
198 | + * |
|
199 | + * @return string |
|
200 | + */ |
|
201 | 201 | public function getSuccessMessage() : string |
202 | 202 | { |
203 | 203 | return $this->getMessage(self::TYPE_SUCCESS); |
@@ -213,21 +213,21 @@ discard block |
||
213 | 213 | return $this->getMessage(self::TYPE_WARNING); |
214 | 214 | } |
215 | 215 | |
216 | - /** |
|
217 | - * Whether a specific error/success code has been specified. |
|
218 | - * |
|
219 | - * @return bool |
|
220 | - */ |
|
216 | + /** |
|
217 | + * Whether a specific error/success code has been specified. |
|
218 | + * |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | 221 | public function hasCode() : bool |
222 | 222 | { |
223 | 223 | return $this->code > 0; |
224 | 224 | } |
225 | 225 | |
226 | - /** |
|
227 | - * Retrieves the error/success code, if any. |
|
228 | - * |
|
229 | - * @return int The error code, or 0 if none. |
|
230 | - */ |
|
226 | + /** |
|
227 | + * Retrieves the error/success code, if any. |
|
228 | + * |
|
229 | + * @return int The error code, or 0 if none. |
|
230 | + */ |
|
231 | 231 | public function getCode() : int |
232 | 232 | { |
233 | 233 | return $this->code; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string $message Should not contain a date, just the system specific info. |
143 | 143 | * @return OperationResult |
144 | 144 | */ |
145 | - public function makeSuccess(string $message, int $code=0) : OperationResult |
|
145 | + public function makeSuccess(string $message, int $code = 0) : OperationResult |
|
146 | 146 | { |
147 | 147 | return $this->setMessage(self::TYPE_SUCCESS, $message, $code, true); |
148 | 148 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @param string $message Should be as detailed as possible. |
154 | 154 | * @return OperationResult |
155 | 155 | */ |
156 | - public function makeError(string $message, int $code=0) : OperationResult |
|
156 | + public function makeError(string $message, int $code = 0) : OperationResult |
|
157 | 157 | { |
158 | 158 | return $this->setMessage(self::TYPE_ERROR, $message, $code, false); |
159 | 159 | } |
@@ -233,11 +233,11 @@ discard block |
||
233 | 233 | return $this->code; |
234 | 234 | } |
235 | 235 | |
236 | - public function getMessage(string $type='') : string |
|
236 | + public function getMessage(string $type = '') : string |
|
237 | 237 | { |
238 | - if(!empty($type)) |
|
238 | + if (!empty($type)) |
|
239 | 239 | { |
240 | - if($this->type === $type) |
|
240 | + if ($this->type === $type) |
|
241 | 241 | { |
242 | 242 | return $this->message; |
243 | 243 | } |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | */ |
27 | 27 | class OperationResult_Collection extends OperationResult |
28 | 28 | { |
29 | - /** |
|
30 | - * @var OperationResult[] |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var OperationResult[] |
|
31 | + */ |
|
32 | 32 | protected $results = array(); |
33 | 33 | |
34 | 34 | public function makeError(string $message, int $code=0) : OperationResult |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | return $this; |
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * @return OperationResult[] |
|
111 | - */ |
|
109 | + /** |
|
110 | + * @return OperationResult[] |
|
111 | + */ |
|
112 | 112 | public function getResults() : array |
113 | 113 | { |
114 | 114 | return $this->results; |
@@ -31,27 +31,27 @@ discard block |
||
31 | 31 | */ |
32 | 32 | protected $results = array(); |
33 | 33 | |
34 | - public function makeError(string $message, int $code=0) : OperationResult |
|
34 | + public function makeError(string $message, int $code = 0) : OperationResult |
|
35 | 35 | { |
36 | 36 | return $this->add('makeError', $message, $code); |
37 | 37 | } |
38 | 38 | |
39 | - public function makeSuccess(string $message, int $code=0) : OperationResult |
|
39 | + public function makeSuccess(string $message, int $code = 0) : OperationResult |
|
40 | 40 | { |
41 | 41 | return $this->add('makeSuccess', $message, $code); |
42 | 42 | } |
43 | 43 | |
44 | - public function makeWarning(string $message, int $code=0) : OperationResult |
|
44 | + public function makeWarning(string $message, int $code = 0) : OperationResult |
|
45 | 45 | { |
46 | 46 | return $this->add('makeWarning', $message, $code); |
47 | 47 | } |
48 | 48 | |
49 | - public function makeNotice(string $message, int $code=0) : OperationResult |
|
49 | + public function makeNotice(string $message, int $code = 0) : OperationResult |
|
50 | 50 | { |
51 | 51 | return $this->add('makeNotice', $message, $code); |
52 | 52 | } |
53 | 53 | |
54 | - protected function add(string $method, string $message, int $code=0) : OperationResult |
|
54 | + protected function add(string $method, string $message, int $code = 0) : OperationResult |
|
55 | 55 | { |
56 | 56 | $result = new OperationResult($this->subject); |
57 | 57 | $result->$method($message, $code); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | public function addResult(OperationResult $result) : OperationResult_Collection |
65 | 65 | { |
66 | - if($result instanceof OperationResult_Collection) |
|
66 | + if ($result instanceof OperationResult_Collection) |
|
67 | 67 | { |
68 | 68 | return $this->importCollection($result); |
69 | 69 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | { |
76 | 76 | $results = $collection->getResults(); |
77 | 77 | |
78 | - foreach($results as $result) |
|
78 | + foreach ($results as $result) |
|
79 | 79 | { |
80 | 80 | $this->addResult($result); |
81 | 81 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | |
112 | 112 | public function isValid() : bool |
113 | 113 | { |
114 | - foreach($this->results as $result) |
|
114 | + foreach ($this->results as $result) |
|
115 | 115 | { |
116 | - if(!$result->isValid()) |
|
116 | + if (!$result->isValid()) |
|
117 | 117 | { |
118 | 118 | return false; |
119 | 119 | } |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | |
125 | 125 | public function hasCode() : bool |
126 | 126 | { |
127 | - foreach($this->results as $result) |
|
127 | + foreach ($this->results as $result) |
|
128 | 128 | { |
129 | - if($result->hasCode()) |
|
129 | + if ($result->hasCode()) |
|
130 | 130 | { |
131 | 131 | return true; |
132 | 132 | } |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | |
138 | 138 | public function getCode() : int |
139 | 139 | { |
140 | - foreach($this->results as $result) |
|
140 | + foreach ($this->results as $result) |
|
141 | 141 | { |
142 | - if($result->hasCode()) |
|
142 | + if ($result->hasCode()) |
|
143 | 143 | { |
144 | 144 | return $result->getCode(); |
145 | 145 | } |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | return 0; |
149 | 149 | } |
150 | 150 | |
151 | - public function getMessage(string $type='') : string |
|
151 | + public function getMessage(string $type = '') : string |
|
152 | 152 | { |
153 | - foreach($this->results as $result) |
|
153 | + foreach ($this->results as $result) |
|
154 | 154 | { |
155 | 155 | $msg = $result->getMessage($type); |
156 | 156 | |
157 | - if(!empty($msg)) |
|
157 | + if (!empty($msg)) |
|
158 | 158 | { |
159 | 159 | return $msg; |
160 | 160 | } |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | |
166 | 166 | public function containsCode(int $code) : bool |
167 | 167 | { |
168 | - foreach($this->results as $result) |
|
168 | + foreach ($this->results as $result) |
|
169 | 169 | { |
170 | - if($result->getCode() === $code) |
|
170 | + if ($result->getCode() === $code) |
|
171 | 171 | { |
172 | 172 | return true; |
173 | 173 | } |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | { |
201 | 201 | $amount = 0; |
202 | 202 | |
203 | - foreach($this->results as $result) |
|
203 | + foreach ($this->results as $result) |
|
204 | 204 | { |
205 | - if($result->isType($type)) |
|
205 | + if ($result->isType($type)) |
|
206 | 206 | { |
207 | 207 | $amount++; |
208 | 208 | } |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | { |
241 | 241 | $results = array(); |
242 | 242 | |
243 | - foreach($this->results as $result) |
|
243 | + foreach ($this->results as $result) |
|
244 | 244 | { |
245 | - if($result->isType($type)) |
|
245 | + if ($result->isType($type)) |
|
246 | 246 | { |
247 | 247 | $results[] = $result; |
248 | 248 | } |
@@ -253,9 +253,9 @@ discard block |
||
253 | 253 | |
254 | 254 | public function isType(string $type) : bool |
255 | 255 | { |
256 | - foreach($this->results as $result) |
|
256 | + foreach ($this->results as $result) |
|
257 | 257 | { |
258 | - if($result->isType($type)) |
|
258 | + if ($result->isType($type)) |
|
259 | 259 | { |
260 | 260 | return true; |
261 | 261 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | $lines[] = 'Collection #'.$this->getID(); |
272 | 272 | $lines[] = 'Subject: '.get_class($this->subject); |
273 | 273 | |
274 | - foreach($this->results as $result) |
|
274 | + foreach ($this->results as $result) |
|
275 | 275 | { |
276 | 276 | $lines[] = ' - '.$result->getType().' #'.$result->getCode().' "'.$result->getMessage($result->getType()).'"'; |
277 | 277 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | public function addClass(string $name) |
34 | 34 | { |
35 | - if(!in_array($name, $this->classes)) { |
|
35 | + if (!in_array($name, $this->classes)) { |
|
36 | 36 | $this->classes[] = $name; |
37 | 37 | } |
38 | 38 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | public function addClasses(array $names) |
43 | 43 | { |
44 | - foreach($names as $name) { |
|
44 | + foreach ($names as $name) { |
|
45 | 45 | $this->addClass($name); |
46 | 46 | } |
47 | 47 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | { |
58 | 58 | $idx = array_search($name, $this->classes); |
59 | 59 | |
60 | - if($idx !== false) { |
|
60 | + if ($idx !== false) { |
|
61 | 61 | unset($this->classes[$idx]); |
62 | 62 | sort($this->classes); |
63 | 63 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function classesToAttribute() : string |
93 | 93 | { |
94 | - if(!empty($this->classes)) |
|
94 | + if (!empty($this->classes)) |
|
95 | 95 | { |
96 | 96 | return sprintf( |
97 | 97 | ' class="%s" ', |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | */ |
26 | 26 | trait Traits_Classable |
27 | 27 | { |
28 | - /** |
|
29 | - * @var string[] |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var string[] |
|
30 | + */ |
|
31 | 31 | protected $classes = array(); |
32 | 32 | |
33 | 33 | public function addClass(string $name) |
@@ -65,30 +65,30 @@ discard block |
||
65 | 65 | return $this; |
66 | 66 | } |
67 | 67 | |
68 | - /** |
|
69 | - * Retrieves a list of all classes, if any. |
|
70 | - * |
|
71 | - * @return string[] |
|
72 | - */ |
|
68 | + /** |
|
69 | + * Retrieves a list of all classes, if any. |
|
70 | + * |
|
71 | + * @return string[] |
|
72 | + */ |
|
73 | 73 | public function getClasses() : array |
74 | 74 | { |
75 | 75 | return $this->classes; |
76 | 76 | } |
77 | 77 | |
78 | - /** |
|
79 | - * Renders the class names list as space-separated string for use in an HTML tag. |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
78 | + /** |
|
79 | + * Renders the class names list as space-separated string for use in an HTML tag. |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | 83 | public function classesToString() : string |
84 | 84 | { |
85 | 85 | return implode(' ', $this->classes); |
86 | 86 | } |
87 | 87 | |
88 | - /** |
|
89 | - * Renders the "class" attribute string for inserting into an HTML tag. |
|
90 | - * @return string |
|
91 | - */ |
|
88 | + /** |
|
89 | + * Renders the "class" attribute string for inserting into an HTML tag. |
|
90 | + * @return string |
|
91 | + */ |
|
92 | 92 | public function classesToAttribute() : string |
93 | 93 | { |
94 | 94 | if(!empty($this->classes)) |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | */ |
40 | 40 | protected static $instance; |
41 | 41 | |
42 | - /** |
|
43 | - * @var string |
|
44 | - */ |
|
42 | + /** |
|
43 | + * @var string |
|
44 | + */ |
|
45 | 45 | protected $baseURL = ''; |
46 | 46 | |
47 | 47 | public function __construct() |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | $this->init(); |
52 | 52 | } |
53 | 53 | |
54 | - /** |
|
55 | - * Can be extended in a subclass, to avoid |
|
56 | - * redefining the constructor. |
|
57 | - */ |
|
54 | + /** |
|
55 | + * Can be extended in a subclass, to avoid |
|
56 | + * redefining the constructor. |
|
57 | + */ |
|
58 | 58 | protected function init() |
59 | 59 | { |
60 | 60 | |
@@ -126,30 +126,30 @@ discard block |
||
126 | 126 | return $this->buildURL($params, $dispatcher); |
127 | 127 | } |
128 | 128 | |
129 | - /** |
|
130 | - * Retrieves the name of the current dispatcher script / page. |
|
131 | - * This is made to be extended and implemented in a subclass. |
|
132 | - * |
|
133 | - * @return string |
|
134 | - */ |
|
129 | + /** |
|
130 | + * Retrieves the name of the current dispatcher script / page. |
|
131 | + * This is made to be extended and implemented in a subclass. |
|
132 | + * |
|
133 | + * @return string |
|
134 | + */ |
|
135 | 135 | public function getDispatcher() : string |
136 | 136 | { |
137 | 137 | return ''; |
138 | 138 | } |
139 | 139 | |
140 | - /** |
|
141 | - * Filters and retrieves the current request variables |
|
142 | - * to be used to build an URL to refresh the current page. |
|
143 | - * |
|
144 | - * For further customization options, use the |
|
145 | - * {@see Request::createRefreshParams()} method. |
|
146 | - * |
|
147 | - * @param array<string,mixed> $params Key => value pairs of parameters to always include in the result. |
|
148 | - * @param string[] $exclude Names of parameters to exclude from the result. |
|
149 | - * @return array<string,mixed> |
|
150 | - * |
|
151 | - * @see Request::createRefreshParams() |
|
152 | - */ |
|
140 | + /** |
|
141 | + * Filters and retrieves the current request variables |
|
142 | + * to be used to build an URL to refresh the current page. |
|
143 | + * |
|
144 | + * For further customization options, use the |
|
145 | + * {@see Request::createRefreshParams()} method. |
|
146 | + * |
|
147 | + * @param array<string,mixed> $params Key => value pairs of parameters to always include in the result. |
|
148 | + * @param string[] $exclude Names of parameters to exclude from the result. |
|
149 | + * @return array<string,mixed> |
|
150 | + * |
|
151 | + * @see Request::createRefreshParams() |
|
152 | + */ |
|
153 | 153 | public function getRefreshParams(array $params = array(), array $exclude = array()) |
154 | 154 | { |
155 | 155 | return $this->createRefreshParams() |
@@ -158,13 +158,13 @@ discard block |
||
158 | 158 | ->getParams(); |
159 | 159 | } |
160 | 160 | |
161 | - /** |
|
162 | - * Creates an instance of the helper that can be used to |
|
163 | - * retrieve the request's parameters collection, with the |
|
164 | - * possiblity to exlude and override some by rules. |
|
165 | - * |
|
166 | - * @return Request_RefreshParams |
|
167 | - */ |
|
161 | + /** |
|
162 | + * Creates an instance of the helper that can be used to |
|
163 | + * retrieve the request's parameters collection, with the |
|
164 | + * possiblity to exlude and override some by rules. |
|
165 | + * |
|
166 | + * @return Request_RefreshParams |
|
167 | + */ |
|
168 | 168 | public function createRefreshParams() : Request_RefreshParams |
169 | 169 | { |
170 | 170 | return new Request_RefreshParams(); |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | return $url; |
198 | 198 | } |
199 | 199 | |
200 | - /** |
|
201 | - * Retrieves the base URL of the application. |
|
202 | - * @return string |
|
203 | - */ |
|
200 | + /** |
|
201 | + * Retrieves the base URL of the application. |
|
202 | + * @return string |
|
203 | + */ |
|
204 | 204 | public function getBaseURL() : string |
205 | 205 | { |
206 | 206 | return $this->baseURL; |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | return $this->knownParams[$name]; |
231 | 231 | } |
232 | 232 | |
233 | - /** |
|
234 | - * Retrieves a previously registered parameter instance. |
|
235 | - * |
|
236 | - * @param string $name |
|
237 | - * @throws Request_Exception |
|
238 | - * @return Request_Param |
|
239 | - */ |
|
233 | + /** |
|
234 | + * Retrieves a previously registered parameter instance. |
|
235 | + * |
|
236 | + * @param string $name |
|
237 | + * @throws Request_Exception |
|
238 | + * @return Request_Param |
|
239 | + */ |
|
240 | 240 | public function getRegisteredParam(string $name) : Request_Param |
241 | 241 | { |
242 | 242 | if(isset($this->knownParams[$name])) { |
@@ -253,48 +253,48 @@ discard block |
||
253 | 253 | ); |
254 | 254 | } |
255 | 255 | |
256 | - /** |
|
257 | - * Checks whether a parameter with the specified name |
|
258 | - * has been registered. |
|
259 | - * |
|
260 | - * @param string $name |
|
261 | - * @return bool |
|
262 | - */ |
|
256 | + /** |
|
257 | + * Checks whether a parameter with the specified name |
|
258 | + * has been registered. |
|
259 | + * |
|
260 | + * @param string $name |
|
261 | + * @return bool |
|
262 | + */ |
|
263 | 263 | public function hasRegisteredParam(string $name) : bool |
264 | 264 | { |
265 | 265 | return isset($this->knownParams[$name]); |
266 | 266 | } |
267 | 267 | |
268 | - /** |
|
269 | - * Retrieves an indexed array with accept mime types |
|
270 | - * that the client sent, in the order of preference |
|
271 | - * the client specified. |
|
272 | - * |
|
273 | - * Example: |
|
274 | - * |
|
275 | - * array( |
|
276 | - * 'text/html', |
|
277 | - * 'application/xhtml+xml', |
|
278 | - * 'image/webp' |
|
279 | - * ... |
|
280 | - * ) |
|
281 | - * |
|
282 | - * @return array |
|
283 | - * @see Request::parseAcceptHeaders() |
|
284 | - */ |
|
268 | + /** |
|
269 | + * Retrieves an indexed array with accept mime types |
|
270 | + * that the client sent, in the order of preference |
|
271 | + * the client specified. |
|
272 | + * |
|
273 | + * Example: |
|
274 | + * |
|
275 | + * array( |
|
276 | + * 'text/html', |
|
277 | + * 'application/xhtml+xml', |
|
278 | + * 'image/webp' |
|
279 | + * ... |
|
280 | + * ) |
|
281 | + * |
|
282 | + * @return array |
|
283 | + * @see Request::parseAcceptHeaders() |
|
284 | + */ |
|
285 | 285 | public static function getAcceptHeaders() : array |
286 | 286 | { |
287 | 287 | return self::parseAcceptHeaders()->getMimeStrings(); |
288 | 288 | } |
289 | 289 | |
290 | - /** |
|
291 | - * Returns an instance of the accept headers parser, |
|
292 | - * to access information on the browser's accepted |
|
293 | - * mime types. |
|
294 | - * |
|
295 | - * @return Request_AcceptHeaders |
|
296 | - * @see Request::getAcceptHeaders() |
|
297 | - */ |
|
290 | + /** |
|
291 | + * Returns an instance of the accept headers parser, |
|
292 | + * to access information on the browser's accepted |
|
293 | + * mime types. |
|
294 | + * |
|
295 | + * @return Request_AcceptHeaders |
|
296 | + * @see Request::getAcceptHeaders() |
|
297 | + */ |
|
298 | 298 | public static function parseAcceptHeaders() : Request_AcceptHeaders |
299 | 299 | { |
300 | 300 | static $accept; |
@@ -342,14 +342,14 @@ discard block |
||
342 | 342 | return false; |
343 | 343 | } |
344 | 344 | |
345 | - /** |
|
346 | - * Removes a single parameter from the request. |
|
347 | - * If the parameter has been registered, also |
|
348 | - * removes the registration info. |
|
349 | - * |
|
350 | - * @param string $name |
|
351 | - * @return Request |
|
352 | - */ |
|
345 | + /** |
|
346 | + * Removes a single parameter from the request. |
|
347 | + * If the parameter has been registered, also |
|
348 | + * removes the registration info. |
|
349 | + * |
|
350 | + * @param string $name |
|
351 | + * @return Request |
|
352 | + */ |
|
353 | 353 | public function removeParam(string $name) : Request |
354 | 354 | { |
355 | 355 | if(isset($_REQUEST[$name])) { |
@@ -363,12 +363,12 @@ discard block |
||
363 | 363 | return $this; |
364 | 364 | } |
365 | 365 | |
366 | - /** |
|
367 | - * Removes several parameters from the request. |
|
368 | - * |
|
369 | - * @param string[] $names |
|
370 | - * @return Request |
|
371 | - */ |
|
366 | + /** |
|
367 | + * Removes several parameters from the request. |
|
368 | + * |
|
369 | + * @param string[] $names |
|
370 | + * @return Request |
|
371 | + */ |
|
372 | 372 | public function removeParams(array $names) : Request |
373 | 373 | { |
374 | 374 | foreach($names as $name) { |
@@ -435,18 +435,18 @@ discard block |
||
435 | 435 | return $val; |
436 | 436 | } |
437 | 437 | |
438 | - /** |
|
439 | - * Treats the request parameter as a JSON string, and |
|
440 | - * if it exists and contains valid JSON, returns the |
|
441 | - * decoded JSON value as an array (default). |
|
442 | - * |
|
443 | - * @param string $name |
|
444 | - * @param bool $assoc |
|
445 | - * @return array|object |
|
446 | - * |
|
447 | - * @see Request::getJSONAssoc() |
|
448 | - * @see Request::getJSONObject() |
|
449 | - */ |
|
438 | + /** |
|
439 | + * Treats the request parameter as a JSON string, and |
|
440 | + * if it exists and contains valid JSON, returns the |
|
441 | + * decoded JSON value as an array (default). |
|
442 | + * |
|
443 | + * @param string $name |
|
444 | + * @param bool $assoc |
|
445 | + * @return array|object |
|
446 | + * |
|
447 | + * @see Request::getJSONAssoc() |
|
448 | + * @see Request::getJSONObject() |
|
449 | + */ |
|
450 | 450 | public function getJSON(string $name, bool $assoc=true) |
451 | 451 | { |
452 | 452 | $value = $this->getParam($name); |
@@ -471,13 +471,13 @@ discard block |
||
471 | 471 | return new \stdClass(); |
472 | 472 | } |
473 | 473 | |
474 | - /** |
|
475 | - * Like {@link Request::getJSON()}, but omitting the second |
|
476 | - * parameter. Use this for more readable code. |
|
477 | - * |
|
478 | - * @param string $name |
|
479 | - * @return array |
|
480 | - */ |
|
474 | + /** |
|
475 | + * Like {@link Request::getJSON()}, but omitting the second |
|
476 | + * parameter. Use this for more readable code. |
|
477 | + * |
|
478 | + * @param string $name |
|
479 | + * @return array |
|
480 | + */ |
|
481 | 481 | public function getJSONAssoc(string $name) : array |
482 | 482 | { |
483 | 483 | $result = $this->getJSON($name); |
@@ -488,13 +488,13 @@ discard block |
||
488 | 488 | return array(); |
489 | 489 | } |
490 | 490 | |
491 | - /** |
|
492 | - * Like {@link Request::getJSON()}, but omitting the second |
|
493 | - * parameter. Use this for more readable code. |
|
494 | - * |
|
495 | - * @param string $name |
|
496 | - * @return object |
|
497 | - */ |
|
491 | + /** |
|
492 | + * Like {@link Request::getJSON()}, but omitting the second |
|
493 | + * parameter. Use this for more readable code. |
|
494 | + * |
|
495 | + * @param string $name |
|
496 | + * @return object |
|
497 | + */ |
|
498 | 498 | public function getJSONObject(string $name) : object |
499 | 499 | { |
500 | 500 | $result = $this->getJSON($name, false); |
@@ -505,12 +505,12 @@ discard block |
||
505 | 505 | return new \stdClass(); |
506 | 506 | } |
507 | 507 | |
508 | - /** |
|
509 | - * Sends a JSON response with the correct headers. |
|
510 | - * |
|
511 | - * @param array|string $data |
|
512 | - * @param bool $exit Whether to exit the script afterwards. |
|
513 | - */ |
|
508 | + /** |
|
509 | + * Sends a JSON response with the correct headers. |
|
510 | + * |
|
511 | + * @param array|string $data |
|
512 | + * @param bool $exit Whether to exit the script afterwards. |
|
513 | + */ |
|
514 | 514 | public static function sendJSON($data, bool $exit=true) |
515 | 515 | { |
516 | 516 | $payload = $data; |
@@ -530,12 +530,12 @@ discard block |
||
530 | 530 | } |
531 | 531 | } |
532 | 532 | |
533 | - /** |
|
534 | - * Sends HTML to the browser with the correct headers. |
|
535 | - * |
|
536 | - * @param string $html |
|
537 | - * @param bool $exit Whether to exit the script afterwards. |
|
538 | - */ |
|
533 | + /** |
|
534 | + * Sends HTML to the browser with the correct headers. |
|
535 | + * |
|
536 | + * @param string $html |
|
537 | + * @param bool $exit Whether to exit the script afterwards. |
|
538 | + */ |
|
539 | 539 | public static function sendHTML(string $html, bool $exit=true) |
540 | 540 | { |
541 | 541 | header('Cache-Control: no-cache, must-revalidate'); |
@@ -550,16 +550,16 @@ discard block |
||
550 | 550 | } |
551 | 551 | } |
552 | 552 | |
553 | - /** |
|
554 | - * Creates a new instance of the URL comparer, which can check |
|
555 | - * whether the specified URLs match, regardless of the order in |
|
556 | - * which the query parameters are, if any. |
|
557 | - * |
|
558 | - * @param string $sourceURL |
|
559 | - * @param string $targetURL |
|
560 | - * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
561 | - * @return Request_URLComparer |
|
562 | - */ |
|
553 | + /** |
|
554 | + * Creates a new instance of the URL comparer, which can check |
|
555 | + * whether the specified URLs match, regardless of the order in |
|
556 | + * which the query parameters are, if any. |
|
557 | + * |
|
558 | + * @param string $sourceURL |
|
559 | + * @param string $targetURL |
|
560 | + * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
561 | + * @return Request_URLComparer |
|
562 | + */ |
|
563 | 563 | public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
564 | 564 | { |
565 | 565 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
@@ -568,10 +568,10 @@ discard block |
||
568 | 568 | return $comparer; |
569 | 569 | } |
570 | 570 | |
571 | - /** |
|
572 | - * Retrieves the full URL that was used to access the current page. |
|
573 | - * @return string |
|
574 | - */ |
|
571 | + /** |
|
572 | + * Retrieves the full URL that was used to access the current page. |
|
573 | + * @return string |
|
574 | + */ |
|
575 | 575 | public function getCurrentURL() : string |
576 | 576 | { |
577 | 577 | return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | public function getParam($name, $default = null) |
91 | 91 | { |
92 | 92 | $value = $default; |
93 | - if(isset($_REQUEST[$name])) { |
|
93 | + if (isset($_REQUEST[$name])) { |
|
94 | 94 | $value = $_REQUEST[$name]; |
95 | 95 | } |
96 | 96 | |
97 | - if(isset($this->knownParams[$name])) { |
|
97 | + if (isset($this->knownParams[$name])) { |
|
98 | 98 | $value = $this->knownParams[$name]->validate($value); |
99 | 99 | } |
100 | 100 | |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | * @param string $dispatcher Relative path to script to use for the URL. Append trailing slash if needed. |
186 | 186 | * @return string |
187 | 187 | */ |
188 | - public function buildURL($params = array(), string $dispatcher='') |
|
188 | + public function buildURL($params = array(), string $dispatcher = '') |
|
189 | 189 | { |
190 | - $url = rtrim($this->getBaseURL(), '/') . '/' . $dispatcher; |
|
190 | + $url = rtrim($this->getBaseURL(), '/').'/'.$dispatcher; |
|
191 | 191 | |
192 | 192 | // append any leftover parameters to the end of the URL |
193 | 193 | if (!empty($params)) { |
194 | - $url .= '?' . http_build_query($params, '', '&'); |
|
194 | + $url .= '?'.http_build_query($params, '', '&'); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | return $url; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function registerParam($name) |
224 | 224 | { |
225 | - if(!isset($this->knownParams[$name])) { |
|
225 | + if (!isset($this->knownParams[$name])) { |
|
226 | 226 | $param = new Request_Param($this, $name); |
227 | 227 | $this->knownParams[$name] = $param; |
228 | 228 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function getRegisteredParam(string $name) : Request_Param |
241 | 241 | { |
242 | - if(isset($this->knownParams[$name])) { |
|
242 | + if (isset($this->knownParams[$name])) { |
|
243 | 243 | return $this->knownParams[$name]; |
244 | 244 | } |
245 | 245 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | { |
300 | 300 | static $accept; |
301 | 301 | |
302 | - if(!isset($accept)) { |
|
302 | + if (!isset($accept)) { |
|
303 | 303 | $accept = new Request_AcceptHeaders(); |
304 | 304 | } |
305 | 305 | |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | { |
319 | 319 | $_REQUEST[$name] = $value; |
320 | 320 | |
321 | - if(isset($this->knownParams[$name])) { |
|
321 | + if (isset($this->knownParams[$name])) { |
|
322 | 322 | unset($this->knownParams[$name]); |
323 | 323 | } |
324 | 324 | |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | */ |
353 | 353 | public function removeParam(string $name) : Request |
354 | 354 | { |
355 | - if(isset($_REQUEST[$name])) { |
|
355 | + if (isset($_REQUEST[$name])) { |
|
356 | 356 | unset($_REQUEST[$name]); |
357 | 357 | } |
358 | 358 | |
359 | - if(isset($this->knownParams[$name])) { |
|
359 | + if (isset($this->knownParams[$name])) { |
|
360 | 360 | unset($this->knownParams[$name]); |
361 | 361 | } |
362 | 362 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function removeParams(array $names) : Request |
373 | 373 | { |
374 | - foreach($names as $name) { |
|
374 | + foreach ($names as $name) { |
|
375 | 375 | $this->removeParam($name); |
376 | 376 | } |
377 | 377 | |
@@ -387,10 +387,10 @@ discard block |
||
387 | 387 | * @param string $name |
388 | 388 | * @return bool |
389 | 389 | */ |
390 | - public function getBool($name, $default=false) |
|
390 | + public function getBool($name, $default = false) |
|
391 | 391 | { |
392 | 392 | $value = $this->getParam($name, $default); |
393 | - if(ConvertHelper::isBoolean($value)) { |
|
393 | + if (ConvertHelper::isBoolean($value)) { |
|
394 | 394 | return ConvertHelper::string2bool($value); |
395 | 395 | } |
396 | 396 | |
@@ -399,11 +399,11 @@ discard block |
||
399 | 399 | |
400 | 400 | public function validate() |
401 | 401 | { |
402 | - foreach($this->knownParams as $param) |
|
402 | + foreach ($this->knownParams as $param) |
|
403 | 403 | { |
404 | 404 | $name = $param->getName(); |
405 | 405 | |
406 | - if($param->isRequired() && !$this->hasParam($name)) |
|
406 | + if ($param->isRequired() && !$this->hasParam($name)) |
|
407 | 407 | { |
408 | 408 | throw new Request_Exception( |
409 | 409 | 'Missing request parameter '.$name, |
@@ -425,10 +425,10 @@ discard block |
||
425 | 425 | * @param mixed $default |
426 | 426 | * @return string |
427 | 427 | */ |
428 | - public function getFilteredParam($name, $default=null) |
|
428 | + public function getFilteredParam($name, $default = null) |
|
429 | 429 | { |
430 | 430 | $val = $this->getParam($name, $default); |
431 | - if(is_string($val)) { |
|
431 | + if (is_string($val)) { |
|
432 | 432 | $val = htmlspecialchars(trim(strip_tags($val)), ENT_QUOTES, 'UTF-8'); |
433 | 433 | } |
434 | 434 | |
@@ -447,24 +447,24 @@ discard block |
||
447 | 447 | * @see Request::getJSONAssoc() |
448 | 448 | * @see Request::getJSONObject() |
449 | 449 | */ |
450 | - public function getJSON(string $name, bool $assoc=true) |
|
450 | + public function getJSON(string $name, bool $assoc = true) |
|
451 | 451 | { |
452 | 452 | $value = $this->getParam($name); |
453 | 453 | |
454 | - if(!empty($value) && is_string($value)) |
|
454 | + if (!empty($value) && is_string($value)) |
|
455 | 455 | { |
456 | 456 | $data = json_decode($value, $assoc); |
457 | 457 | |
458 | - if($assoc && is_array($data)) { |
|
458 | + if ($assoc && is_array($data)) { |
|
459 | 459 | return $data; |
460 | 460 | } |
461 | 461 | |
462 | - if(is_object($data)) { |
|
462 | + if (is_object($data)) { |
|
463 | 463 | return $data; |
464 | 464 | } |
465 | 465 | } |
466 | 466 | |
467 | - if($assoc) { |
|
467 | + if ($assoc) { |
|
468 | 468 | return array(); |
469 | 469 | } |
470 | 470 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | public function getJSONAssoc(string $name) : array |
482 | 482 | { |
483 | 483 | $result = $this->getJSON($name); |
484 | - if(is_array($result)) { |
|
484 | + if (is_array($result)) { |
|
485 | 485 | return $result; |
486 | 486 | } |
487 | 487 | |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | public function getJSONObject(string $name) : object |
499 | 499 | { |
500 | 500 | $result = $this->getJSON($name, false); |
501 | - if(is_object($result)) { |
|
501 | + if (is_object($result)) { |
|
502 | 502 | return $result; |
503 | 503 | } |
504 | 504 | |
@@ -511,10 +511,10 @@ discard block |
||
511 | 511 | * @param array|string $data |
512 | 512 | * @param bool $exit Whether to exit the script afterwards. |
513 | 513 | */ |
514 | - public static function sendJSON($data, bool $exit=true) |
|
514 | + public static function sendJSON($data, bool $exit = true) |
|
515 | 515 | { |
516 | 516 | $payload = $data; |
517 | - if(!is_string($payload)) { |
|
517 | + if (!is_string($payload)) { |
|
518 | 518 | $payload = json_encode($payload); |
519 | 519 | } |
520 | 520 | |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | |
525 | 525 | echo $payload; |
526 | 526 | |
527 | - if($exit) |
|
527 | + if ($exit) |
|
528 | 528 | { |
529 | 529 | exit; |
530 | 530 | } |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | * @param string $html |
537 | 537 | * @param bool $exit Whether to exit the script afterwards. |
538 | 538 | */ |
539 | - public static function sendHTML(string $html, bool $exit=true) |
|
539 | + public static function sendHTML(string $html, bool $exit = true) |
|
540 | 540 | { |
541 | 541 | header('Cache-Control: no-cache, must-revalidate'); |
542 | 542 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | |
545 | 545 | echo $html; |
546 | 546 | |
547 | - if($exit) |
|
547 | + if ($exit) |
|
548 | 548 | { |
549 | 549 | exit; |
550 | 550 | } |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
561 | 561 | * @return Request_URLComparer |
562 | 562 | */ |
563 | - public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
|
563 | + public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams = array()) : Request_URLComparer |
|
564 | 564 | { |
565 | 565 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
566 | 566 | $comparer->addLimitParams($limitParams); |
@@ -19,9 +19,9 @@ |
||
19 | 19 | */ |
20 | 20 | class Request_RefreshParams_Exclude_Name extends Request_RefreshParams_Exclude |
21 | 21 | { |
22 | - /** |
|
23 | - * @var string |
|
24 | - */ |
|
22 | + /** |
|
23 | + * @var string |
|
24 | + */ |
|
25 | 25 | private $name; |
26 | 26 | |
27 | 27 | public function __construct(string $paramName) |
@@ -22,9 +22,9 @@ |
||
22 | 22 | { |
23 | 23 | const ERROR_INVALID_CALLBACK = 62101; |
24 | 24 | |
25 | - /** |
|
26 | - * @var callable |
|
27 | - */ |
|
25 | + /** |
|
26 | + * @var callable |
|
27 | + */ |
|
28 | 28 | private $callback; |
29 | 29 | |
30 | 30 | public function __construct($callback) |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | public function __construct($callback) |
31 | 31 | { |
32 | - if(!is_callable($callback)) |
|
32 | + if (!is_callable($callback)) |
|
33 | 33 | { |
34 | 34 | throw new Request_Exception( |
35 | 35 | 'Invalid exclusion callback', |