[TASK] Re-work/simplify copyright header in PHP files - Part 1
[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 /**
18 * Transform PHP error code to readable text
19 */
20 class PhpErrorCodeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
21
22 /**
23 * @var array
24 */
25 protected $levelNames = array(
26 E_ERROR => 'E_ERROR',
27 E_WARNING => 'E_WARNING',
28 E_PARSE => 'E_PARSE',
29 E_NOTICE => 'E_NOTICE',
30 E_CORE_ERROR => 'E_CORE_ERROR',
31 E_CORE_WARNING => 'E_CORE_WARNING',
32 E_COMPILE_ERROR => 'E_COMPILE_ERROR',
33 E_COMPILE_WARNING => 'E_COMPILE_WARNING',
34 E_USER_ERROR => 'E_USER_ERROR',
35 E_USER_WARNING => 'E_USER_WARNING',
36 E_USER_NOTICE => 'E_USER_NOTICE',
37 E_STRICT => 'E_STRICT',
38 E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
39 E_DEPRECATED => 'E_DEPRECATED',
40 E_USER_DEPRECATED => 'E_USER_DEPRECATED',
41 );
42
43 /**
44 * Render a readable string for PHP error code
45 *
46 * @param integer $phpErrorCode
47 * @return string
48 */
49 public function render($phpErrorCode) {
50 $levels = array();
51 if (($phpErrorCode & E_ALL) == E_ALL) {
52 $levels[] = 'E_ALL';
53 $phpErrorCode &= ~E_ALL;
54 }
55 foreach ($this->levelNames as $level => $name) {
56 if (($phpErrorCode & $level) == $level) {
57 $levels[] = $name;
58 }
59 }
60
61 $output = '';
62 if (!empty($levels)) {
63 $output = implode(' | ', $levels);
64 }
65
66 return $output;
67 }
68
69 }