c2af1d3e1a23a2f76f9d62ee2cd80a6899d5d6fe
[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 * Render a readable string for PHP error code
50 *
51 * @param int $phpErrorCode
52 * @return string
53 */
54 public function render($phpErrorCode)
55 {
56 return static::renderStatic(
57 array(
58 'phpErrorCode' => $phpErrorCode,
59 ),
60 $this->buildRenderChildrenClosure(),
61 $this->renderingContext
62 );
63 }
64
65 /**
66 * @param array $arguments
67 * @param \Closure $renderChildrenClosure
68 * @param RenderingContextInterface $renderingContext
69 *
70 * @return string
71 */
72 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
73 {
74 $phpErrorCode = $arguments['phpErrorCode'];
75 $levels = array();
76 if (($phpErrorCode & E_ALL) == E_ALL) {
77 $levels[] = 'E_ALL';
78 $phpErrorCode &= ~E_ALL;
79 }
80 foreach (self::$levelNames as $level => $name) {
81 if (($phpErrorCode & $level) == $level) {
82 $levels[] = $name;
83 }
84 }
85
86 $output = '';
87 if (!empty($levels)) {
88 $output = implode(' | ', $levels);
89 }
90
91 return $output;
92 }
93 }