X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Fhttp-kernel%2FDataCollector%2FDataCollector.php;fp=vendor%2Fsymfony%2Fhttp-kernel%2FDataCollector%2FDataCollector.php;h=3808852dfaafb6e650ab6d3c56aa89529ef2d0f6;hp=5dca65298d059d0c64438759953423fbdf6e75ba;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/symfony/http-kernel/DataCollector/DataCollector.php b/vendor/symfony/http-kernel/DataCollector/DataCollector.php index 5dca65298..3808852df 100644 --- a/vendor/symfony/http-kernel/DataCollector/DataCollector.php +++ b/vendor/symfony/http-kernel/DataCollector/DataCollector.php @@ -12,6 +12,13 @@ namespace Symfony\Component\HttpKernel\DataCollector; use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter; +use Symfony\Component\VarDumper\Caster\ClassStub; +use Symfony\Component\VarDumper\Caster\LinkStub; +use Symfony\Component\VarDumper\Caster\StubCaster; +use Symfony\Component\VarDumper\Cloner\ClonerInterface; +use Symfony\Component\VarDumper\Cloner\Data; +use Symfony\Component\VarDumper\Cloner\Stub; +use Symfony\Component\VarDumper\Cloner\VarCloner; /** * DataCollector. @@ -30,6 +37,13 @@ abstract class DataCollector implements DataCollectorInterface, \Serializable */ private $valueExporter; + /** + * @var ClonerInterface + */ + private $cloner; + + private static $stubsCache = array(); + public function serialize() { return serialize($this->data); @@ -40,19 +54,92 @@ abstract class DataCollector implements DataCollectorInterface, \Serializable $this->data = unserialize($data); } + /** + * Converts the variable into a serializable Data instance. + * + * This array can be displayed in the template using + * the VarDumper component. + * + * @param mixed $var + * + * @return Data + */ + protected function cloneVar($var) + { + if (null === $this->cloner) { + if (class_exists(ClassStub::class)) { + $this->cloner = new VarCloner(); + $this->cloner->setMaxItems(250); + $this->cloner->addCasters(array( + Stub::class => function (Stub $v, array $a, Stub $s, $isNested) { + return $isNested ? $a : StubCaster::castStub($v, $a, $s, true); + }, + )); + } else { + @trigger_error(sprintf('Using the %s() method without the VarDumper component is deprecated since version 3.2 and won\'t be supported in 4.0. Install symfony/var-dumper version 3.2 or above.', __METHOD__), E_USER_DEPRECATED); + $this->cloner = false; + } + } + if (false === $this->cloner) { + if (null === $this->valueExporter) { + $this->valueExporter = new ValueExporter(); + } + + return $this->valueExporter->exportValue($var); + } + + return $this->cloner->cloneVar($this->decorateVar($var)); + } + /** * Converts a PHP variable to a string. * * @param mixed $var A PHP variable * * @return string The string representation of the variable + * + * @deprecated Deprecated since version 3.2, to be removed in 4.0. Use cloneVar() instead. */ protected function varToString($var) { + @trigger_error(sprintf('The %s() method is deprecated since version 3.2 and will be removed in 4.0. Use cloneVar() instead.', __METHOD__), E_USER_DEPRECATED); + if (null === $this->valueExporter) { $this->valueExporter = new ValueExporter(); } return $this->valueExporter->exportValue($var); } + + private function decorateVar($var) + { + if (is_array($var)) { + if (isset($var[0], $var[1]) && is_callable($var)) { + return ClassStub::wrapCallable($var); + } + foreach ($var as $k => $v) { + if ($v !== $d = $this->decorateVar($v)) { + $var[$k] = $d; + } + } + + return $var; + } + if (is_string($var)) { + if (isset(self::$stubsCache[$var])) { + return self::$stubsCache[$var]; + } + if (false !== strpos($var, '\\')) { + $c = (false !== $i = strpos($var, '::')) ? substr($var, 0, $i) : $var; + if (class_exists($c, false) || interface_exists($c, false) || trait_exists($c, false)) { + return self::$stubsCache[$var] = new ClassStub($var); + } + } + if (false !== strpos($var, DIRECTORY_SEPARATOR) && false === strpos($var, '://') && false === strpos($var, "\0") && @is_file($var)) { + return self::$stubsCache[$var] = new LinkStub($var); + } + } + + return $var; + } }