8bca7688d322494c303583f602665b7ab48680f1
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / ViewHelpers / Format / PhpErrorCodeViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Install\ViewHelpers\Format;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Wouter Wolters <typo3@wouterwolters.nl>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Transform PHP error code to readable text
29 */
30 class PhpErrorCodeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
31
32 /**
33 * @var array
34 */
35 protected $levelNames = array(
36 E_ERROR => 'E_ERROR',
37 E_WARNING => 'E_WARNING',
38 E_PARSE => 'E_PARSE',
39 E_NOTICE => 'E_NOTICE',
40 E_CORE_ERROR => 'E_CORE_ERROR',
41 E_CORE_WARNING => 'E_CORE_WARNING',
42 E_COMPILE_ERROR => 'E_COMPILE_ERROR',
43 E_COMPILE_WARNING => 'E_COMPILE_WARNING',
44 E_USER_ERROR => 'E_USER_ERROR',
45 E_USER_WARNING => 'E_USER_WARNING',
46 E_USER_NOTICE => 'E_USER_NOTICE',
47 E_STRICT => 'E_STRICT',
48 E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
49 E_DEPRECATED => 'E_DEPRECATED',
50 E_USER_DEPRECATED => 'E_USER_DEPRECATED',
51 );
52
53 /**
54 * Render a readable string for PHP error code
55 *
56 * @param integer $phpErrorCode
57 * @return string
58 */
59 public function render($phpErrorCode) {
60 $levels = array();
61 if (($phpErrorCode & E_ALL) == E_ALL) {
62 $levels[] = 'E_ALL';
63 $phpErrorCode &= ~E_ALL;
64 }
65 foreach ($this->levelNames as $level => $name) {
66 if (($phpErrorCode & $level) == $level) {
67 $levels[] = $name;
68 }
69 }
70
71 $output = '';
72 if (!empty($levels)) {
73 $output = implode(' | ', $levels);
74 }
75
76 return $output;
77 }
78
79 }