[TASK] Move ViewHelper arguments to initializeArguments() in ext:install
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / ViewHelpers / Format / PhpErrorCodeViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Install\ViewHelpers\Format;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
18 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
19
20 /**
21 * Transform PHP error code to readable text
22 *
23 * @internal
24 */
25 class PhpErrorCodeViewHelper extends AbstractViewHelper
26 {
27 /**
28 * @var array
29 */
30 protected static $levelNames = array(
31 E_ERROR => 'E_ERROR',
32 E_WARNING => 'E_WARNING',
33 E_PARSE => 'E_PARSE',
34 E_NOTICE => 'E_NOTICE',
35 E_CORE_ERROR => 'E_CORE_ERROR',
36 E_CORE_WARNING => 'E_CORE_WARNING',
37 E_COMPILE_ERROR => 'E_COMPILE_ERROR',
38 E_COMPILE_WARNING => 'E_COMPILE_WARNING',
39 E_USER_ERROR => 'E_USER_ERROR',
40 E_USER_WARNING => 'E_USER_WARNING',
41 E_USER_NOTICE => 'E_USER_NOTICE',
42 E_STRICT => 'E_STRICT',
43 E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
44 E_DEPRECATED => 'E_DEPRECATED',
45 E_USER_DEPRECATED => 'E_USER_DEPRECATED',
46 );
47
48 /**
49 * Initialize arguments
50 */
51 public function initializeArguments()
52 {
53 parent::initializeArguments();
54 $this->registerArgument('phpErrorCode', 'int', '', true);
55 }
56
57 /**
58 * Render a readable string for PHP error code
59 *
60 * @return string
61 */
62 public function render()
63 {
64 return static::renderStatic(
65 $this->arguments,
66 $this->buildRenderChildrenClosure(),
67 $this->renderingContext
68 );
69 }
70
71 /**
72 * @param array $arguments
73 * @param \Closure $renderChildrenClosure
74 * @param RenderingContextInterface $renderingContext
75 *
76 * @return string
77 */
78 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
79 {
80 $phpErrorCode = $arguments['phpErrorCode'];
81 $levels = array();
82 if (($phpErrorCode & E_ALL) == E_ALL) {
83 $levels[] = 'E_ALL';
84 $phpErrorCode &= ~E_ALL;
85 }
86 foreach (self::$levelNames as $level => $name) {
87 if (($phpErrorCode & $level) == $level) {
88 $levels[] = $name;
89 }
90 }
91
92 $output = '';
93 if (!empty($levels)) {
94 $output = implode(' | ', $levels);
95 }
96
97 return $output;
98 }
99 }