[TASK] Move arguments to initializeArguments() in DebugVH in ext:fluid
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / DebugViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers;
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\Extbase\Utility\DebuggerUtility;
18 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
19 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
20
21 /**
22 * This ViewHelper generates a HTML dump of the tagged variable.
23 *
24 * = Examples =
25 *
26 * <code title="Simple">
27 * <f:debug>{testVariables.array}</f:debug>
28 * </code>
29 * <output>
30 * foobarbazfoo
31 * </output>
32 *
33 * <code title="All Features">
34 * <f:debug title="My Title" maxDepth="5" blacklistedClassNames="{0:'Tx_BlogExample_Domain_Model_Administrator'}" plainText="TRUE" ansiColors="FALSE" inline="TRUE" blacklistedPropertyNames="{0:'posts'}">{blogs}</f:debug>
35 * </code>
36 * <output>
37 * [A HTML view of the var_dump]
38 * </output>
39 */
40 class DebugViewHelper extends AbstractViewHelper
41 {
42 /**
43 * This prevents double escaping as the output is encoded in DebuggerUtility::var_dump
44 *
45 * @var bool
46 */
47 protected $escapeChildren = false;
48
49 /**
50 * Output of this viewhelper is already escaped
51 *
52 * @var bool
53 */
54 protected $escapeOutput = false;
55
56 /**
57 * Initialize arguments.
58 *
59 * @api
60 * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
61 */
62 public function initializeArguments()
63 {
64 parent::initializeArguments();
65 $this->registerArgument('title', 'string', 'optional custom title for the debug output');
66 $this->registerArgument('maxDepth', 'int', 'Sets the max recursion depth of the dump (defaults to 8). De- or increase the number according to your needs and memory limit.', false, 8);
67 $this->registerArgument('plainText', 'bool', 'If TRUE, the dump is in plain text, if FALSE the debug output is in HTML format.', false, false);
68 $this->registerArgument('ansiColors', 'bool', 'If TRUE, ANSI color codes is added to the plaintext output, if FALSE (default) the plaintext debug output not colored.', false, false);
69 $this->registerArgument('inline', 'bool', 'if TRUE, the dump is rendered at the position of the <f:debug> tag. If FALSE (default), the dump is displayed at the top of the page.', false, false);
70 $this->registerArgument('blacklistedClassNames', 'array', 'An array of class names (RegEx) to be filtered. Default is an array of some common class names.');
71 $this->registerArgument('blacklistedPropertyNames', 'array', 'An array of property names and/or array keys (RegEx) to be filtered. Default is an array of some common property names.');
72 }
73
74 /**
75 * A wrapper for \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump().
76 *
77 * @return string
78 */
79 public function render()
80 {
81 $title = $this->arguments['title'];
82 $maxDepth = $this->arguments['maxDepth'];
83 $plainText = $this->arguments['plainText'];
84 $ansiColors = $this->arguments['ansiColors'];
85 $inline = $this->arguments['inline'];
86 $blacklistedClassNames = $this->arguments['blacklistedClassNames'];
87 $blacklistedPropertyNames = $this->arguments['blacklistedPropertyNames'];
88 return static::renderStatic(
89 array(
90 'title' => $title,
91 'maxDepth' => $maxDepth,
92 'plainText' => $plainText,
93 'ansiColors' => $ansiColors,
94 'inline' => $inline,
95 'blacklistedClassNames' => $blacklistedClassNames,
96 'blacklistedPropertyNames' => $blacklistedPropertyNames
97 ),
98 $this->buildRenderChildrenClosure(),
99 $this->renderingContext
100 );
101 }
102
103 /**
104 * @param array $arguments
105 * @param \Closure $renderChildrenClosure
106 * @param RenderingContextInterface $renderingContext
107 *
108 * @return string
109 */
110 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
111 {
112 return DebuggerUtility::var_dump($renderChildrenClosure(), $arguments['title'], $arguments['maxDepth'], (bool)$arguments['plainText'], (bool)$arguments['ansiColors'], (bool)$arguments['inline'], $arguments['blacklistedClassNames'], $arguments['blacklistedPropertyNames']);
113 }
114 }