8000 VarDumper and DebugBundle by nicolas-grekas · Pull Request #10640 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

VarDumper and DebugBundle #10640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Sep 23, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
eec5c92
[Debug] Symfony debug extension
Mar 7, 2014
4bf9300
[Debug] a README for the debug extension
nicolas-grekas Mar 20, 2014
07135a0
[VarDumper] algo to clone any PHP variable to a breadth-first queue
nicolas-grekas Apr 5, 2014
5b7ae28
[VarDumper] symfony_debug ext. fast and memory efficient cloning algo
nicolas-grekas Apr 5, 2014
3ddbf4b
[VarDumper] add casters for per class/resource custom state extraction
nicolas-grekas Apr 5, 2014
c91bc83
[VarDumper] casters for exceptions representation
nicolas-grekas Apr 5, 2014
da3e50a
[VarDumper] casters for SPL data structures
nicolas-grekas Apr 5, 2014
0a92c08
[VarDumper] casters for PDO related objects
nicolas-grekas Apr 5, 2014
c426d8b
[VarDumper] casters for Doctrine objects
nicolas-grekas Apr 5, 2014
0266072
[VarDumper] casters for DOM objects
nicolas-grekas Aug 24, 2014
1d5e3f4
[VarDumper] interface for dumping collected variables
nicolas-grekas Apr 5, 2014
fa81544
[VarDumper] CLI dedicated dumper and related abstract
nicolas-grekas Apr 5, 2014
e6dde33
[VarDumper] HTML variant of the CLI dumper
nicolas-grekas Apr 5, 2014
5eaa187
[VarDumper] tests for CliDumper
nicolas-grekas Apr 5, 2014
a69e962
[VarDumper] tests for HtmlDumper
nicolas-grekas Jun 13, 2014
297d373
[VarDumper] README, LICENSE and composer.json
nicolas-grekas Apr 5, 2014
9dea601
[DebugBundle] global dump() function for daily use
nicolas-grekas May 29, 2014
eb98c81
[DebugBundle] dump() + better Symfony glue
nicolas-grekas Aug 26, 2014
8d5d970
[DebugBundle] adjust after review
nicolas-grekas Aug 27, 2014
c8746a4
[DebugBundle] add tests for twig and for the bundle
nicolas-grekas Aug 27, 2014
0d8a942
[VarDumper] add Stub objects for cutting cleanly and dumping consts
nicolas-grekas Sep 8, 2014
081363c
[HttpKernel] tests for DumpListener
nicolas-grekas Sep 8, 2014
49f13c6
[HttpKernel] add tests for DumpDataCollector
nicolas-grekas Sep 9, 2014
de05cd9
[DebugBundle] enhance dump excerpts
nicolas-grekas Sep 12, 2014
e4e00ef
[TwigBridge] DumpNode and Token parser
ruian Sep 12, 2014
5f59811
[DebugBundle] Add doc example for Twig usage
Sep 12, 2014
a8d81e4
[DebugBundle] Inlined assets to avoid installation issues
Sep 12, 2014
d43ae82
[VarDumper] Add workaround to https://bugs.php.net/65967
romainneutron Sep 12, 2014
0f8d30f
[VarDumper] Replace \e with \x1B in CliDumper to support colour in PH…
oscherler Sep 12, 2014
2e167ba
[TwigBridge] add Twig dump() function + tests and fixes
nicolas-grekas Sep 17, 2014
80fd736
[DebugBundle] Enhance some comments
lyrixx Sep 23, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[VarDumper] add Stub objects for cutting cleanly and dumping consts
  • Loading branch information
nicolas-grekas committed Sep 23, 2014
commit 0d8a942cfa8971be767455041b19dc17a6c737f0
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function flushDumps()

$h = headers_list();
$i = count($h);
array_unshift($h, 'Content-Type: ' . ini_get('default_mimetype'));
array_unshift($h, 'Content-Type: '.ini_get('default_mimetype'));
while (0 !== stripos($h[$i], 'Content-Type:')) {
--$i;
}
Expand Down
62 changes: 62 additions & 0 deletions src/Symfony/Component/VarDumper/Caster/CasterStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\VarDumper\Caster;

use Symfony\Component\VarDumper\Cloner\Stub;

/**
* Represents the main properties of a PHP variable, pre-casted by a caster.
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class CasterStub extends Stub
{
public function __construct($value, $class = '')
{
switch (gettype($value)) {
case 'object':
$this->type = self::TYPE_OBJECT;
$this->class = get_class($value);
$this->value = spl_object_hash($value);
$this->cut = -1;
break;

case 'array':
$this->type = self::TYPE_ARRAY;
$this->class = self::ARRAY_ASSOC;
$this->cut = $this->value = count($value);
break;

case 'resource':
case 'unknown type':
$this->type = self::TYPE_RESOURCE;
$this->class = @get_resource_type($value);
$this->value = (int) $value;
$this->cut = -1;
break;

case 'string':
if ('' === $class) {
$this->type = self::TYPE_STRING;
$this->class = preg_match('//u', $value) ? self::STRING_UTF8 : self::STRING_BINARY;
$this->cut = self::STRING_BINARY === $this->class ? strlen($value) : (function_exists('iconv_strlen') ? iconv_strlen($value, 'UTF-8') : -1);
break;
}
// No break;

default:
$this->class = $class;
$this->value = $value;
break;
}
}
}
93 changes: 56 additions & 37 deletions src/Symfony/Component/VarDumper/Caster/DOMCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\VarDumper\Caster;

use Symfony\Component\VarDumper\Cloner\Stub;

/**
* Casts DOM related classes to array representation.
*
Expand Down Expand Up @@ -38,16 +40,37 @@ class DOMCaster
DOM_VALIDATION_ERR => 'DOM_VALIDATION_ERR',
);

public static function castException(\DOMException $e, array $a, $isNested, &$cut)
private static $nodeTypes = array(
XML_ELEMENT_NODE => 'XML_ELEMENT_NODE',
XML_ATTRIBUTE_NODE => 'XML_ATTRIBUTE_NODE',
XML_TEXT_NODE => 'XML_TEXT_NODE',
XML_CDATA_SECTION_NODE => 'XML_CDATA_SECTION_NODE',
XML_ENTITY_REF_NODE => 'XML_ENTITY_REF_NODE',
XML_ENTITY_NODE => 'XML_ENTITY_NODE',
XML_PI_NODE => 'XML_PI_NODE',
XML_COMMENT_NODE => 'XML_COMMENT_NODE',
XML_DOCUMENT_NODE => 'XML_DOCUMENT_NODE',
XML_DOCUMENT_TYPE_NODE => 'XML_DOCUMENT_TYPE_NODE',
XML_DOCUMENT_FRAG_NODE => 'XML_DOCUMENT_FRAG_NODE',
XML_NOTATION_NODE => 'XML_NOTATION_NODE',
XML_HTML_DOCUMENT_NODE => 'XML_HTML_DOCUMENT_NODE',
XML_DTD_NODE => 'XML_DTD_NODE',
XML_ELEMENT_DECL_NODE => 'XML_ELEMENT_DECL_NODE',
XML_ATTRIBUTE_DECL_NODE => 'XML_ATTRIBUTE_DECL_NODE',
XML_ENTITY_DECL_NODE => 'XML_ENTITY_DECL_NODE',
XML_NAMESPACE_DECL_NODE => 'XML_NAMESPACE_DECL_NODE',
);

public static function castException(\DOMException $e, array $a, Stub $stub, $isNested)
{
if (isset($a["\0*\0code"], self::$errorCodes[$a["\0*\0code"]])) {
$a["\0*\0code"] .= ' ('.self::$errorCodes[$a["\0*\0code"]].')';
$a["\0*\0code"] = new CasterStub(self::$errorCodes[$a["\0*\0code"]], 'const');
}

return $a;
}

public static function castLength($dom, array $a, $isNested, &$cut)
public static function castLength($dom, array $a, Stub $stub, $isNested)
{
$a += array(
'length' => $dom->length,
Expand All @@ -56,7 +79,7 @@ public static function castLength($dom, array $a, $isNested, &$cut)
return $a;
}

public static function castImplementation($dom, array $a, $isNested, &$cut)
public static function castImplementation($dom, array $a, Stub $stub, $isNested)
{
$a += array(
"\0~\0Core" => '1.0',
Expand All @@ -66,61 +89,57 @@ public static function castImplementation($dom, array $a, $isNested, &$cut)
return $a;
}

public static function castNode(\DOMNode $dom, array $a, $isNested, &$cut)
public static function castNode(\DOMNode $dom, array $a, Stub $stub, $isNested)
{
// Commented lines denote properties that exist but are better not dumped for clarity.

$a += array(
'nodeName' => $dom->nodeName,
//'nodeValue' => $dom->nodeValue,
'nodeType' => $dom->nodeType,
//'parentNode' => $dom->parentNode,
'nodeValue' => new CasterStub($dom->nodeValue),
'nodeType' => new CasterStub(self::$nodeTypes[$dom->nodeType], 'const'),
'parentNode' => new CasterStub($dom->parentNode),
'childNodes' => $dom->childNodes,
//'firstChild' => $dom->firstChild,
//'lastChild' => $dom->lastChild,
//'previousSibling' => $dom->previousSibling,
//'nextSibling' => $dom->nextSibling,
'firstChild' => new CasterStub($dom->firstChild),
'lastChild' => new CasterStub($dom->lastChild),
'previousSibling' => new CasterStub($dom->previousSibling),
'nextSibling' => new CasterStub($dom->nextSibling),
'attributes' => $dom->attributes,
//'ownerDocument' => $dom->ownerDocument,
'ownerDocument' => new CasterStub($dom->ownerDocument),
'namespaceURI' => $dom->namespaceURI,
'prefix' => $dom->prefix,
'localName' => $dom->localName,
'baseURI' => $dom->baseURI,
//'textContent' => $dom->textContent,
'textContent' => new CasterStub($dom->textContent),
);
$cut += 8;

return $a;
}

public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, $isNested, &$cut)
public static function castNameSpaceNode(\DOMNameSpaceNode $dom, array $a, Stub $stub, $isNested)
{
// Commented lines denote properties that exist but are better not dumped for clarity.

$a += array(
'nodeName' => $dom->nodeName,
//'nodeValue' => $dom->nodeValue,
'nodeType' => $dom->nodeType,
'nodeValue' => new CasterStub($dom->nodeValue),
'nodeType' => new CasterStub(self::$nodeTypes[$dom->nodeType], 'const'),
'prefix' => $dom->prefix,
'localName' => $dom->localName,
'namespaceURI' => $dom->namespaceURI,
//'ownerDocument' => $dom->ownerDocument,
//'parentNode' => $dom->parentNode,
'ownerDocument' => new CasterStub($dom->ownerDocument),
'parentNode' => new CasterStub($dom->parentNode),
);
$cut += 3;

return $a;
}

public static function castDocument(\DOMDocument $dom, array $a, $isNested, &$cut)
public static function castDocument(\DOMDocument $dom, array $a, Stub $stub, $isNested)
{
$formatOutput = $dom->formatOutput;
$dom->formatOutput = true;

$a += array(
'doctype' => $dom->doctype,
'implementation' => $dom->implementation,
'documentElement' => $dom->documentElement,
'documentElement' => new CasterStub($dom->documentElement),
'actualEncoding' => $dom->actualEncoding,
'encoding' => $dom->encoding,
'xmlEncoding' => $dom->xmlEncoding,
Expand All @@ -145,7 +164,7 @@ public static function castDocument(\DOMDocument $dom, array $a, $isNested, &$cu
return $a;
}

public static function castCharacterData(\DOMCharacterData $dom, array $a, $isNested, &$cut)
public static function castCharacterData(\DOMCharacterData $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'data' => $dom->data,
Expand All @@ -155,7 +174,7 @@ public static function castCharacterData(\DOMCharacterData $dom, array $a, $isNe
return $a;
}

public static function castAttr(\DOMAttr $dom, array $a, $isNested, &$cut)
public static function castAttr(\DOMAttr $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'name' => $dom->name,
Expand All @@ -168,7 +187,7 @@ public static function castAttr(\DOMAttr $dom, array $a, $isNested, &$cut)
return $a;
}

public static function castElement(\DOMElement $dom, array $a, $isNested, &$cut)
public static function castElement(\DOMElement $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'tagName' => $dom->tagName,
Expand All @@ -178,7 +197,7 @@ public static function castElement(\DOMElement $dom, array $a, $isNested, &$cut)
return $a;
}

public static function castText(\DOMText $dom, array $a, $isNested, &$cut)
public static function castText(\DOMText $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'wholeText' => $dom->wholeText,
Expand All @@ -187,7 +206,7 @@ public static function castText(\DOMText $dom, array $a, $isNested, &$cut)
return $a;
}

public static function castTypeinfo(\DOMTypeinfo $dom, array $a, $isNested, &$cut)
public static function castTypeinfo(\DOMTypeinfo $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'typeName' => $dom->typeName,
Expand All @@ -197,7 +216,7 @@ public static function castTypeinfo(\DOMTypeinfo $dom, array $a, $isNested, &$cu
return $a;
}

public static function castDomError(\DOMDomError $dom, array $a, $isNested, &$cut)
public static function castDomError(\DOMDomError $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'severity' => $dom->severity,
Expand All @@ -211,7 +230,7 @@ public static function castDomError(\DOMDomError $dom, array $a, $isNested, &$cu
return $a;
}

public static function castLocator(\DOMLocator $dom, array $a, $isNested, &$cut)
public static function castLocator(\DOMLocator $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'lineNumber' => $dom->lineNumber,
Expand All @@ -224,7 +243,7 @@ public static function castLocator(\DOMLocator $dom, array $a, $isNested, &$cut)
return $a;
}

public static function castDocumentType(\DOMDocumentType $dom, array $a, $isNested, &$cut)
public static function castDocumentType(\DOMDocumentType $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'name' => $dom->name,
Expand All @@ -238,7 +257,7 @@ public static function castDocumentType(\DOMDocumentType $dom, array $a, $isNest
return $a;
}

public static function castNotation(\DOMNotation $dom, array $a, $isNested, &$cut)
public static function castNotation(\DOMNotation $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'publicId' => $dom->publicId,
Expand All @@ -248,7 +267,7 @@ public static function castNotation(\DOMNotation $dom, array $a, $isNested, &$cu
return $a;
}

public static function castEntity(\DOMEntity $dom, array $a, $isNested, &$cut)
public static function castEntity(\DOMEntity $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'publicId' => $dom->publicId,
Expand All @@ -262,7 +281,7 @@ public static function castEntity(\DOMEntity $dom, array $a, $isNested, &$cut)
return $a;
}

public static function castProcessingInstruction(\DOMProcessingInstruction $dom, array $a, $isNested, &$cut)
public static function castProcessingInstruction(\DOMProcessingInstruction $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'target' => $dom->target,
Expand All @@ -272,7 +291,7 @@ public static function castProcessingInstruction(\DOMProcessingInstruction $dom,
return $a;
}

public static function castXPath(\DOMXPath $dom, array $a, $isNested, &$cut)
public static function castXPath(\DOMXPath $dom, array $a, Stub $stub, $isNested)
{
$a += array(
'document' => $dom->document,
Expand Down
34 changes: 10 additions & 24 deletions src/Symfony/Component/VarDumper/Caster/DoctrineCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Symfony\Component\VarDumper\Caster;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Proxy\Proxy as CommonProxy;
use Doctrine\ORM\Proxy\Proxy as OrmProxy;
use Doctrine\ORM\PersistentCollection;
use Symfony\Component\VarDumper\Cloner\Stub;

/**
* Casts Doctrine related classes to array representation.
Expand All @@ -23,50 +23,36 @@
*/
class DoctrineCaster
{
public static function castCommonProxy(CommonProxy $proxy, array $a, $isNested, &$cut)
public static function castCommonProxy(CommonProxy $proxy, array $a, Stub $stub, $isNested)
{
unset(
$a['__cloner__'],
$a['__initializer__']
);
$cut += 2;
$stub->cut += 2;

return $a;
}

public static function castOrmProxy(OrmProxy $proxy, array $a, $isNested, &$cut)
public static function castOrmProxy(OrmProxy $proxy, array $a, Stub $stub, $isNested)
{
$prefix = "\0Doctrine\\ORM\\Proxy\\Proxy\0";
unset(
$a[$prefix.'_entityPersister'],
$a[$prefix.'_identifier']
);
$cut += 2;
$stub->cut += 2;

return $a;
}

public static function castObjectManager(ObjectManager $manager, array $a, $isNested, &$cut)
{
if ($isNested) {
$cut += count($a);

return array();
}

return $a;
}

public static function castPersistentCollection(PersistentCollection $coll, array $a, $isNested, &$cut)
public static function castPersistentCollection(PersistentCollection $coll, array $a, Stub $stub, $isNested)
{
$prefix = "\0Doctrine\\ORM\\PersistentCollection\0";
unset(
$a[$prefix.'snapshot'],
$a[$prefix.'association'],
$a[$prefix.'em'],
$a[$prefix.'typeClass']
);
$cut += 4;

$a[$prefix.'snapshot'] = new CasterStub($a[$prefix.'snapshot']);
$a[$prefix.'association'] = new CasterStub($a[$prefix.'association']);
$a[$prefix.'typeClass'] = new CasterStub($a[$prefix.'typeClass']);

return $a;
}
Expand Down
Loading
0