39 'PHPUnit_Framework_MockObject_InvocationMocker',
40 \TYPO3\CMS\Extbase\Reflection\ReflectionService::class,
41 \TYPO3\CMS\Extbase\Object\ObjectManager::class,
42 \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class,
43 \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class,
44 \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory::class,
45 \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class
74 self::$renderedObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
86 protected static function renderDump($value, $level, $plainText, $ansiColors)
89 if (is_string($value)) {
90 $croppedValue = strlen($value) > 2000 ? substr($value, 0, 2000) .
'...' : $value;
92 $dump =
self::ansiEscapeWrap(
'"' . implode(PHP_EOL . str_repeat(self::PLAINTEXT_INDENT, $level + 1), str_split($croppedValue, 76)) .
'"',
'33', $ansiColors) .
' (' . strlen($value) .
' chars)';
94 $lines = str_split($croppedValue, 76);
95 $lines = array_map(
'htmlspecialchars', $lines);
96 $dump = sprintf(
'\'<span
class=
"extbase-debug-string">%s</span>\
' (%s chars)', implode(
'<br />' . str_repeat(self::HTML_INDENT, $level + 1), $lines), strlen($value));
98 } elseif (is_numeric($value)) {
99 $dump = sprintf(
'%s (%s)', self::ansiEscapeWrap($value,
'35', $ansiColors), gettype($value));
100 } elseif (is_bool($value)) {
102 } elseif ($value ===
null || is_resource($value)) {
103 $dump = gettype($value);
104 } elseif (is_array($value)) {
106 } elseif (is_object($value)) {
107 if ($value instanceof \Closure) {
125 protected static function renderArray($array, $level, $plainText =
false, $ansiColors =
false)
128 $count = count($array);
133 $header =
'<span class="extbase-debug-type">array</span>';
135 $header .= $count > 0 ?
'(' . $count .
' item' . ($count > 1 ?
's' :
'') .
')' :
'(empty)';
136 if ($level >= self::$maxDepth) {
140 $header .=
'<span class="extbase-debug-filtered">max depth</span>';
145 $header = ($level > 1 && $count > 0 ?
'<input type="checkbox" /><span class="extbase-debug-header" >' :
'<span>') . $header .
'</span >';
148 if ($level > 1 && $count > 0 && !$plainText) {
149 $dump =
'<span class="extbase-debugger-tree">' . $header .
'<span class="extbase-debug-content">' . $content .
'</span></span>';
151 $dump = $header . $content;
165 protected static function renderObject($object, $level, $plainText =
false, $ansiColors =
false)
167 if ($object instanceof \
TYPO3\CMS\
Extbase\Persistence\Generic\LazyLoadingProxy) {
168 $object = $object->_loadRealInstance();
170 return gettype($object);
174 if ($level < self::$maxDepth && !self::isBlacklisted($object) && !(self::isAlreadyRendered($object) && $plainText !==
true)) {
180 return $header . $content;
182 return '<span class="extbase-debugger-tree">' . $header .
'<span class="extbase-debug-content">' . $content .
'</span></span>';
194 protected static function renderClosure($object, $level, $plainText =
false, $ansiColors =
false)
197 if ($level < self::$maxDepth && (!self::isAlreadyRendered($object) || $plainText)) {
203 return $header . $content;
205 return '<span class="extbase-debugger-tree"><input type="checkbox" /><span class="extbase-debug-header">' . $header .
'</span><span class="extbase-debug-content">' . $content .
'</span></span>';
217 if ($value instanceof \ReflectionProperty) {
218 $result = in_array($value->getName(), self::$blacklistedPropertyNames,
true);
219 } elseif (is_object($value)) {
220 $result = in_array(get_class($value), self::$blacklistedClassNames,
true);
233 return self::$renderedObjects->contains($object);
245 protected static function renderHeader($object, $level, $plainText, $ansiColors)
248 $persistenceType =
'';
249 $className = get_class($object);
250 $classReflection = new \ReflectionClass($className);
254 $dump .=
'<span class="extbase-debug-type">' . htmlspecialchars($className) .
'</span>';
256 if (!$object instanceof \Closure) {
257 if ($object instanceof \
TYPO3\CMS\Core\SingletonInterface) {
258 $scope =
'singleton';
260 $scope =
'prototype';
265 $dump .= $scope ?
'<span class="extbase-debug-scope">' . $scope .
'</span>' :
'';
267 if ($object instanceof \
TYPO3\CMS\
Extbase\DomainObject\AbstractDomainObject) {
268 if ($object->_isDirty()) {
269 $persistenceType =
'modified';
270 } elseif ($object->_isNew()) {
271 $persistenceType =
'transient';
273 $persistenceType =
'persistent';
276 if ($object instanceof \
TYPO3\CMS\
Extbase\Persistence\ObjectStorage && $object->_isDirty()) {
277 $persistenceType =
'modified';
279 if ($object instanceof \
TYPO3\CMS\
Extbase\DomainObject\AbstractEntity) {
280 $domainObjectType =
'entity';
281 } elseif ($object instanceof \
TYPO3\CMS\
Extbase\DomainObject\AbstractValueObject) {
282 $domainObjectType =
'valueobject';
284 $domainObjectType =
'object';
287 $dump .=
' ' .
self::ansiEscapeWrap(($persistenceType ? $persistenceType .
' ' :
'') . $domainObjectType,
'42;30', $ansiColors);
289 $dump .=
'<span class="extbase-debug-ptype">' . ($persistenceType ? $persistenceType .
' ' :
'') . $domainObjectType .
'</span>';
292 if (strpos(implode(
'|', self::$blacklistedClassNames), get_class($object)) > 0) {
296 $dump .=
'<span class="extbase-debug-filtered">filtered</span>';
298 } elseif (self::$renderedObjects->contains($object) && !$plainText) {
299 $dump =
'<a href="javascript:;" onclick="document.location.hash=\'#' . spl_object_hash($object) .
'\';
" class="extbase-
debug-seeabove
">' . $dump . '<span class="extbase-
debug-filtered
">see above</span></a>';
300 } elseif ($level >= self::$maxDepth && !$object instanceof \DateTimeInterface) {
302 $dump .= ' ' . self::ansiEscapeWrap('max depth', '47;30', $ansiColors);
304 $dump .= '<span class="extbase-
debug-filtered
">max depth</span>';
306 } elseif ($level > 1 && !$object instanceof \DateTimeInterface && !$plainText) {
307 if (($object instanceof \Countable && empty($object)) || empty($classReflection->getProperties())) {
308 $dump = '<span>' . $dump . '</span>';
310 $dump = '<input type="checkbox
" id="' . spl_object_hash($object) . '" /><span class="extbase-
debug-header
">' . $dump . '</span>';
313 if ($object instanceof \Countable) {
314 $objectCount = count($object);
315 $dump .= $objectCount > 0 ? ' (' . $objectCount . ' items)' : ' (empty)';
317 if ($object instanceof \DateTimeInterface) {
318 $dump .= ' (' . $object->format(\DateTimeInterface::RFC3339) . ', ' . $object->getTimestamp() . ')';
320 if ($object instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface && !$object->_isNew()) {
321 $dump .= ' (uid=' . $object->getUid() . ', pid=' . $object->getPid() . ')';
333 protected static function renderContent($object, $level, $plainText, $ansiColors)
336 if ($object instanceof \TYPO3\CMS\Extbase\Persistence\ObjectStorage || $object instanceof \Iterator || $object instanceof \ArrayObject) {
337 $dump .= self::renderCollection($object, $level, $plainText, $ansiColors);
339 self::$renderedObjects->attach($object);
341 $dump .= '<a name="' . spl_object_hash($object) . '" id="' . spl_object_hash($object) . '"></a>';
343 if ($object instanceof \Closure) {
344 $dump .= PHP_EOL . str_repeat(self::PLAINTEXT_INDENT, $level)
345 . ($plainText ? '' : '<span class="extbase-
debug-closure
">')
346 . self::ansiEscapeWrap('function (', '33', $ansiColors) . ($plainText ? '' : '</span>');
348 $reflectionFunction = new \ReflectionFunction($object);
350 foreach ($reflectionFunction->getParameters() as $parameter) {
352 if ($parameter->isArray()) {
354 $parameterDump .= self::ansiEscapeWrap('array ', '36', $ansiColors);
356 $parameterDump .= '<span class="extbase-
debug-type
">array </span>';
358 } elseif ($parameter->getClass()) {
360 $parameterDump .= self::ansiEscapeWrap($parameter->getClass()->name . ' ', '36', $ansiColors);
362 $parameterDump .= '<span class="extbase-
debug-type
">'
363 . htmlspecialchars($parameter->getClass()->name) . '</span>';
366 if ($parameter->isPassedByReference()) {
367 $parameterDump .= '&';
369 if ($parameter->isVariadic()) {
370 $parameterDump .= '...';
373 $parameterDump .= self::ansiEscapeWrap('$' . $parameter->name, '37', $ansiColors);
375 $parameterDump .= '<span class="extbase-
debug-
property">'
376 . htmlspecialchars('$' . $parameter->name) . '</span>';
378 if ($parameter->isDefaultValueAvailable()) {
379 $parameterDump .= ' = ';
381 $parameterDump .= self::ansiEscapeWrap(var_export($parameter->getDefaultValue(), true), '33', $ansiColors);
383 $parameterDump .= '<span class="extbase-
debug-
string">'
384 . htmlspecialchars(var_export($parameter->getDefaultValue(), true)) . '</span>';
387 $params[] = $parameterDump;
389 $dump .= implode(', ', $params);
391 $dump .= self::ansiEscapeWrap(') {' . PHP_EOL, '33', $ansiColors);
393 $dump .= '<span class="extbase-
debug-closure
">) {' . PHP_EOL . '</span>';
395 $lines = file($reflectionFunction->getFileName());
396 for ($l = $reflectionFunction->getStartLine(); $l < $reflectionFunction->getEndLine() - 1; ++$l) {
397 $dump .= $plainText ? $lines[$l] : htmlspecialchars($lines[$l]);
399 $dump .= str_repeat(self::PLAINTEXT_INDENT, $level);
401 $dump .= self::ansiEscapeWrap('}' . PHP_EOL, '33', $ansiColors);
403 $dump .= '<span class="extbase-
debug-closure
">}</span>';
406 if (get_class($object) === 'stdClass') {
407 $objReflection = new \ReflectionObject($object);
408 $properties = $objReflection->getProperties();
410 $classReflection = new \ReflectionClass(get_class($object));
411 $properties = $classReflection->getProperties();
413 foreach ($properties as $property) {
414 if (self::isBlacklisted($property)) {
417 $dump .= PHP_EOL . str_repeat(self::PLAINTEXT_INDENT, $level);
419 $dump .= self::ansiEscapeWrap($property->getName(), '37', $ansiColors);
421 $dump .= '<span class="extbase-
debug-
property">'
422 . htmlspecialchars($property->getName()) . '</span>';
425 $property->setAccessible(true);
426 $visibility = ($property->isProtected() ? 'protected' : ($property->isPrivate() ? 'private' : 'public'));
428 $dump .= self::ansiEscapeWrap($visibility, '42;30', $ansiColors) . ' ';
430 $dump .= '<span class="extbase-
debug-visibility
">' . $visibility . '</span>';
432 $dump .= self::renderDump($property->getValue($object), $level, $plainText, $ansiColors);
433 if ($object instanceof \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject && !$object->_isNew() && $object->_isDirty($property->getName())) {
435 $dump .= ' ' . self::ansiEscapeWrap('modified', '43;30', $ansiColors);
437 $dump .= '<span class="extbase-
debug-dirty
">modified</span>';
453 protected static function renderCollection($collection, $level, $plainText, $ansiColors)
456 foreach ($collection as $key => $value) {
457 $dump .= PHP_EOL . str_repeat(self::PLAINTEXT_INDENT, $level);
459 $dump .= self::ansiEscapeWrap($key, '37', $ansiColors);
461 $dump .= '<span class="extbase-
debug-
property">' . htmlspecialchars($key) . '</span>';
464 $dump .= self::renderDump($value, $level, $plainText, $ansiColors);
466 if ($collection instanceof \Iterator && !$collection instanceof \Generator) {
467 $collection->rewind();
480 protected static function ansiEscapeWrap($string, $ansiColors, $enable = true)
483 return '[' . $ansiColors . 'm' . $string . '[0m';
501 public static function var_dump($variable, $title = null, $maxDepth = 8, $plainText = false, $ansiColors = true, $return = false, $blacklistedClassNames = null, $blacklistedPropertyNames = null)
503 self::$maxDepth = $maxDepth;
504 if ($title === null) {
505 $title = 'Extbase Variable Dump';
507 $ansiColors = $plainText && $ansiColors;
508 if ($ansiColors === true) {
509 $title = '[1m' . $title . '[0m';
511 $backupBlacklistedClassNames = self::$blacklistedClassNames;
512 if (is_array($blacklistedClassNames)) {
513 self::$blacklistedClassNames = $blacklistedClassNames;
515 $backupBlacklistedPropertyNames = self::$blacklistedPropertyNames;
516 if (is_array($blacklistedPropertyNames)) {
517 self::$blacklistedPropertyNames = $blacklistedPropertyNames;
521 if (!$plainText && self::$stylesheetEchoed === false) {
523 <style type=\'text/css\'>
524 .extbase-debugger-tree{position:relative}
525 .extbase-debugger-tree input{position:absolute !important;float: none !important;top:0;left:0;height:14px;width:14px;margin:0 !important;cursor:pointer;opacity:0;z-index:2}
526 .extbase-debugger-tree input~.extbase-debug-content{display:none}
527 .extbase-debugger-tree .extbase-debug-header:before{position:relative;top:3px;content:"";padding:0;line-height:10px;height:12px;width:12px;text-align:center;margin:0 3px 0 0;background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkViZW5lXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTIgMTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDEyIDEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe2ZpbGw6Izg4ODg4ODt9PC9zdHlsZT48cGF0aCBpZD0iQm9yZGVyIiBjbGFzcz0ic3QwIiBkPSJNMTEsMTFIMFYwaDExVjExeiBNMTAsMUgxdjloOVYxeiIvPjxnIGlkPSJJbm5lciI+PHJlY3QgeD0iMiIgeT0iNSIgY2xhc3M9InN0MCIgd2lkdGg9IjciIGhlaWdodD0iMSIvPjxyZWN0IHg9IjUiIHk9IjIiIGNsYXNzPSJzdDAiIHdpZHRoPSIxIiBoZWlnaHQ9IjciLz48L2c+PC9zdmc+);display:inline-block}
528 .extbase-debugger-tree input:checked~.extbase-debug-content{display:inline}
529 .extbase-debugger-tree input:checked~.extbase-debug-header:before{background-image:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkViZW5lXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB2aWV3Qm94PSIwIDAgMTIgMTIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDEyIDEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHN0eWxlIHR5cGU9InRleHQvY3NzIj4uc3Qwe2ZpbGw6Izg4ODg4ODt9PC9zdHlsZT48cGF0aCBpZD0iQm9yZGVyIiBjbGFzcz0ic3QwIiBkPSJNMTEsMTFIMFYwaDExVjExeiBNMTAsMUgxdjloOVYxeiIvPjxnIGlkPSJJbm5lciI+PHJlY3QgeD0iMiIgeT0iNSIgY2xhc3M9InN0MCIgd2lkdGg9IjciIGhlaWdodD0iMSIvPjwvZz48L3N2Zz4=)}
530 .extbase-debugger{display:block;text-align:left;background:#2a2a2a;border:1px solid #2a2a2a;box-shadow:0 3px 0 rgba(0,0,0,.5);color:#000;margin:20px;overflow:hidden;border-radius:4px}
531 .extbase-debugger-floating{position:relative;z-index:999}
532 .extbase-debugger-top{background:#444;font-size:12px;font-family:monospace;color:#f1f1f1;padding:6px 15px}
533 .extbase-debugger-center{padding:0 15px;margin:15px 0;background-image:repeating-linear-gradient(to bottom,transparent 0,transparent 20px,#252525 20px,#252525 40px)}
534 .extbase-debugger-center,.extbase-debugger-center .extbase-debug-string,.extbase-debugger-center a,.extbase-debugger-center p,.extbase-debugger-center pre,.extbase-debugger-center strong{font-size:12px;font-weight:400;font-family:monospace;line-height:20px;color:#f1f1f1}
535 .extbase-debugger-center pre{background-color:transparent;margin:0;padding:0;border:0;word-wrap:break-word;color:#999}
536 .extbase-debugger-center .extbase-debug-string{color:#ce9178;white-space:normal}
537 .extbase-debugger-center .extbase-debug-type{color:#569CD6;padding-right:4px}
538 .extbase-debugger-center .extbase-debug-unregistered{background-color:#dce1e8}
539 .extbase-debugger-center .extbase-debug-filtered,.extbase-debugger-center .extbase-debug-proxy,.extbase-debugger-center .extbase-debug-ptype,.extbase-debugger-center .extbase-debug-visibility,.extbase-debugger-center .extbase-debug-scope{color:#fff;font-size:10px;line-height:12px;padding:2px 4px;margin-right:2px;position:relative;top:-1px}
540 .extbase-debugger-center .extbase-debug-scope{background-color:#497AA2}
541 .extbase-debugger-center .extbase-debug-ptype{background-color:#698747}
542 .extbase-debugger-center .extbase-debug-visibility{background-color:#698747}
543 .extbase-debugger-center .extbase-debug-dirty{background-color:#FFFFB6}
544 .extbase-debugger-center .extbase-debug-filtered{background-color:#4F4F4F}
545 .extbase-debugger-center .extbase-debug-seeabove{text-decoration:none;font-style:italic}
546 .extbase-debugger-center .extbase-debug-property{color:#f1f1f1}
547 .extbase-debugger-center .extbase-debug-closure{color:#9BA223;}
549 self::$stylesheetEchoed = true;
552 $output = $title . PHP_EOL . self::renderDump($variable, 0, true, $ansiColors) . PHP_EOL . PHP_EOL;
555 <div class="extbase-debugger
' . ($return ? 'extbase-debugger-
inline' : 'extbase-debugger-floating
') . '">
556 <div class="extbase-debugger-top
">' . htmlspecialchars($title) . '</div>
557 <div class="extbase-debugger-center
">
558 <pre dir="ltr
">' . self::renderDump($variable, 0, false, false) . '</pre>
563 self::$blacklistedClassNames = $backupBlacklistedClassNames;
564 self::$blacklistedPropertyNames = $backupBlacklistedPropertyNames;
565 if ($return === true) {
566 return $css . $output;