Merge branch '2.8'

* 2.8:
  fixed deprecation notices
  fixed typos
  [FrameworkBundle] Tag deprecated services
  [VarDumper] Dump PHP+Twig code excerpts in backtraces
  [Config] Fix ArrayNode extra keys "ignore" and "remove" behaviors
This commit is contained in:
Fabien Potencier 2015-09-30 14:30:29 +02:00
commit ed610df788
17 changed files with 413 additions and 144 deletions

View File

@ -7,6 +7,7 @@
<services>
<service id="form.csrf_provider" class="Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfTokenManagerAdapter">
<argument type="service" id="security.csrf.token_manager" />
<deprecated>The "%service_id%" service is deprecated since Symfony 2.4 and will be removed in 3.0. Use the "security.csrf.token_manager" service instead.</deprecated>
</service>
<service id="form.type_extension.csrf" class="Symfony\Component\Form\Extension\Csrf\Type\FormTypeCsrfExtension">

View File

@ -40,6 +40,7 @@
</call>
</service>
</argument>
<deprecated>The "%service_id%" service is deprecated since Symfony 2.8 and will be removed in 3.0.</deprecated>
</service>
<service id="validator.validator_factory" class="Symfony\Bundle\FrameworkBundle\Validator\ConstraintValidatorFactory" public="false">

View File

@ -303,9 +303,8 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
if (isset($this->children[$name])) {
$normalized[$name] = $this->children[$name]->normalize($val);
unset($value[$name]);
} elseif (false === $this->removeExtraKeys) {
} elseif (!$this->removeExtraKeys) {
$normalized[$name] = $val;
unset($value[$name]);
}
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Config\Tests\Definition;
use Symfony\Component\Config\Definition\ArrayNode;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\ScalarNode;
class ArrayNodeTest extends \PHPUnit_Framework_TestCase
@ -35,34 +36,30 @@ class ArrayNodeTest extends \PHPUnit_Framework_TestCase
$node->normalize(array('foo' => 'bar'));
}
/**
* Tests that no exception is thrown for an unrecognized child if the
* ignoreExtraKeys option is set to true.
*
* Related to testExceptionThrownOnUnrecognizedChild
*/
public function testIgnoreExtraKeysNoException()
public function ignoreAndRemoveMatrixProvider()
{
$node = new ArrayNode('roo');
$node->setIgnoreExtraKeys(true);
$unrecognizedOptionException = new InvalidConfigurationException('Unrecognized option "foo" under "root"');
$node->normalize(array('foo' => 'bar'));
$this->assertTrue(true, 'No exception was thrown when setIgnoreExtraKeys is true');
return array(
array(true, true, array(), 'no exception is thrown for an unrecognized child if the ignoreExtraKeys option is set to true'),
array(true, false, array('foo' => 'bar'), 'extra keys are not removed when ignoreExtraKeys second option is set to false'),
array(false, true, $unrecognizedOptionException),
array(false, false, $unrecognizedOptionException),
);
}
/**
* Tests that extra keys are not removed when
* ignoreExtraKeys second option is set to false.
*
* Related to testExceptionThrownOnUnrecognizedChild
* @dataProvider ignoreAndRemoveMatrixProvider
*/
public function testIgnoreExtraKeysNotRemoved()
public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '')
{
$node = new ArrayNode('roo');
$node->setIgnoreExtraKeys(true, false);
$data = array('foo' => 'bar');
$this->assertSame($data, $node->normalize($data));
if ($expected instanceof \Exception) {
$this->setExpectedException(get_class($expected), $expected->getMessage());
}
$node = new ArrayNode('root');
$node->setIgnoreExtraKeys($ignore, $remove);
$result = $node->normalize(array('foo' => 'bar'));
$this->assertSame($expected, $result, $message);
}
/**

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\CssSelector;
@trigger_error('The '.__NAMESPACE__.'\CssSelector class is deprecated since version 2.8 and will be removed in 3.0. Use directly the \Symfony\Component\CssSelector\Converter class instead.', E_USER_DEPRECATED);
@trigger_error('The '.__NAMESPACE__.'\CssSelector class is deprecated since version 2.8 and will be removed in 3.0. Use directly the \Symfony\Component\CssSelector\CssSelectorConverter class instead.', E_USER_DEPRECATED);
/**
* CssSelector is the main entry point of the component and can convert CSS
@ -57,7 +57,7 @@ namespace Symfony\Component\CssSelector;
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated as of 2.8, will be removed in 3.0. Use the \Symfony\Component\CssSelector\Converter class instead.
* @deprecated as of 2.8, will be removed in 3.0. Use the \Symfony\Component\CssSelector\CssSelectorConverter class instead.
*/
class CssSelector
{
@ -75,7 +75,7 @@ class CssSelector
*/
public static function toXPath($cssExpr, $prefix = 'descendant-or-self::')
{
$converter = new Converter(self::$html);
$converter = new CssSelectorConverter(self::$html);
return $converter->toXPath($cssExpr, $prefix);
}

View File

@ -11,13 +11,13 @@
namespace Symfony\Component\CssSelector\Tests;
use Symfony\Component\CssSelector\Converter;
use Symfony\Component\CssSelector\CssSelectorConverter;
class ConverterTest extends \PHPUnit_Framework_TestCase
class CssSelectorConverterTest extends \PHPUnit_Framework_TestCase
{
public function testCssToXPath()
{
$converter = new Converter();
$converter = new CssSelectorConverter();
$this->assertEquals('descendant-or-self::*', $converter->toXPath(''));
$this->assertEquals('descendant-or-self::h1', $converter->toXPath('h1'));
@ -29,7 +29,7 @@ class ConverterTest extends \PHPUnit_Framework_TestCase
public function testCssToXPathXml()
{
$converter = new Converter(false);
$converter = new CssSelectorConverter(false);
$this->assertEquals('descendant-or-self::H1', $converter->toXPath('H1'));
}

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\DomCrawler;
use Symfony\Component\CssSelector\Converter;
use Symfony\Component\CssSelector\CssSelectorConverter;
/**
* Crawler eases navigation of a list of \DOMElement objects.
@ -41,7 +41,7 @@ class Crawler extends \SplObjectStorage
private $baseHref;
/**
* Whether the Crawler contains HTML or XML content (used when converting CSS to XPath)
* Whether the Crawler contains HTML or XML content (used when converting CSS to XPath).
*
* @var bool
*/
@ -659,11 +659,11 @@ class Crawler extends \SplObjectStorage
*/
public function filter($selector)
{
if (!class_exists('Symfony\\Component\\CssSelector\\Converter')) {
if (!class_exists('Symfony\\Component\\CssSelector\\CssSelectorConverter')) {
throw new \RuntimeException('Unable to filter with a CSS selector as the Symfony CssSelector 2.8+ is not installed (you can use filterXPath instead).');
}
$converter = new Converter($this->isHtml);
$converter = new CssSelectorConverter($this->isHtml);
// The CssSelector already prefixes the selector with descendant-or-self::
return $this->filterRelativeXPath($converter->toXPath($selector));
@ -1142,7 +1142,7 @@ class Crawler extends \SplObjectStorage
}
/**
* Creates a crawler for some subnodes
* Creates a crawler for some subnodes.
*
* @param \DOMElement|\DOMElement[]|\DOMNodeList|null $nodes
*

View File

@ -16,13 +16,13 @@ use Symfony\Component\HttpKernel\Profiler\Profile;
class FileProfilerStorageTest extends AbstractProfilerStorageTest
{
protected static $tmpDir;
protected static $storage;
private $tmpDir;
private $storage;
protected static function cleanDir()
protected function cleanDir()
{
$flags = \FilesystemIterator::SKIP_DOTS;
$iterator = new \RecursiveDirectoryIterator(self::$tmpDir, $flags);
$iterator = new \RecursiveDirectoryIterator($this->tmpDir, $flags);
$iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
@ -32,23 +32,19 @@ class FileProfilerStorageTest extends AbstractProfilerStorageTest
}
}
public static function setUpBeforeClass()
{
self::$tmpDir = sys_get_temp_dir().'/sf2_profiler_file_storage';
if (is_dir(self::$tmpDir)) {
self::cleanDir();
}
self::$storage = new FileProfilerStorage('file:'.self::$tmpDir);
}
public static function tearDownAfterClass()
{
self::cleanDir();
}
protected function setUp()
{
self::$storage->purge();
$this->tmpDir = sys_get_temp_dir().'/sf2_profiler_file_storage';
if (is_dir($this->tmpDir)) {
self::cleanDir();
}
$this->storage = new FileProfilerStorage('file:'.$this->tmpDir);
$this->storage->purge();
}
protected function tearDown()
{
self::cleanDir();
}
/**
@ -56,7 +52,7 @@ class FileProfilerStorageTest extends AbstractProfilerStorageTest
*/
protected function getStorage()
{
return self::$storage;
return $this->storage;
}
public function testMultiRowIndexFile()
@ -73,7 +69,7 @@ class FileProfilerStorageTest extends AbstractProfilerStorageTest
$storage->write($profile);
}
$handle = fopen(self::$tmpDir.'/index.csv', 'r');
$handle = fopen($this->tmpDir.'/index.csv', 'r');
for ($i = 0; $i < $iteration; ++$i) {
$row = fgetcsv($handle);
$this->assertEquals('token'.$i, $row[0]);
@ -85,7 +81,7 @@ class FileProfilerStorageTest extends AbstractProfilerStorageTest
public function testReadLineFromFile()
{
$r = new \ReflectionMethod(self::$storage, 'readLineFromFile');
$r = new \ReflectionMethod($this->storage, 'readLineFromFile');
$r->setAccessible(true);
@ -94,7 +90,7 @@ class FileProfilerStorageTest extends AbstractProfilerStorageTest
fwrite($h, "line1\n\n\nline2\n");
fseek($h, 0, SEEK_END);
$this->assertEquals('line2', $r->invoke(self::$storage, $h));
$this->assertEquals('line1', $r->invoke(self::$storage, $h));
$this->assertEquals('line2', $r->invoke($this->storage, $h));
$this->assertEquals('line1', $r->invoke($this->storage, $h));
}
}

View File

@ -17,14 +17,6 @@ use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class DummyMongoDbProfilerStorage extends MongoDbProfilerStorage
{
public function getMongo()
{
return parent::getMongo();
}
}
class MongoDbProfilerStorageTestDataCollector extends DataCollector
{
public function setData($data)
@ -52,27 +44,7 @@ class MongoDbProfilerStorageTestDataCollector extends DataCollector
*/
class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest
{
protected static $storage;
public static function setUpBeforeClass()
{
if (extension_loaded('mongo')) {
self::$storage = new DummyMongoDbProfilerStorage('mongodb://localhost/symfony_tests/profiler_data', '', '', 86400);
try {
self::$storage->getMongo();
} catch (\MongoConnectionException $e) {
self::$storage = null;
}
}
}
public static function tearDownAfterClass()
{
if (self::$storage) {
self::$storage->purge();
self::$storage = null;
}
}
private $storage;
public function getDsns()
{
@ -108,12 +80,12 @@ class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest
$profile = new Profile('time_'.$i);
$profile->setTime($dt->getTimestamp());
$profile->setMethod('GET');
self::$storage->write($profile);
$this->storage->write($profile);
}
$records = self::$storage->find('', '', 3, 'GET');
$records = $this->storage->find('', '', 3, 'GET');
$this->assertCount(1, $records, '->find() returns only one record');
$this->assertEquals($records[0]['token'], 'time_2', '->find() returns the latest added record');
self::$storage->purge();
$this->storage->purge();
}
/**
@ -121,10 +93,10 @@ class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest
*/
public function testDsnParser($dsn, $expected)
{
$m = new \ReflectionMethod(self::$storage, 'parseDsn');
$m = new \ReflectionMethod($this->storage, 'parseDsn');
$m->setAccessible(true);
$this->assertEquals($expected, $m->invoke(self::$storage, $dsn));
$this->assertEquals($expected, $m->invoke($this->storage, $dsn));
}
public function testUtf8()
@ -139,9 +111,9 @@ class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest
$profile->setCollectors(array($collector));
self::$storage->write($profile);
$this->storage->write($profile);
$readProfile = self::$storage->read('utf8_test_profile');
$readProfile = $this->storage->read('utf8_test_profile');
$collectors = $readProfile->getCollectors();
$this->assertCount(1, $collectors);
@ -154,15 +126,31 @@ class MongoDbProfilerStorageTest extends AbstractProfilerStorageTest
*/
protected function getStorage()
{
return self::$storage;
return $this->storage;
}
protected function setUp()
{
if (self::$storage) {
self::$storage->purge();
} else {
if (!extension_loaded('mongo')) {
$this->markTestSkipped('MongoDbProfilerStorageTest requires the mongo PHP extension and a MongoDB server on localhost');
}
$this->storage = new MongoDbProfilerStorage('mongodb://localhost/symfony_tests/profiler_data', '', '', 86400);
$m = new \ReflectionMethod($this->storage, 'getMongo');
$m->setAccessible(true);
try {
$m->invoke($this->storage);
} catch (\MongoConnectionException $e) {
$this->storage = null;
}
$this->storage->purge();
}
protected function tearDown()
{
if ($this->storage) {
$this->storage->purge();
}
}
}

View File

@ -18,29 +18,27 @@ use Symfony\Component\HttpKernel\Profiler\SqliteProfilerStorage;
*/
class SqliteProfilerStorageTest extends AbstractProfilerStorageTest
{
protected static $dbFile;
protected static $storage;
public static function setUpBeforeClass()
{
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf2_sqlite_storage');
if (file_exists(self::$dbFile)) {
@unlink(self::$dbFile);
}
self::$storage = new SqliteProfilerStorage('sqlite:'.self::$dbFile);
}
public static function tearDownAfterClass()
{
@unlink(self::$dbFile);
}
private $dbFile;
private $storage;
protected function setUp()
{
if (!class_exists('SQLite3') && (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers()))) {
$this->markTestSkipped('This test requires SQLite support in your environment');
}
self::$storage->purge();
$this->dbFile = tempnam(sys_get_temp_dir(), 'sf2_sqlite_storage');
if (file_exists($this->dbFile)) {
@unlink($this->dbFile);
}
$this->storage = new SqliteProfilerStorage('sqlite:'.$this->dbFile);
$this->storage->purge();
}
protected function tearDown()
{
@unlink($this->dbFile);
}
/**
@ -48,6 +46,6 @@ class SqliteProfilerStorageTest extends AbstractProfilerStorageTest
*/
protected function getStorage()
{
return self::$storage;
return $this->storage;
}
}

View File

@ -42,12 +42,12 @@ class ExceptionCaster
public static function castError(\Error $e, array $a, Stub $stub, $isNested, $filter = 0)
{
return self::filterExceptionArray($a, "\0Error\0", $filter);
return self::filterExceptionArray($stub->class, $a, "\0Error\0", $filter);
}
public static function castException(\Exception $e, array $a, Stub $stub, $isNested, $filter = 0)
{
return self::filterExceptionArray($a, "\0Exception\0", $filter);
return self::filterExceptionArray($stub->class, $a, "\0Exception\0", $filter);
}
public static function castErrorException(\ErrorException $e, array $a, Stub $stub, $isNested)
@ -64,24 +64,133 @@ class ExceptionCaster
$prefix = Caster::PREFIX_PROTECTED;
$xPrefix = "\0Exception\0";
if (isset($a[$xPrefix.'previous'], $a[$xPrefix.'trace'][0])) {
if (isset($a[$xPrefix.'previous'], $a[$xPrefix.'trace'])) {
$b = (array) $a[$xPrefix.'previous'];
$b[$xPrefix.'trace'][0] += array(
array_unshift($b[$xPrefix.'trace'], array(
'function' => 'new '.get_class($a[$xPrefix.'previous']),
'file' => $b[$prefix.'file'],
'line' => $b[$prefix.'line'],
);
array_splice($b[$xPrefix.'trace'], -1 - count($a[$xPrefix.'trace']));
static::filterTrace($b[$xPrefix.'trace'], false);
$a[Caster::PREFIX_VIRTUAL.'trace'] = $b[$xPrefix.'trace'];
));
$a[$xPrefix.'trace'] = new TraceStub($b[$xPrefix.'trace'], 1, false, 0, -1 - count($a[$xPrefix.'trace']->value));
}
unset($a[$xPrefix.'trace'], $a[$xPrefix.'previous'], $a[$prefix.'code'], $a[$prefix.'file'], $a[$prefix.'line']);
unset($a[$xPrefix.'previous'], $a[$prefix.'code'], $a[$prefix.'file'], $a[$prefix.'line']);
return $a;
}
public static function castTraceStub(TraceStub $trace, array $a, Stub $stub, $isNested)
{
if (!$isNested) {
return $a;
}
$stub->class = '';
$stub->handle = 0;
$frames = $trace->value;
$a = array();
$j = count($frames);
if (0 > $i = $trace->offset) {
$i = max(0, $j + $i);
}
if (!isset($trace->value[$i])) {
return array();
}
$lastCall = isset($frames[$i]['function']) ? ' ==> '.(isset($frames[$i]['class']) ? $frames[0]['class'].$frames[$i]['type'] : '').$frames[$i]['function'].'()' : '';
for ($j -= $i++; isset($frames[$i]); ++$i, --$j) {
$call = isset($frames[$i]['function']) ? (isset($frames[$i]['class']) ? $frames[$i]['class'].$frames[$i]['type'] : '').$frames[$i]['function'].'()' : '???';
$a[Caster::PREFIX_VIRTUAL.$j.'. '.$call.$lastCall] = new FrameStub(
array(
'object' => isset($frames[$i]['object']) ? $frames[$i]['object'] : null,
'class' => isset($frames[$i]['class']) ? $frames[$i]['class'] : null,
'type' => isset($frames[$i]['type']) ? $frames[$i]['type'] : null,
'function' => isset($frames[$i]['function']) ? $frames[$i]['function'] : null,
) + $frames[$i - 1],
$trace->srcContext,
$trace->keepArgs,
true
);
$lastCall = ' ==> '.$call;
}
$a[Caster::PREFIX_VIRTUAL.$j.'. {main}'.$lastCall] = new FrameStub(
array(
'object' => null,
'class' => null,
'type' => null,
'function' => '{main}',
) + $frames[$i - 1],
$trace->srcContext,
$trace->keepArgs,
true
);
if (null !== $trace->length) {
$a = array_slice($a, 0, $trace->length, true);
}
return $a;
}
public static function castFrameStub(FrameStub $frame, array $a, Stub $stub, $isNested)
{
if (!$isNested) {
return $a;
}
$f = $frame->value;
$prefix = Caster::PREFIX_VIRTUAL;
if (isset($f['file'], $f['line'])) {
if (preg_match('/\((\d+)\)(?:\([\da-f]{32}\))? : (?:eval\(\)\'d code|runtime-created function)$/', $f['file'], $match)) {
$f['file'] = substr($f['file'], 0, -strlen($match[0]));
$f['line'] = (int) $match[1];
}
if (file_exists($f['file']) && 0 <= $frame->srcContext) {
$src[$f['file'].':'.$f['line']] = self::extractSource(explode("\n", file_get_contents($f['file'])), $f['line'], $frame->srcContext);
if (!empty($f['class']) && is_subclass_of($f['class'], 'Twig_Template') && method_exists($f['class'], 'getDebugInfo')) {
$template = isset($f['object']) ? $f['object'] : new $f['class'](new \Twig_Environment(new \Twig_Loader_Filesystem()));
try {
$templateName = $template->getTemplateName();
$templateSrc = explode("\n", method_exists($template, 'getSource') ? $template->getSource() : $template->getEnvironment()->getLoader()->getSource($templateName));
$templateInfo = $template->getDebugInfo();
if (isset($templateInfo[$f['line']])) {
$src[$templateName.':'.$templateInfo[$f['line']]] = self::extractSource($templateSrc, $templateInfo[$f['line']], $frame->srcContext);
}
} catch (\Twig_Error_Loader $e) {
}
}
} else {
$src[$f['file']] = $f['line'];
}
$a[$prefix.'src'] = new EnumStub($src);
}
unset($a[$prefix.'args'], $a[$prefix.'line'], $a[$prefix.'file']);
if ($frame->inTraceStub) {
unset($a[$prefix.'class'], $a[$prefix.'type'], $a[$prefix.'function']);
}
foreach ($a as $k => $v) {
if (!$v) {
unset($a[$k]);
}
}
if ($frame->keepArgs && isset($f['args'])) {
$a[$prefix.'args'] = $f['args'];
}
return $a;
}
/**
* @deprecated since 2.8, to be removed in 3.0. Use the castTraceStub method instead.
*/
public static function filterTrace(&$trace, $dumpArgs, $offset = 0)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the castTraceStub method instead.', E_USER_DEPRECATED);
if (0 > $offset || empty($trace[$offset])) {
return $trace = null;
}
@ -111,7 +220,7 @@ class ExceptionCaster
}
}
private static function filterExceptionArray(array $a, $xPrefix, $filter)
private static function filterExceptionArray($xClass, array $a, $xPrefix, $filter)
{
if (isset($a[$xPrefix.'trace'])) {
$trace = $a[$xPrefix.'trace'];
@ -121,11 +230,12 @@ class ExceptionCaster
}
if (!($filter & Caster::EXCLUDE_VERBOSE)) {
static::filterTrace($trace, static::$traceArgs);
if (null !== $trace) {
$a[$xPrefix.'trace'] = $trace;
}
array_unshift($trace, array(
'function' => $xClass ? 'new '.$xClass : null,
'file' => $a[Caster::PREFIX_PROTECTED.'file'],
'line' => $a[Caster::PREFIX_PROTECTED.'line'],
));
$a[$xPrefix.'trace'] = new TraceStub($trace);
}
if (empty($a[$xPrefix.'previous'])) {
unset($a[$xPrefix.'previous']);
@ -134,4 +244,18 @@ class ExceptionCaster
return $a;
}
private static function extractSource(array $srcArray, $line, $srcContext)
{
$src = '';
for ($i = $line - 1 - $srcContext; $i <= $line - 1 + $srcContext; ++$i) {
$src .= (isset($srcArray[$i]) ? $srcArray[$i] : '')."\n";
}
if (!$srcContext) {
$src = trim($src);
}
return $src;
}
}

View File

@ -0,0 +1,32 @@
<?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;
/**
* Represents a single backtrace frame as returned by debug_backtrace() or Exception->getTrace().
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class FrameStub extends EnumStub
{
public $srcContext;
public $keepArgs;
public $inTraceStub;
public function __construct(array $trace, $srcContext = 1, $keepArgs = true, $inTraceStub = false)
{
$this->value = $trace;
$this->srcContext = $srcContext;
$this->keepArgs = $keepArgs;
$this->inTraceStub = $inTraceStub;
}
}

View File

@ -0,0 +1,36 @@
<?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 a backtrace as returned by debug_backtrace() or Exception->getTrace().
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class TraceStub extends Stub
{
public $srcContext;
public $keepArgs;
public $offset;
public $length;
public function __construct(array $trace, $srcContext = 1, $keepArgs = true, $offset = 0, $length = null)
{
$this->value = $trace;
$this->srcContext = $srcContext;
$this->keepArgs = $keepArgs;
$this->offset = $offset;
$this->length = $length;
}
}

View File

@ -69,6 +69,8 @@ abstract class AbstractCloner implements ClonerInterface
'Error' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castError',
'Symfony\Component\DependencyInjection\ContainerInterface' => 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',
'Symfony\Component\VarDumper\Exception\ThrowingCasterException' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castThrowingCasterException',
'Symfony\Component\VarDumper\Caster\TraceStub' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castTraceStub',
'Symfony\Component\VarDumper\Caster\FrameStub' => 'Symfony\Component\VarDumper\Caster\ExceptionCaster::castFrameStub',
'PHPUnit_Framework_MockObject_MockObject' => 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',
'Prophecy\Prophecy\ProphecySubjectInterface' => 'Symfony\Component\VarDumper\Caster\StubCaster::cutInternals',

View File

@ -163,6 +163,9 @@ EOTXT
{
$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();
@ -174,12 +177,15 @@ EOTXT
},
));
$cloner->addCasters(array(
':stream' => function () {
throw new \Exception('Foobar');
},
':stream' => eval('return function () use ($twig) {
try {
$twig->render(array());
} catch (\Twig_Error_Runtime $e) {
throw $e->getPrevious();
}
};'),
));
$line = __LINE__ - 3;
$file = __FILE__;
$line = __LINE__ - 2;
$ref = (int) $out;
$data = $cloner->cloneVar($out);
@ -187,6 +193,19 @@ EOTXT
rewind($out);
$out = stream_get_contents($out);
if (method_exists($twig, 'getSource')) {
$twig = <<<EOTXT
foo.twig:2: """
foo bar\\n
twig source\\n
\\n
"""
EOTXT;
} else {
$twig = '';
}
$r = defined('HHVM_VERSION') ? '' : '#%d';
$this->assertStringMatchesFormat(
<<<EOTXT
@ -203,12 +222,53 @@ stream resource {@{$ref}
options: []
: 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}"
]
]
-trace: {
%d. __TwigTemplate_VarDumperFixture_u75a09->doDisplay() ==> new Exception(): {
src: {
%sTwig.php:19: """
// line 2\\n
throw new \Exception('Foobar');\\n
}\\n
"""
{$twig} }
}
%d. Twig_Template->displayWithErrorHandling() ==> __TwigTemplate_VarDumperFixture_u75a09->doDisplay(): {
src: {
%sTemplate.php:%d: """
try {\\n
\$this->doDisplay(\$context, \$blocks);\\n
} catch (Twig_Error \$e) {\\n
"""
}
}
%d. Twig_Template->display() ==> Twig_Template->displayWithErrorHandling(): {
src: {
%sTemplate.php:%d: """
{\\n
\$this->displayWithErrorHandling(\$this->env->mergeGlobals(\$context), array_merge(\$this->blocks, \$blocks));\\n
}\\n
"""
}
}
%d. Twig_Template->render() ==> Twig_Template->display(): {
src: {
%sTemplate.php:%d: """
try {\\n
\$this->display(\$context);\\n
} catch (Exception \$e) {\\n
"""
}
}
%d. %slosure%s() ==> Twig_Template->render(): {
src: {
%sCliDumperTest.php:{$line}: """
}\\n
};'),\\n
));\\n
"""
}
}
}
}
}

View File

@ -0,0 +1,34 @@
<?php
/* foo.twig */
class __TwigTemplate_VarDumperFixture_u75a09 extends Twig_Template
{
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
$this->parent = false;
$this->blocks = array(
);
}
protected function doDisplay(array $context, array $blocks = array())
{
// line 2
throw new \Exception('Foobar');
}
public function getTemplateName()
{
return 'foo.twig';
}
public function getDebugInfo()
{
return array (19 => 2);
}
}
/* foo bar*/
/* twig source*/
/* */

View File

@ -19,7 +19,8 @@
"php": ">=5.5.9"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.8|~3.0"
"symfony/phpunit-bridge": "~2.8|~3.0",
"twig/twig": "~1.20|~2.0"
},
"suggest": {
"ext-symfony_debug": ""