Complex classes like PrettyPageHandler often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PrettyPageHandler, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class PrettyPageHandler extends Handler |
||
19 | { |
||
20 | /** |
||
21 | * Search paths to be scanned for resources, in the reverse |
||
22 | * order they're declared. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | private $searchPaths = []; |
||
27 | |||
28 | /** |
||
29 | * Fast lookup cache for known resource locations. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private $resourceCache = []; |
||
34 | |||
35 | /** |
||
36 | * The name of the custom css file. |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | private $customCss = null; |
||
41 | |||
42 | /** |
||
43 | * @var array[] |
||
44 | */ |
||
45 | private $extraTables = []; |
||
46 | |||
47 | /** |
||
48 | * @var bool |
||
49 | */ |
||
50 | private $handleUnconditionally = false; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | private $pageTitle = "Whoops! There was an error."; |
||
56 | |||
57 | /** |
||
58 | * @var array[] |
||
59 | */ |
||
60 | private $applicationPaths; |
||
61 | |||
62 | /** |
||
63 | * @var array[] |
||
64 | */ |
||
65 | private $blacklist = [ |
||
66 | '_GET' => [], |
||
67 | '_POST' => [], |
||
68 | '_FILES' => [], |
||
69 | '_COOKIE' => [], |
||
70 | '_SESSION' => [], |
||
71 | '_SERVER' => [], |
||
72 | '_ENV' => [], |
||
73 | ]; |
||
74 | |||
75 | /** |
||
76 | * A string identifier for a known IDE/text editor, or a closure |
||
77 | * that resolves a string that can be used to open a given file |
||
78 | * in an editor. If the string contains the special substrings |
||
79 | * %file or %line, they will be replaced with the correct data. |
||
80 | * |
||
81 | * @example |
||
82 | * "txmt://open?url=%file&line=%line" |
||
83 | * @var mixed $editor |
||
84 | */ |
||
85 | protected $editor; |
||
86 | |||
87 | /** |
||
88 | * A list of known editor strings |
||
89 | * @var array |
||
90 | */ |
||
91 | protected $editors = [ |
||
92 | "sublime" => "subl://open?url=file://%file&line=%line", |
||
93 | "textmate" => "txmt://open?url=file://%file&line=%line", |
||
94 | "emacs" => "emacs://open?url=file://%file&line=%line", |
||
95 | "macvim" => "mvim://open/?url=file://%file&line=%line", |
||
96 | "phpstorm" => "phpstorm://open?file=%file&line=%line", |
||
97 | "idea" => "idea://open?file=%file&line=%line", |
||
98 | ]; |
||
99 | |||
100 | /** |
||
101 | * @var TemplateHelper |
||
102 | */ |
||
103 | private $templateHelper; |
||
104 | |||
105 | /** |
||
106 | * Constructor. |
||
107 | */ |
||
108 | 1 | public function __construct() |
|
109 | { |
||
110 | 1 | if (ini_get('xdebug.file_link_format') || extension_loaded('xdebug')) { |
|
111 | // Register editor using xdebug's file_link_format option. |
||
112 | $this->editors['xdebug'] = function ($file, $line) { |
||
113 | 1 | return str_replace(['%f', '%l'], [$file, $line], ini_get('xdebug.file_link_format')); |
|
114 | }; |
||
115 | 1 | } |
|
116 | |||
117 | // Add the default, local resource search path: |
||
118 | 1 | $this->searchPaths[] = __DIR__ . "/../Resources"; |
|
119 | |||
120 | // blacklist php provided auth based values |
||
121 | 1 | $this->blacklist('_SERVER', 'PHP_AUTH_PW'); |
|
122 | |||
123 | 1 | $this->templateHelper = new TemplateHelper(); |
|
124 | |||
125 | 1 | if (class_exists('Symfony\Component\VarDumper\Cloner\VarCloner')) { |
|
126 | 1 | $cloner = new VarCloner(); |
|
127 | // Only dump object internals if a custom caster exists. |
||
128 | $cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) { |
||
129 | $class = $stub->class; |
||
130 | $classes = [$class => $class] + class_parents($class) + class_implements($class); |
||
131 | |||
132 | foreach ($classes as $class) { |
||
133 | if (isset(AbstractCloner::$defaultCasters[$class])) { |
||
134 | return $a; |
||
135 | } |
||
136 | } |
||
137 | |||
138 | // Remove all internals |
||
139 | return []; |
||
140 | 1 | }]); |
|
141 | 1 | $this->templateHelper->setCloner($cloner); |
|
142 | 1 | } |
|
143 | 1 | } |
|
144 | |||
145 | /** |
||
146 | * @return int|null |
||
147 | */ |
||
148 | 1 | public function handle() |
|
149 | { |
||
150 | 1 | if (!$this->handleUnconditionally()) { |
|
151 | // Check conditions for outputting HTML: |
||
152 | // @todo: Make this more robust |
||
153 | 1 | if (php_sapi_name() === 'cli') { |
|
154 | // Help users who have been relying on an internal test value |
||
155 | // fix their code to the proper method |
||
156 | 1 | if (isset($_ENV['whoops-test'])) { |
|
157 | throw new \Exception( |
||
158 | 'Use handleUnconditionally instead of whoops-test' |
||
159 | .' environment variable' |
||
160 | ); |
||
161 | } |
||
162 | |||
163 | 1 | return Handler::DONE; |
|
164 | } |
||
165 | } |
||
166 | |||
167 | $templateFile = $this->getResource("views/layout.html.php"); |
||
168 | $cssFile = $this->getResource("css/whoops.base.css"); |
||
169 | $zeptoFile = $this->getResource("js/zepto.min.js"); |
||
170 | $clipboard = $this->getResource("js/clipboard.min.js"); |
||
171 | $jsFile = $this->getResource("js/whoops.base.js"); |
||
172 | |||
173 | if ($this->customCss) { |
||
174 | $customCssFile = $this->getResource($this->customCss); |
||
175 | } |
||
176 | |||
177 | $inspector = $this->getInspector(); |
||
178 | $frames = $inspector->getFrames(); |
||
179 | |||
180 | $code = $inspector->getException()->getCode(); |
||
181 | |||
182 | if ($inspector->getException() instanceof \ErrorException) { |
||
183 | // ErrorExceptions wrap the php-error types within the "severity" property |
||
184 | $code = Misc::translateErrorCode($inspector->getException()->getSeverity()); |
||
185 | } |
||
186 | |||
187 | // Detect frames that belong to the application. |
||
188 | if ($this->applicationPaths) { |
||
189 | /* @var \Whoops\Exception\Frame $frame */ |
||
190 | foreach ($frames as $frame) { |
||
191 | foreach ($this->applicationPaths as $path) { |
||
192 | if (substr($frame->getFile(), 0, strlen($path)) === $path) { |
||
193 | $frame->setApplication(true); |
||
194 | break; |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | } |
||
199 | |||
200 | // List of variables that will be passed to the layout template. |
||
201 | $vars = [ |
||
202 | "page_title" => $this->getPageTitle(), |
||
203 | |||
204 | // @todo: Asset compiler |
||
205 | "stylesheet" => file_get_contents($cssFile), |
||
206 | "zepto" => file_get_contents($zeptoFile), |
||
207 | "clipboard" => file_get_contents($clipboard), |
||
208 | "javascript" => file_get_contents($jsFile), |
||
209 | |||
210 | // Template paths: |
||
211 | "header" => $this->getResource("views/header.html.php"), |
||
212 | "header_outer" => $this->getResource("views/header_outer.html.php"), |
||
213 | "frame_list" => $this->getResource("views/frame_list.html.php"), |
||
214 | "frames_description" => $this->getResource("views/frames_description.html.php"), |
||
215 | "frames_container" => $this->getResource("views/frames_container.html.php"), |
||
216 | "panel_details" => $this->getResource("views/panel_details.html.php"), |
||
217 | "panel_details_outer" => $this->getResource("views/panel_details_outer.html.php"), |
||
218 | "panel_left" => $this->getResource("views/panel_left.html.php"), |
||
219 | "panel_left_outer" => $this->getResource("views/panel_left_outer.html.php"), |
||
220 | "frame_code" => $this->getResource("views/frame_code.html.php"), |
||
221 | "env_details" => $this->getResource("views/env_details.html.php"), |
||
222 | |||
223 | "title" => $this->getPageTitle(), |
||
224 | "name" => explode("\\", $inspector->getExceptionName()), |
||
225 | "message" => $inspector->getExceptionMessage(), |
||
226 | "docref_url" => $inspector->getExceptionDocrefUrl(), |
||
227 | "code" => $code, |
||
228 | "plain_exception" => Formatter::formatExceptionPlain($inspector), |
||
229 | "frames" => $frames, |
||
230 | "has_frames" => !!count($frames), |
||
231 | "handler" => $this, |
||
232 | "handlers" => $this->getRun()->getHandlers(), |
||
233 | |||
234 | "active_frames_tab" => count($frames) && $frames->offsetGet(0)->isApplication() ? 'application' : 'all', |
||
235 | "has_frames_tabs" => $this->getApplicationPaths(), |
||
236 | |||
237 | "tables" => [ |
||
238 | "GET Data" => $this->masked($_GET, '_GET'), |
||
239 | "POST Data" => $this->masked($_POST, '_POST'), |
||
240 | "Files" => isset($_FILES) ? $this->masked($_FILES, '_FILES') : [], |
||
241 | "Cookies" => $this->masked($_COOKIE, '_COOKIE'), |
||
242 | "Session" => isset($_SESSION) ? $this->masked($_SESSION, '_SESSION') : [], |
||
243 | "Server/Request Data" => $this->masked($_SERVER, '_SERVER'), |
||
244 | "Environment Variables" => $this->masked($_ENV, '_ENV'), |
||
245 | ], |
||
246 | ]; |
||
247 | |||
248 | if (isset($customCssFile)) { |
||
249 | $vars["stylesheet"] .= file_get_contents($customCssFile); |
||
250 | } |
||
251 | |||
252 | // Add extra entries list of data tables: |
||
253 | // @todo: Consolidate addDataTable and addDataTableCallback |
||
254 | $extraTables = array_map(function ($table) use ($inspector) { |
||
255 | return $table instanceof \Closure ? $table($inspector) : $table; |
||
256 | }, $this->getDataTables()); |
||
257 | $vars["tables"] = array_merge($extraTables, $vars["tables"]); |
||
258 | |||
259 | $plainTextHandler = new PlainTextHandler(); |
||
260 | $plainTextHandler->setException($this->getException()); |
||
261 | $plainTextHandler->setInspector($this->getInspector()); |
||
262 | $vars["preface"] = "<!--\n\n\n" . $this->templateHelper->escape($plainTextHandler->generateResponse()) . "\n\n\n\n\n\n\n\n\n\n\n-->"; |
||
263 | |||
264 | $this->templateHelper->setVariables($vars); |
||
265 | $this->templateHelper->render($templateFile); |
||
266 | |||
267 | return Handler::QUIT; |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * @return string |
||
272 | */ |
||
273 | public function contentType() |
||
274 | { |
||
275 | return 'text/html'; |
||
276 | } |
||
277 | |||
278 | /** |
||
279 | * Adds an entry to the list of tables displayed in the template. |
||
280 | * The expected data is a simple associative array. Any nested arrays |
||
281 | * will be flattened with print_r |
||
282 | * @param string $label |
||
283 | * @param array $data |
||
284 | */ |
||
285 | 1 | public function addDataTable($label, array $data) |
|
286 | { |
||
287 | 1 | $this->extraTables[$label] = $data; |
|
288 | 1 | } |
|
289 | |||
290 | /** |
||
291 | * Lazily adds an entry to the list of tables displayed in the table. |
||
292 | * The supplied callback argument will be called when the error is rendered, |
||
293 | * it should produce a simple associative array. Any nested arrays will |
||
294 | * be flattened with print_r. |
||
295 | * |
||
296 | * @throws InvalidArgumentException If $callback is not callable |
||
297 | * @param string $label |
||
298 | * @param callable $callback Callable returning an associative array |
||
299 | */ |
||
300 | 1 | public function addDataTableCallback($label, /* callable */ $callback) |
|
301 | { |
||
302 | 1 | if (!is_callable($callback)) { |
|
303 | throw new InvalidArgumentException('Expecting callback argument to be callable'); |
||
304 | } |
||
305 | |||
306 | 1 | $this->extraTables[$label] = function (\Whoops\Exception\Inspector $inspector = null) use ($callback) { |
|
307 | try { |
||
308 | 1 | $result = call_user_func($callback, $inspector); |
|
309 | |||
310 | // Only return the result if it can be iterated over by foreach(). |
||
311 | 1 | return is_array($result) || $result instanceof \Traversable ? $result : []; |
|
312 | } catch (\Exception $e) { |
||
313 | // Don't allow failure to break the rendering of the original exception. |
||
314 | return []; |
||
315 | } |
||
316 | }; |
||
317 | 1 | } |
|
318 | |||
319 | /** |
||
320 | * Returns all the extra data tables registered with this handler. |
||
321 | * Optionally accepts a 'label' parameter, to only return the data |
||
322 | * table under that label. |
||
323 | * @param string|null $label |
||
324 | * @return array[]|callable |
||
325 | */ |
||
326 | 2 | public function getDataTables($label = null) |
|
327 | { |
||
328 | 2 | if ($label !== null) { |
|
329 | 2 | return isset($this->extraTables[$label]) ? |
|
330 | 2 | $this->extraTables[$label] : []; |
|
331 | } |
||
332 | |||
333 | 2 | return $this->extraTables; |
|
334 | } |
||
335 | |||
336 | /** |
||
337 | * Allows to disable all attempts to dynamically decide whether to |
||
338 | * handle or return prematurely. |
||
339 | * Set this to ensure that the handler will perform no matter what. |
||
340 | * @param bool|null $value |
||
341 | * @return bool|null |
||
342 | */ |
||
343 | 1 | public function handleUnconditionally($value = null) |
|
344 | { |
||
345 | 1 | if (func_num_args() == 0) { |
|
346 | 1 | return $this->handleUnconditionally; |
|
347 | } |
||
348 | |||
349 | $this->handleUnconditionally = (bool) $value; |
||
350 | } |
||
351 | |||
352 | /** |
||
353 | * Adds an editor resolver, identified by a string |
||
354 | * name, and that may be a string path, or a callable |
||
355 | * resolver. If the callable returns a string, it will |
||
356 | * be set as the file reference's href attribute. |
||
357 | * |
||
358 | * @example |
||
359 | * $run->addEditor('macvim', "mvim://open?url=file://%file&line=%line") |
||
360 | * @example |
||
361 | * $run->addEditor('remove-it', function($file, $line) { |
||
362 | * unlink($file); |
||
363 | * return "http://stackoverflow.com"; |
||
364 | * }); |
||
365 | * @param string $identifier |
||
366 | * @param string $resolver |
||
367 | */ |
||
368 | 1 | public function addEditor($identifier, $resolver) |
|
369 | { |
||
370 | 1 | $this->editors[$identifier] = $resolver; |
|
371 | 1 | } |
|
372 | |||
373 | /** |
||
374 | * Set the editor to use to open referenced files, by a string |
||
375 | * identifier, or a callable that will be executed for every |
||
376 | * file reference, with a $file and $line argument, and should |
||
377 | * return a string. |
||
378 | * |
||
379 | * @example |
||
380 | * $run->setEditor(function($file, $line) { return "file:///{$file}"; }); |
||
381 | * @example |
||
382 | * $run->setEditor('sublime'); |
||
383 | * |
||
384 | * @throws InvalidArgumentException If invalid argument identifier provided |
||
385 | * @param string|callable $editor |
||
386 | */ |
||
387 | 4 | public function setEditor($editor) |
|
388 | { |
||
389 | 4 | if (!is_callable($editor) && !isset($this->editors[$editor])) { |
|
390 | throw new InvalidArgumentException( |
||
391 | "Unknown editor identifier: $editor. Known editors:" . |
||
392 | implode(",", array_keys($this->editors)) |
||
393 | ); |
||
394 | } |
||
395 | |||
396 | 4 | $this->editor = $editor; |
|
397 | 4 | } |
|
398 | |||
399 | /** |
||
400 | * Given a string file path, and an integer file line, |
||
401 | * executes the editor resolver and returns, if available, |
||
402 | * a string that may be used as the href property for that |
||
403 | * file reference. |
||
404 | * |
||
405 | * @throws InvalidArgumentException If editor resolver does not return a string |
||
406 | * @param string $filePath |
||
407 | * @param int $line |
||
408 | * @return string|bool |
||
409 | */ |
||
410 | 4 | public function getEditorHref($filePath, $line) |
|
411 | { |
||
412 | 4 | $editor = $this->getEditor($filePath, $line); |
|
413 | |||
414 | 4 | if (empty($editor)) { |
|
415 | return false; |
||
416 | } |
||
417 | |||
418 | // Check that the editor is a string, and replace the |
||
419 | // %line and %file placeholders: |
||
420 | 4 | if (!isset($editor['url']) || !is_string($editor['url'])) { |
|
421 | throw new UnexpectedValueException( |
||
422 | __METHOD__ . " should always resolve to a string or a valid editor array; got something else instead." |
||
423 | ); |
||
424 | } |
||
425 | |||
426 | 4 | $editor['url'] = str_replace("%line", rawurlencode($line), $editor['url']); |
|
427 | 4 | $editor['url'] = str_replace("%file", rawurlencode($filePath), $editor['url']); |
|
428 | |||
429 | 4 | return $editor['url']; |
|
430 | } |
||
431 | |||
432 | /** |
||
433 | * Given a boolean if the editor link should |
||
434 | * act as an Ajax request. The editor must be a |
||
435 | * valid callable function/closure |
||
436 | * |
||
437 | * @throws UnexpectedValueException If editor resolver does not return a boolean |
||
438 | * @param string $filePath |
||
439 | * @param int $line |
||
440 | * @return bool |
||
441 | */ |
||
442 | 1 | public function getEditorAjax($filePath, $line) |
|
443 | { |
||
444 | 1 | $editor = $this->getEditor($filePath, $line); |
|
445 | |||
446 | // Check that the ajax is a bool |
||
447 | 1 | if (!isset($editor['ajax']) || !is_bool($editor['ajax'])) { |
|
448 | throw new UnexpectedValueException( |
||
449 | __METHOD__ . " should always resolve to a bool; got something else instead." |
||
450 | ); |
||
451 | } |
||
452 | 1 | return $editor['ajax']; |
|
453 | } |
||
454 | |||
455 | /** |
||
456 | * Given a boolean if the editor link should |
||
457 | * act as an Ajax request. The editor must be a |
||
458 | * valid callable function/closure |
||
459 | * |
||
460 | * @param string $filePath |
||
461 | * @param int $line |
||
462 | * @return array |
||
463 | */ |
||
464 | 1 | protected function getEditor($filePath, $line) |
|
465 | { |
||
466 | 1 | if (!$this->editor || (!is_string($this->editor) && !is_callable($this->editor))) { |
|
467 | return []; |
||
468 | } |
||
469 | |||
470 | 1 | if (is_string($this->editor) && isset($this->editors[$this->editor]) && !is_callable($this->editors[$this->editor])) { |
|
471 | return [ |
||
472 | 'ajax' => false, |
||
473 | 'url' => $this->editors[$this->editor], |
||
474 | ]; |
||
475 | } |
||
476 | |||
477 | 1 | if (is_callable($this->editor) || (isset($this->editors[$this->editor]) && is_callable($this->editors[$this->editor]))) { |
|
478 | 1 | if (is_callable($this->editor)) { |
|
479 | $callback = call_user_func($this->editor, $filePath, $line); |
||
480 | } else { |
||
481 | 1 | $callback = call_user_func($this->editors[$this->editor], $filePath, $line); |
|
482 | } |
||
483 | |||
484 | 1 | if (is_string($callback)) { |
|
485 | return [ |
||
486 | 1 | 'ajax' => false, |
|
487 | 1 | 'url' => $callback, |
|
488 | 1 | ]; |
|
489 | } |
||
490 | |||
491 | return [ |
||
492 | 'ajax' => isset($callback['ajax']) ? $callback['ajax'] : false, |
||
493 | 'url' => isset($callback['url']) ? $callback['url'] : $callback, |
||
494 | ]; |
||
495 | } |
||
496 | |||
497 | return []; |
||
498 | } |
||
499 | |||
500 | /** |
||
501 | * @param string $title |
||
502 | * @return void |
||
503 | */ |
||
504 | 1 | public function setPageTitle($title) |
|
505 | { |
||
506 | 1 | $this->pageTitle = (string) $title; |
|
507 | 1 | } |
|
508 | |||
509 | /** |
||
510 | * @return string |
||
511 | */ |
||
512 | 1 | public function getPageTitle() |
|
513 | { |
||
514 | 1 | return $this->pageTitle; |
|
515 | } |
||
516 | |||
517 | /** |
||
518 | * Adds a path to the list of paths to be searched for |
||
519 | * resources. |
||
520 | * |
||
521 | * @throws InvalidArgumentException If $path is not a valid directory |
||
522 | * |
||
523 | * @param string $path |
||
524 | * @return void |
||
525 | */ |
||
526 | 2 | public function addResourcePath($path) |
|
527 | { |
||
528 | 2 | if (!is_dir($path)) { |
|
529 | 1 | throw new InvalidArgumentException( |
|
530 | 1 | "'$path' is not a valid directory" |
|
531 | 1 | ); |
|
532 | } |
||
533 | |||
534 | 1 | array_unshift($this->searchPaths, $path); |
|
535 | 1 | } |
|
536 | |||
537 | /** |
||
538 | * Adds a custom css file to be loaded. |
||
539 | * |
||
540 | * @param string $name |
||
541 | * @return void |
||
542 | */ |
||
543 | public function addCustomCss($name) |
||
544 | { |
||
545 | $this->customCss = $name; |
||
546 | } |
||
547 | |||
548 | /** |
||
549 | * @return array |
||
550 | */ |
||
551 | 1 | public function getResourcePaths() |
|
552 | { |
||
553 | 1 | return $this->searchPaths; |
|
554 | } |
||
555 | |||
556 | /** |
||
557 | * Finds a resource, by its relative path, in all available search paths. |
||
558 | * The search is performed starting at the last search path, and all the |
||
559 | * way back to the first, enabling a cascading-type system of overrides |
||
560 | * for all resources. |
||
561 | * |
||
562 | * @throws RuntimeException If resource cannot be found in any of the available paths |
||
563 | * |
||
564 | * @param string $resource |
||
565 | * @return string |
||
566 | */ |
||
567 | protected function getResource($resource) |
||
568 | { |
||
569 | // If the resource was found before, we can speed things up |
||
570 | // by caching its absolute, resolved path: |
||
571 | if (isset($this->resourceCache[$resource])) { |
||
572 | return $this->resourceCache[$resource]; |
||
573 | } |
||
574 | |||
575 | // Search through available search paths, until we find the |
||
576 | // resource we're after: |
||
577 | foreach ($this->searchPaths as $path) { |
||
578 | $fullPath = $path . "/$resource"; |
||
579 | |||
580 | if (is_file($fullPath)) { |
||
581 | // Cache the result: |
||
582 | $this->resourceCache[$resource] = $fullPath; |
||
583 | return $fullPath; |
||
584 | } |
||
585 | } |
||
586 | |||
587 | // If we got this far, nothing was found. |
||
588 | throw new RuntimeException( |
||
589 | "Could not find resource '$resource' in any resource paths." |
||
590 | . "(searched: " . join(", ", $this->searchPaths). ")" |
||
591 | ); |
||
592 | } |
||
593 | |||
594 | /** |
||
595 | * @deprecated |
||
596 | * |
||
597 | * @return string |
||
598 | */ |
||
599 | public function getResourcesPath() |
||
600 | { |
||
601 | $allPaths = $this->getResourcePaths(); |
||
602 | |||
603 | // Compat: return only the first path added |
||
604 | return end($allPaths) ?: null; |
||
605 | } |
||
606 | |||
607 | /** |
||
608 | * @deprecated |
||
609 | * |
||
610 | * @param string $resourcesPath |
||
611 | * @return void |
||
612 | */ |
||
613 | public function setResourcesPath($resourcesPath) |
||
614 | { |
||
615 | $this->addResourcePath($resourcesPath); |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * Return the application paths. |
||
620 | * |
||
621 | * @return array |
||
622 | */ |
||
623 | public function getApplicationPaths() |
||
624 | { |
||
625 | return $this->applicationPaths; |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * Set the application paths. |
||
630 | * |
||
631 | * @param array $applicationPaths |
||
632 | */ |
||
633 | public function setApplicationPaths($applicationPaths) |
||
634 | { |
||
635 | $this->applicationPaths = $applicationPaths; |
||
636 | } |
||
637 | |||
638 | /** |
||
639 | * Set the application root path. |
||
640 | * |
||
641 | * @param string $applicationRootPath |
||
642 | */ |
||
643 | public function setApplicationRootPath($applicationRootPath) |
||
647 | |||
648 | /** |
||
649 | * blacklist a sensitive value within one of the superglobal arrays. |
||
650 | * |
||
651 | * @param $superGlobalName string the name of the superglobal array, e.g. '_GET' |
||
652 | * @param $key string the key within the superglobal |
||
653 | */ |
||
654 | 1 | public function blacklist($superGlobalName, $key) { |
|
655 | 1 | $this->blacklist[$superGlobalName][] = $key; |
|
656 | 1 | } |
|
657 | |||
658 | /** |
||
659 | * Checks all values within the given superGlobal array. |
||
660 | * Blacklisted values will be replaced by a equal length string cointaining only '*' characters. |
||
661 | * |
||
662 | * We intentionally dont rely on $GLOBALS as it depends on 'auto_globals_jit' php.ini setting. |
||
663 | * |
||
664 | * @param $superGlobal array One of the superglobal arrays |
||
665 | * @param $superGlobalName string the name of the superglobal array, e.g. '_GET' |
||
666 | * @return array $values without sensitive data |
||
667 | */ |
||
668 | private function masked(array $superGlobal, $superGlobalName) { |
||
669 | $blacklisted = $this->blacklist[$superGlobalName]; |
||
670 | |||
679 | } |
||
680 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.