[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\HttpKernel\DataCollector; 13 14 use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter; 15 use Symfony\Component\VarDumper\Caster\CutStub; 16 use Symfony\Component\VarDumper\Cloner\ClonerInterface; 17 use Symfony\Component\VarDumper\Cloner\Data; 18 use Symfony\Component\VarDumper\Cloner\Stub; 19 use Symfony\Component\VarDumper\Cloner\VarCloner; 20 21 /** 22 * DataCollector. 23 * 24 * Children of this class must store the collected data in the data property. 25 * 26 * @author Fabien Potencier <fabien@symfony.com> 27 * @author Bernhard Schussek <bschussek@symfony.com> 28 */ 29 abstract class DataCollector implements DataCollectorInterface, \Serializable 30 { 31 /** 32 * @var array|Data 33 */ 34 protected $data = []; 35 36 /** 37 * @var ValueExporter 38 */ 39 private $valueExporter; 40 41 /** 42 * @var ClonerInterface 43 */ 44 private $cloner; 45 46 public function serialize() 47 { 48 $trace = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT, 2); 49 $isCalledFromOverridingMethod = isset($trace[1]['function'], $trace[1]['object']) && 'serialize' === $trace[1]['function'] && $this === $trace[1]['object']; 50 51 return $isCalledFromOverridingMethod ? $this->data : serialize($this->data); 52 } 53 54 public function unserialize($data) 55 { 56 $this->data = \is_array($data) ? $data : unserialize($data); 57 } 58 59 /** 60 * Converts the variable into a serializable Data instance. 61 * 62 * This array can be displayed in the template using 63 * the VarDumper component. 64 * 65 * @param mixed $var 66 * 67 * @return Data 68 */ 69 protected function cloneVar($var) 70 { 71 if ($var instanceof Data) { 72 return $var; 73 } 74 if (null === $this->cloner) { 75 if (class_exists(CutStub::class)) { 76 $this->cloner = new VarCloner(); 77 $this->cloner->setMaxItems(-1); 78 $this->cloner->addCasters($this->getCasters()); 79 } else { 80 @trigger_error(sprintf('Using the %s() method without the VarDumper component is deprecated since Symfony 3.2 and won\'t be supported in 4.0. Install symfony/var-dumper version 3.2 or above.', __METHOD__), \E_USER_DEPRECATED); 81 $this->cloner = false; 82 } 83 } 84 if (false === $this->cloner) { 85 if (null === $this->valueExporter) { 86 $this->valueExporter = new ValueExporter(); 87 } 88 89 return $this->valueExporter->exportValue($var); 90 } 91 92 return $this->cloner->cloneVar($var); 93 } 94 95 /** 96 * Converts a PHP variable to a string. 97 * 98 * @param mixed $var A PHP variable 99 * 100 * @return string The string representation of the variable 101 * 102 * @deprecated since version 3.2, to be removed in 4.0. Use cloneVar() instead. 103 */ 104 protected function varToString($var) 105 { 106 @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.2 and will be removed in 4.0. Use cloneVar() instead.', __METHOD__), \E_USER_DEPRECATED); 107 108 if (null === $this->valueExporter) { 109 $this->valueExporter = new ValueExporter(); 110 } 111 112 return $this->valueExporter->exportValue($var); 113 } 114 115 /** 116 * @return callable[] The casters to add to the cloner 117 */ 118 protected function getCasters() 119 { 120 return [ 121 '*' => function ($v, array $a, Stub $s, $isNested) { 122 if (!$v instanceof Stub) { 123 foreach ($a as $k => $v) { 124 if (\is_object($v) && !$v instanceof \DateTimeInterface && !$v instanceof Stub) { 125 $a[$k] = new CutStub($v); 126 } 127 } 128 } 129 130 return $a; 131 }, 132 ]; 133 } 134 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |