本文整理汇总了PHP中Symfony\Component\VarDumper\Cloner\VarCloner::addCasters方法的典型用法代码示例。如果您正苦于以下问题:PHP VarCloner::addCasters方法的具体用法?PHP VarCloner::addCasters怎么用?PHP VarCloner::addCasters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\VarDumper\Cloner\VarCloner
的用法示例。
在下文中一共展示了VarCloner::addCasters方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
$app['dump'] = $app->protect(function ($var) use($app) {
if (!$app['debug']) {
return;
}
$app['dumper']->dump($app['dumper.cloner']->cloneVar($var));
});
VarDumper::setHandler(function ($var) use($app) {
/*
* Referencing $app['dump'] in anonymous function
* so the closure can be replaced in $app without
* breaking the reference here.
*/
return $app['dump']($var);
});
$app['dumper'] = $app->share(function ($app) {
return PHP_SAPI === 'cli' ? $app['dumper.cli'] : $app['dumper.html'];
});
$app['dumper.cli'] = $app->share(function () {
return new CliDumper();
});
$app['dumper.html'] = $app->share(function () {
return new HtmlDumper();
});
$app['dumper.cloner'] = $app->share(function () {
$cloner = new VarCloner();
$cloner->addCasters(Caster\FilesystemCasters::getCasters());
return $cloner;
});
}
示例2: cloneVar
/**
* Converts the variable into a serializable Data instance.
*
* @param mixed $var
*
* @return Data
*/
private function cloneVar($var)
{
if (null === $this->cloner) {
$this->cloner = new VarCloner();
$this->cloner->addCasters(array(Stub::class => function (Stub $v, array $a, Stub $s, $isNested) {
return $isNested ? $a : StubCaster::castStub($v, $a, $s, true);
}, \Exception::class => function (\Exception $e, array $a, Stub $s) {
if (isset($a[$k = "Exceptionprevious"])) {
unset($a[$k]);
++$s->cut;
}
return $a;
}, FormInterface::class => function (FormInterface $f, array $a) {
return array(Caster::PREFIX_VIRTUAL . 'name' => $f->getName(), Caster::PREFIX_VIRTUAL . 'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())));
}, ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) {
return array(Caster::PREFIX_VIRTUAL . 'root' => $v->getRoot(), Caster::PREFIX_VIRTUAL . 'path' => $v->getPropertyPath(), Caster::PREFIX_VIRTUAL . 'value' => $v->getInvalidValue());
}));
}
return $this->cloner->cloneVar($var);
}
示例3: register
/**
* {@inheritdoc}
*/
public function register(Application $app)
{
$app['dump'] = $app->protect(function ($var) use($app) {
$app['dumper']->dump($app['dumper.cloner']->cloneVar($var));
});
VarDumper::setHandler($app['dump']);
$app['dumper'] = $app->share(function ($app) {
return PHP_SAPI === 'cli' ? $app['dumper.cli'] : $app['dumper.html'];
});
$app['dumper.cli'] = $app->share(function () {
return new CliDumper();
});
$app['dumper.html'] = $app->share(function () {
return new HtmlDumper();
});
$app['dumper.cloner'] = $app->share(function () {
$cloner = new VarCloner();
$cloner->addCasters(Caster\FilesystemCasters::getCasters());
return $cloner;
});
}
示例4: testGet
public function testGet()
{
require __DIR__ . '/Fixtures/dumb-var.php';
$dumper = new HtmlDumper('php://output');
$dumper->setDumpHeader('<foo></foo>');
$dumper->setDumpBoundaries('<bar>', '</bar>');
$cloner = new VarCloner();
$cloner->addCasters(array(':stream' => function ($res, $a) {
unset($a['uri']);
return $a;
}));
$data = $cloner->cloneVar($var);
ob_start();
$dumper->dump($data);
$out = ob_get_clean();
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
$out = preg_replace('/[ \\t]+$/m', '', $out);
$var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
$intMax = PHP_INT_MAX;
preg_match('/sf-dump-\\d+/', $out, $dumpId);
$dumpId = $dumpId[0];
$res1 = (int) $var['res'];
$res2 = (int) $var[8];
$this->assertStringMatchesFormat(<<<EOTXT
<foo></foo><bar><span class=sf-dump-note>array:25</span> [<samp>
"<span class=sf-dump-key>number</span>" => <span class=sf-dump-num>1</span>
<span class=sf-dump-key>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref01 title="2 occurrences">&1</a> <span class=sf-dump-const>null</span>
"<span class=sf-dump-key>const</span>" => <span class=sf-dump-num>1.1</span>
<span class=sf-dump-key>1</span> => <span class=sf-dump-const>true</span>
<span class=sf-dump-key>2</span> => <span class=sf-dump-const>false</span>
<span class=sf-dump-key>3</span> => <span class=sf-dump-num>NAN</span>
<span class=sf-dump-key>4</span> => <span class=sf-dump-num>INF</span>
<span class=sf-dump-key>5</span> => <span class=sf-dump-num>-INF</span>
<span class=sf-dump-key>6</span> => <span class=sf-dump-num>{$intMax}</span>
"<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="4 characters">déjà</span>"
<span class=sf-dump-key>7</span> => b"<span class=sf-dump-str title="2 binary or non-UTF-8 characters">é<span class=sf-dump-cchr title=\\x00>␀</span></span>"
"<span class=sf-dump-key>[]</span>" => []
"<span class=sf-dump-key>res</span>" => <abbr title="`stream` resource" class=sf-dump-note>:stream</abbr> {<a class=sf-dump-ref>@{$res1}</a><samp>
<span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str title="9 characters">plainfile</span>"
<span class=sf-dump-meta>stream_type</span>: "<span class=sf-dump-str title="5 characters">STDIO</span>"
<span class=sf-dump-meta>mode</span>: "<span class=sf-dump-str>r</span>"
<span class=sf-dump-meta>unread_bytes</span>: <span class=sf-dump-num>0</span>
<span class=sf-dump-meta>seekable</span>: <span class=sf-dump-const>true</span>
<span class=sf-dump-meta>timed_out</span>: <span class=sf-dump-const>false</span>
<span class=sf-dump-meta>blocked</span>: <span class=sf-dump-const>true</span>
<span class=sf-dump-meta>eof</span>: <span class=sf-dump-const>false</span>
<span class=sf-dump-meta>options</span>: []
</samp>}
<span class=sf-dump-key>8</span> => <abbr title="`Unknown` resource" class=sf-dump-note>:Unknown</abbr> {<a class=sf-dump-ref>@{$res2}</a>}
"<span class=sf-dump-key>obj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="2 occurrences">#%d</a><samp id={$dumpId}-ref2%d>
+<span class=sf-dump-public title="Public property">foo</span>: "<span class=sf-dump-str title="3 characters">foo</span>"
+"<span class=sf-dump-public title="Runtime added dynamic property">bar</span>": "<span class=sf-dump-str title="3 characters">bar</span>"
</samp>}
"<span class=sf-dump-key>closure</span>" => <span class=sf-dump-note>Closure</span> {<a class=sf-dump-ref>#%d</a><samp>
<span class=sf-dump-meta>reflection</span>: """
<span class=sf-dump-str title="%d characters">Closure [ <user> {$closureLabel} Symfony\\Component\\VarDumper\\Tests\\Fixture\\{closure} ] {</span>
<span class=sf-dump-str title="%d characters"> @@ {$var['file']} {$var['line']} - {$var['line']}</span>
<span class=sf-dump-str title="%d characters"> - Parameters [2] {</span>
<span class=sf-dump-str title="%d characters"> Parameter #0 [ <required> \$a ]</span>
<span class=sf-dump-str title="%d characters"> Parameter #1 [ <optional> PDO or NULL &\$b = NULL ]</span>
<span class=sf-dump-str title="%d characters"> }</span>
<span class=sf-dump-str title="%d characters">}</span>
"""
</samp>}
"<span class=sf-dump-key>line</span>" => <span class=sf-dump-num>{$var['line']}</span>
"<span class=sf-dump-key>nobj</span>" => <span class=sf-dump-note>array:1</span> [<samp>
<span class=sf-dump-index>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref03 title="2 occurrences">&3</a> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="3 occurrences">#%d</a>}
</samp>]
"<span class=sf-dump-key>recurs</span>" => <a class=sf-dump-ref href=#{$dumpId}-ref04 title="2 occurrences">&4</a> <span class=sf-dump-note>array:1</span> [<samp id={$dumpId}-ref04>
<span class=sf-dump-index>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref04 title="2 occurrences">&4</a> <span class=sf-dump-note>array:1</span> [<a class=sf-dump-ref href=#{$dumpId}-ref04 title="2 occurrences">&4</a>]
</samp>]
<span class=sf-dump-key>9</span> => <a class=sf-dump-ref href=#{$dumpId}-ref01 title="2 occurrences">&1</a> <span class=sf-dump-const>null</span>
"<span class=sf-dump-key>sobj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="2 occurrences">#%d</a>}
"<span class=sf-dump-key>snobj</span>" => <a class=sf-dump-ref href=#{$dumpId}-ref03 title="2 occurrences">&3</a> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="3 occurrences">#%d</a>}
"<span class=sf-dump-key>snobj2</span>" => {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="3 occurrences">#%d</a>}
"<span class=sf-dump-key>file</span>" => "<span class=sf-dump-str title="%d characters">{$var['file']}</span>"
b"<span class=sf-dump-key>bin-key-é</span>" => ""
</samp>]
</bar>
EOTXT
, $out);
}
示例5: testThrowingCaster
public function testThrowingCaster()
{
$out = fopen('php://memory', 'r+b');
$dumper = new CliDumper();
$dumper->setColors(false);
$cloner = new VarCloner();
$cloner->addCasters(array(':stream' => function () {
throw new \Exception('Foobar');
}));
$line = __LINE__ - 3;
$file = __FILE__;
$ref = (int) $out;
$data = $cloner->cloneVar($out);
$dumper->dump($data, $out);
rewind($out);
$out = stream_get_contents($out);
$this->assertStringMatchesFormat(<<<EOTXT
:stream {@{$ref}
wrapper_type: "PHP"
stream_type: "MEMORY"
mode: "w+b"
unread_bytes: 0
seekable: true
uri: "php://memory"
timed_out: false
blocked: true
eof: false
options: []
⚠: Symfony\\Component\\VarDumper\\Exception\\ThrowingCasterException {#%d
#message: "Unexpected Exception thrown from a caster: Foobar"
trace: array:1 [
0 => array:2 [
"call" => "%s{closure}()"
"file" => "{$file}:{$line}"
]
]
}
}
EOTXT
, $out);
}
示例6: testThrowingCaster
public function testThrowingCaster()
{
$out = fopen('php://memory', 'r+b');
require_once __DIR__ . '/Fixtures/Twig.php';
$twig = new \__TwigTemplate_VarDumperFixture_u75a09(new \Twig_Environment(new \Twig_Loader_Filesystem()));
$dumper = new CliDumper();
$dumper->setColors(false);
$cloner = new VarCloner();
$cloner->addCasters(array(':stream' => function ($res, $a) {
unset($a['wrapper_data']);
return $a;
}));
$cloner->addCasters(array(':stream' => eval('return function () use ($twig) {
try {
$twig->render(array());
} catch (\\Twig_Error_Runtime $e) {
throw $e->getPrevious();
}
};')));
$line = __LINE__ - 2;
$ref = (int) $out;
$data = $cloner->cloneVar($out);
$dumper->dump($data, $out);
rewind($out);
$out = stream_get_contents($out);
if (method_exists($twig, 'getSource')) {
$twig = <<<EOTXT
foo.twig: {
1: foo bar
2: twig source
3:
}
EOTXT;
} else {
$twig = '%A';
}
$r = defined('HHVM_VERSION') ? '' : '#%d';
$this->assertStringMatchesFormat(<<<EOTXT
stream resource {@{$ref}
%Awrapper_type: "PHP"
stream_type: "MEMORY"
mode: "%s+b"
unread_bytes: 0
seekable: true
uri: "php://memory"
%Aoptions: []
⚠: Symfony\\Component\\VarDumper\\Exception\\ThrowingCasterException {{$r}
#message: "Unexpected Exception thrown from a caster: Foobar"
-trace: {
%d. {$twig}
%d. %sTemplate.php: {
%d: try {
%d: \$this->doDisplay(\$context, \$blocks);
%d: } catch (Twig_Error \$e) {
}
%d. %sTemplate.php: {
%d: {
%d: \$this->displayWithErrorHandling(\$this->env->mergeGlobals(\$context), array_merge(\$this->blocks, \$blocks));
%d: }
}
%d. %sTemplate.php: {
%d: try {
%d: \$this->display(\$context);
%d: } catch (Exception \$e) {
}
%d. %sCliDumperTest.php: {
%d: }
{$line}: };'),
%d: ));
}
}
}
}
EOTXT
, $out);
}
示例7: testGet
public function testGet()
{
require __DIR__ . '/Fixtures/dumb-var.php';
$dumper = new HtmlDumper('php://output');
$dumper->setDumpHeader('<foo></foo>');
$dumper->setDumpBoundaries('<bar>', '</bar>');
$cloner = new VarCloner();
$cloner->addCasters(array(':stream' => function ($res, $a) {
unset($a['uri'], $a['wrapper_data']);
return $a;
}));
$data = $cloner->cloneVar($var);
ob_start();
$dumper->dump($data);
$out = ob_get_clean();
$out = preg_replace('/[ \\t]+$/m', '', $out);
$var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
$intMax = PHP_INT_MAX;
preg_match('/sf-dump-\\d+/', $out, $dumpId);
$dumpId = $dumpId[0];
$res = (int) $var['res'];
$r = defined('HHVM_VERSION') ? '' : '<a class=sf-dump-ref>#%d</a>';
$this->assertStringMatchesFormat(<<<EOTXT
<foo></foo><bar><span class=sf-dump-note>array:24</span> [<samp>
"<span class=sf-dump-key>number</span>" => <span class=sf-dump-num>1</span>
<span class=sf-dump-key>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref01 title="2 occurrences">&1</a> <span class=sf-dump-const>null</span>
"<span class=sf-dump-key>const</span>" => <span class=sf-dump-num>1.1</span>
<span class=sf-dump-key>1</span> => <span class=sf-dump-const>true</span>
<span class=sf-dump-key>2</span> => <span class=sf-dump-const>false</span>
<span class=sf-dump-key>3</span> => <span class=sf-dump-num>NAN</span>
<span class=sf-dump-key>4</span> => <span class=sf-dump-num>INF</span>
<span class=sf-dump-key>5</span> => <span class=sf-dump-num>-INF</span>
<span class=sf-dump-key>6</span> => <span class=sf-dump-num>{$intMax}</span>
"<span class=sf-dump-key>str</span>" => "<span class=sf-dump-str title="5 characters">d&%s;j&%s;</span>\\n"
<span class=sf-dump-key>7</span> => b"<span class=sf-dump-str title="2 binary or non-UTF-8 characters">&%s;</span>\\x00"
"<span class=sf-dump-key>[]</span>" => []
"<span class=sf-dump-key>res</span>" => <span class=sf-dump-note>stream resource</span> <a class=sf-dump-ref>@{$res}</a><samp>
<span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str title="9 characters">plainfile</span>"
<span class=sf-dump-meta>stream_type</span>: "<span class=sf-dump-str title="5 characters">STDIO</span>"
<span class=sf-dump-meta>mode</span>: "<span class=sf-dump-str>r</span>"
<span class=sf-dump-meta>unread_bytes</span>: <span class=sf-dump-num>0</span>
<span class=sf-dump-meta>seekable</span>: <span class=sf-dump-const>true</span>
<span class=sf-dump-meta>timed_out</span>: <span class=sf-dump-const>false</span>
<span class=sf-dump-meta>blocked</span>: <span class=sf-dump-const>true</span>
<span class=sf-dump-meta>eof</span>: <span class=sf-dump-const>false</span>
<span class=sf-dump-meta>options</span>: []
</samp>}
"<span class=sf-dump-key>obj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="2 occurrences">#%d</a><samp id={$dumpId}-ref2%d>
+<span class=sf-dump-public title="Public property">foo</span>: "<span class=sf-dump-str title="3 characters">foo</span>"
+"<span class=sf-dump-public title="Runtime added dynamic property">bar</span>": "<span class=sf-dump-str title="3 characters">bar</span>"
</samp>}
"<span class=sf-dump-key>closure</span>" => <span class=sf-dump-note>Closure</span> {{$r}<samp>
<span class=sf-dump-meta>class</span>: "<span class=sf-dump-str title="48 characters">Symfony\\Component\\VarDumper\\Tests\\HtmlDumperTest</span>"
<span class=sf-dump-meta>this</span>: <abbr title="Symfony\\Component\\VarDumper\\Tests\\HtmlDumperTest" class=sf-dump-note>HtmlDumperTest</abbr> {{$r} &%s;}
<span class=sf-dump-meta>parameters</span>: {<samp>
<span class=sf-dump-meta>\$a</span>: {}
<span class=sf-dump-meta>&\$b</span>: {<samp>
<span class=sf-dump-meta>typeHint</span>: "<span class=sf-dump-str title="3 characters">PDO</span>"
<span class=sf-dump-meta>default</span>: <span class=sf-dump-const>null</span>
</samp>}
</samp>}
<span class=sf-dump-meta>file</span>: "<span class=sf-dump-str title="%d characters">{$var['file']}</span>"
<span class=sf-dump-meta>line</span>: "<span class=sf-dump-str title="%d characters">{$var['line']} to {$var['line']}</span>"
</samp>}
"<span class=sf-dump-key>line</span>" => <span class=sf-dump-num>{$var['line']}</span>
"<span class=sf-dump-key>nobj</span>" => <span class=sf-dump-note>array:1</span> [<samp>
<span class=sf-dump-index>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref03 title="2 occurrences">&3</a> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="3 occurrences">#%d</a>}
</samp>]
"<span class=sf-dump-key>recurs</span>" => <a class=sf-dump-ref href=#{$dumpId}-ref04 title="2 occurrences">&4</a> <span class=sf-dump-note>array:1</span> [<samp id={$dumpId}-ref04>
<span class=sf-dump-index>0</span> => <a class=sf-dump-ref href=#{$dumpId}-ref04 title="2 occurrences">&4</a> <span class=sf-dump-note>array:1</span> [<a class=sf-dump-ref href=#{$dumpId}-ref04 title="2 occurrences">&4</a>]
</samp>]
<span class=sf-dump-key>8</span> => <a class=sf-dump-ref href=#{$dumpId}-ref01 title="2 occurrences">&1</a> <span class=sf-dump-const>null</span>
"<span class=sf-dump-key>sobj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="2 occurrences">#%d</a>}
"<span class=sf-dump-key>snobj</span>" => <a class=sf-dump-ref href=#{$dumpId}-ref03 title="2 occurrences">&3</a> {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="3 occurrences">#%d</a>}
"<span class=sf-dump-key>snobj2</span>" => {<a class=sf-dump-ref href=#{$dumpId}-ref2%d title="3 occurrences">#%d</a>}
"<span class=sf-dump-key>file</span>" => "<span class=sf-dump-str title="%d characters">{$var['file']}</span>"
b"<span class=sf-dump-key>bin-key-&%s;</span>" => ""
</samp>]
</bar>
EOTXT
, $out);
}
示例8: testGet
public function testGet()
{
require __DIR__ . '/Fixtures/dumb-var.php';
$dumper = new HtmlDumper('php://output');
$dumper->setColors(false);
$dumper->setDumpHeader('<foo></foo>');
$dumper->setDumpBoundaries('<bar>', '</bar>');
$cloner = new VarCloner();
$cloner->addCasters(array(':stream' => function ($res, $a) {
unset($a['uri']);
return $a;
}));
$data = $cloner->cloneVar($var);
ob_start();
$dumper->dump($data);
$out = ob_get_clean();
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
$out = preg_replace('/[ \\t]+$/m', '', $out);
$var['file'] = htmlspecialchars($var['file'], ENT_QUOTES, 'UTF-8');
$intMax = PHP_INT_MAX;
preg_match('/sf-dump-\\d+/', $out, $dumpId);
$dumpId = $dumpId[0];
$this->assertSame(<<<EOTXT
<foo></foo><bar><span class=sf-dump-note>array:25</span> [<span name=sf-dump-child>
"<span class=sf-dump-meta>number</span>" => <span class=sf-dump-num>1</span>
<span class=sf-dump-meta>0</span> => <span class=sf-dump-const>null</span> <span class=sf-dump-ref name=sf-dump-ref id="{$dumpId}-ref1">#1</span>
"<span class=sf-dump-meta>const</span>" => <span class=sf-dump-num>1.1</span>
<span class=sf-dump-meta>1</span> => <span class=sf-dump-const>true</span>
<span class=sf-dump-meta>2</span> => <span class=sf-dump-const>false</span>
<span class=sf-dump-meta>3</span> => <span class=sf-dump-num>NAN</span>
<span class=sf-dump-meta>4</span> => <span class=sf-dump-num>INF</span>
<span class=sf-dump-meta>5</span> => <span class=sf-dump-num>-INF</span>
<span class=sf-dump-meta>6</span> => <span class=sf-dump-num>{$intMax}</span>
"<span class=sf-dump-meta>str</span>" => "<span class=sf-dump-str>déjà</span>"
<span class=sf-dump-meta>7</span> => b"<span class=sf-dump-str>é</span>"
"<span class=sf-dump-meta>[]</span>" => []
"<span class=sf-dump-meta>res</span>" => <abbr title="Resource of type `stream`" class=sf-dump-note>:stream</abbr> {<span name=sf-dump-child>
<span class=sf-dump-meta>wrapper_type</span>: "<span class=sf-dump-str>plainfile</span>"
<span class=sf-dump-meta>stream_type</span>: "<span class=sf-dump-str>STDIO</span>"
<span class=sf-dump-meta>mode</span>: "<span class=sf-dump-str>r</span>"
<span class=sf-dump-meta>unread_bytes</span>: <span class=sf-dump-num>0</span>
<span class=sf-dump-meta>seekable</span>: <span class=sf-dump-const>true</span>
<span class=sf-dump-meta>timed_out</span>: <span class=sf-dump-const>false</span>
<span class=sf-dump-meta>blocked</span>: <span class=sf-dump-const>true</span>
<span class=sf-dump-meta>eof</span>: <span class=sf-dump-const>false</span>
<span class=sf-dump-meta>options</span>: []
</span>}
<span class=sf-dump-meta>8</span> => <abbr title="Resource of type `Unknown`" class=sf-dump-note>:Unknown</abbr> {}
"<span class=sf-dump-meta>obj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<span name=sf-dump-child> <span class=sf-dump-ref name=sf-dump-ref id="{$dumpId}-ref2">#2</span>
<span class=sf-dump-public>foo</span>: "<span class=sf-dump-str>foo</span>"
"<span class=sf-dump-public>bar</span>": "<span class=sf-dump-str>bar</span>"
</span>}
"<span class=sf-dump-meta>closure</span>" => <span class=sf-dump-note>Closure</span> {<span name=sf-dump-child>
<span class=sf-dump-meta>reflection</span>: """
<span class=sf-dump-str>Closure [ <user> {$closureLabel} Symfony\\Component\\VarDumper\\Tests\\Fixture\\{closure} ] {</span>
<span class=sf-dump-str> @@ {$var['file']} {$var['line']} - {$var['line']}</span>
<span class=sf-dump-str> - Parameters [2] {</span>
<span class=sf-dump-str> Parameter #0 [ <required> \$a ]</span>
<span class=sf-dump-str> Parameter #1 [ <optional> PDO or NULL &\$b = NULL ]</span>
<span class=sf-dump-str> }</span>
<span class=sf-dump-str>}</span>
"""
</span>}
"<span class=sf-dump-meta>line</span>" => <span class=sf-dump-num>{$var['line']}</span>
"<span class=sf-dump-meta>nobj</span>" => <span class=sf-dump-note>array:1</span> [<span name=sf-dump-child>
<span class=sf-dump-meta>0</span> => {} <span class=sf-dump-ref name=sf-dump-ref id="{$dumpId}-ref3">#3</span>
</span>]
"<span class=sf-dump-meta>recurs</span>" => <span class=sf-dump-note>array:1</span> [<span name=sf-dump-child> <span class=sf-dump-ref name=sf-dump-ref id="{$dumpId}-ref4">#4</span>
<span class=sf-dump-meta>0</span> => <a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref4">&4</a> <span class=sf-dump-note>array:1</span> [<a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref4">@4</a>]
</span>]
<span class=sf-dump-meta>9</span> => <a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref1">&1</a> <span class=sf-dump-const>null</span>
"<span class=sf-dump-meta>sobj</span>" => <abbr title="Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo" class=sf-dump-note>DumbFoo</abbr> {<a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref2">@2</a>}
"<span class=sf-dump-meta>snobj</span>" => <a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref3">&3</a> {<a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref3">@3</a>}
"<span class=sf-dump-meta>snobj2</span>" => {<a class=sf-dump-ref name=sf-dump-ref href="#{$dumpId}-ref3">@3</a>}
"<span class=sf-dump-meta>file</span>" => "<span class=sf-dump-str>{$var['file']}</span>"
b"<span class=sf-dump-meta>bin-key-é</span>" => ""
</span>]
</bar>
EOTXT
, $out);
}
示例9: handle
/**
* @return int|null
*/
public function handle()
{
if (!$this->handleUnconditionally()) {
// Check conditions for outputting HTML:
// @todo: Make this more robust
if (php_sapi_name() === 'cli') {
// Help users who have been relying on an internal test value
// fix their code to the proper method
if (isset($_ENV['whoops-test'])) {
throw new \Exception('Use handleUnconditionally instead of whoops-test' . ' environment variable');
}
return Handler::DONE;
}
}
// @todo: Make this more dynamic
$helper = new TemplateHelper();
$cloner = new VarCloner();
// Only dump object internals if a custom caster exists.
$cloner->addCasters(['*' => function ($obj, $a, $stub, $isNested, $filter = 0) {
$class = $stub->class;
$classes = [$class => $class] + class_parents($class) + class_implements($class);
foreach ($classes as $class) {
if (isset(AbstractCloner::$defaultCasters[$class])) {
return $a;
}
}
// Remove all internals
return [];
}]);
$helper->setCloner($cloner);
$templateFile = $this->getResource("views/layout.html.php");
$cssFile = $this->getResource("css/whoops.base.css");
$zeptoFile = $this->getResource("js/zepto.min.js");
$clipboard = $this->getResource("js/clipboard.min.js");
$jsFile = $this->getResource("js/whoops.base.js");
if ($this->customCss) {
$customCssFile = $this->getResource($this->customCss);
}
$inspector = $this->getInspector();
$frames = $inspector->getFrames();
$code = $inspector->getException()->getCode();
if ($inspector->getException() instanceof \ErrorException) {
// ErrorExceptions wrap the php-error types within the "severity" property
$code = Misc::translateErrorCode($inspector->getException()->getSeverity());
}
// List of variables that will be passed to the layout template.
$vars = array("page_title" => $this->getPageTitle(), "stylesheet" => file_get_contents($cssFile), "zepto" => file_get_contents($zeptoFile), "clipboard" => file_get_contents($clipboard), "javascript" => file_get_contents($jsFile), "header" => $this->getResource("views/header.html.php"), "frame_list" => $this->getResource("views/frame_list.html.php"), "frame_code" => $this->getResource("views/frame_code.html.php"), "env_details" => $this->getResource("views/env_details.html.php"), "title" => $this->getPageTitle(), "name" => explode("\\", $inspector->getExceptionName()), "message" => $inspector->getException()->getMessage(), "code" => $code, "plain_exception" => Formatter::formatExceptionPlain($inspector), "frames" => $frames, "has_frames" => !!count($frames), "handler" => $this, "handlers" => $this->getRun()->getHandlers(), "tables" => array("GET Data" => $_GET, "POST Data" => $_POST, "Files" => $_FILES, "Cookies" => $_COOKIE, "Session" => isset($_SESSION) ? $_SESSION : array(), "Server/Request Data" => $_SERVER, "Environment Variables" => $_ENV));
if (isset($customCssFile)) {
$vars["stylesheet"] .= file_get_contents($customCssFile);
}
// Add extra entries list of data tables:
// @todo: Consolidate addDataTable and addDataTableCallback
$extraTables = array_map(function ($table) {
return $table instanceof \Closure ? $table() : $table;
}, $this->getDataTables());
$vars["tables"] = array_merge($extraTables, $vars["tables"]);
if (\Whoops\Util\Misc::canSendHeaders()) {
header('Content-Type: text/html');
}
$helper->setVariables($vars);
$helper->render($templateFile);
return Handler::QUIT;
}
示例10: testGet
public function testGet()
{
require __DIR__ . '/Fixtures/dumb-var.php';
$dumper = new CliDumper('php://output');
$dumper->setColors(false);
$cloner = new VarCloner();
$cloner->addCasters(array(':stream' => function ($res, $a) {
unset($a['uri']);
return $a;
}));
$data = $cloner->cloneVar($var);
ob_start();
$dumper->dump($data);
$out = ob_get_clean();
$closureLabel = PHP_VERSION_ID >= 50400 ? 'public method' : 'function';
$out = preg_replace('/[ \\t]+$/m', '', $out);
$intMax = PHP_INT_MAX;
$res1 = (int) $var['res'];
$res2 = (int) $var[8];
$this->assertStringMatchesFormat(<<<EOTXT
array:25 [
"number" => 1
0 => &1 null
"const" => 1.1
1 => true
2 => false
3 => NAN
4 => INF
5 => -INF
6 => {$intMax}
"str" => "déjà"
7 => b"é@"
"[]" => []
"res" => :stream {@{$res1}
wrapper_type: "plainfile"
stream_type: "STDIO"
mode: "r"
unread_bytes: 0
seekable: true
timed_out: false
blocked: true
eof: false
options: []
}
8 => :Unknown {@{$res2}}
"obj" => Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo {#%d
+foo: "foo"
+"bar": "bar"
}
"closure" => Closure {#%d
reflection: """
Closure [ <user> {$closureLabel} Symfony\\Component\\VarDumper\\Tests\\Fixture\\{closure} ] {
@@ {$var['file']} {$var['line']} - {$var['line']}
- Parameters [2] {
Parameter #0 [ <required> \$a ]
Parameter #1 [ <optional> PDO or NULL &\$b = NULL ]
}
}
"""
}
"line" => {$var['line']}
"nobj" => array:1 [
0 => &3 {#%d}
]
"recurs" => &4 array:1 [
0 => &4 array:1 [&4]
]
9 => &1 null
"sobj" => Symfony\\Component\\VarDumper\\Tests\\Fixture\\DumbFoo {#%d}
"snobj" => &3 {#%d}
"snobj2" => {#%d}
"file" => "{$var['file']}"
b"bin-key-é" => ""
]
EOTXT
, $out);
}
示例11: testThrowingCaster
public function testThrowingCaster()
{
$out = fopen('php://memory', 'r+b');
$dumper = new CliDumper();
$dumper->setColors(false);
$cloner = new VarCloner();
$cloner->addCasters(array(':stream' => function ($res, $a) {
unset($a['wrapper_data']);
return $a;
}));
$cloner->addCasters(array(':stream' => function () {
throw new \Exception('Foobar');
}));
$line = __LINE__ - 3;
$file = __FILE__;
$ref = (int) $out;
$data = $cloner->cloneVar($out);
$dumper->dump($data, $out);
rewind($out);
$out = stream_get_contents($out);
$r = defined('HHVM_VERSION') ? '' : '#%d';
$this->assertStringMatchesFormat(<<<EOTXT
stream resource {@{$ref}
%Awrapper_type: "PHP"
stream_type: "MEMORY"
mode: "%s+b"
unread_bytes: 0
seekable: true
uri: "php://memory"
%Aoptions: []
⚠: Symfony\\Component\\VarDumper\\Exception\\ThrowingCasterException {{$r}
#message: "Unexpected Exception thrown from a caster: Foobar"
trace: array:1 [
0 => array:2 [
"call" => "%slosure%s()"
"file" => "{$file}:{$line}"
]
]
}
}
EOTXT
, $out);
}