2380e8e4a640c70548326ea25ed07d375274a3f0
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / DebugViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers;
3
4 /* *
5 * This script is part of the TYPO3 project - inspiring people to share! *
6 * *
7 * TYPO3 is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU General Public License version 2 as published by *
9 * the Free Software Foundation. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
14 * Public License for more details. *
15 * */
16 use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
17 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
18 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
19 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
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 implements CompilableInterface {
41
42 /**
43 * A wrapper for \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump().
44 *
45 * @param string $title optional custom title for the debug output
46 * @param int $maxDepth Sets the max recursion depth of the dump (defaults to 8). De- or increase the number according to your needs and memory limit.
47 * @param bool $plainText If TRUE, the dump is in plain text, if FALSE the debug output is in HTML format.
48 * @param bool $ansiColors If TRUE, ANSI color codes is added to the plaintext output, if FALSE (default) the plaintext debug output not colored.
49 * @param bool $inline 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.
50 * @param array $blacklistedClassNames An array of class names (RegEx) to be filtered. Default is an array of some common class names.
51 * @param array $blacklistedPropertyNames An array of property names and/or array keys (RegEx) to be filtered. Default is an array of some common property names.
52 * @return string
53 */
54 public function render($title = NULL, $maxDepth = 8, $plainText = FALSE, $ansiColors = FALSE, $inline = FALSE, $blacklistedClassNames = NULL, $blacklistedPropertyNames = NULL) {
55 return self::renderStatic(
56 array(
57 'title' => $title,
58 'maxDepth' => $maxDepth,
59 'plainText' => $plainText,
60 'ansiColors' => $ansiColors,
61 'inline' => $inline,
62 'blacklistedClassNames' => $blacklistedClassNames,
63 'blacklistedPropertyNames' => $blacklistedPropertyNames
64 ),
65 $this->buildRenderChildrenClosure(),
66 $this->renderingContext
67 );
68 }
69
70 /**
71 * @param array $arguments
72 * @param callable $renderChildrenClosure
73 * @param RenderingContextInterface $renderingContext
74 *
75 * @return string
76 */
77 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
78 return DebuggerUtility::var_dump($renderChildrenClosure(), $arguments['title'], $arguments['maxDepth'], (bool)$arguments['plainText'], (bool)$arguments['ansiColors'], (bool)$arguments['inline'], $arguments['blacklistedClassNames'], $arguments['blacklistedPropertyNames']);
79 }
80 }