Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DataCollector.php

class DataCollector

DataCollector.

Children of this class must store the collected data in the data property.

@author Fabien Potencier <fabien@symfony.com> @author Bernhard Schussek <bschussek@symfony.com>

Hierarchy

  • class \Symfony\Component\HttpKernel\DataCollector\DataCollector implements \Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface

Expanded class hierarchy of DataCollector

4 files declare their use of DataCollector
CommandDataCollector.php in vendor/symfony/console/DataCollector/CommandDataCollector.php
MessageDataCollector.php in vendor/symfony/mailer/DataCollector/MessageDataCollector.php
SerializerDataCollector.php in vendor/symfony/serializer/DataCollector/SerializerDataCollector.php
ValidatorDataCollector.php in vendor/symfony/validator/DataCollector/ValidatorDataCollector.php

File

vendor/symfony/http-kernel/DataCollector/DataCollector.php, line 29

Namespace

Symfony\Component\HttpKernel\DataCollector
View source
abstract class DataCollector implements DataCollectorInterface {
    protected array|Data $data = [];
    private ClonerInterface $cloner;
    
    /**
     * Converts the variable into a serializable Data instance.
     *
     * This array can be displayed in the template using
     * the VarDumper component.
     */
    protected function cloneVar(mixed $var) : Data {
        if ($var instanceof Data) {
            return $var;
        }
        if (!isset($this->cloner)) {
            $this->cloner = new VarCloner();
            $this->cloner
                ->setMaxItems(-1);
            $this->cloner
                ->addCasters($this->getCasters());
        }
        return $this->cloner
            ->cloneVar($var);
    }
    
    /**
     * @return callable[] The casters to add to the cloner
     */
    protected function getCasters() : array {
        return [
            '*' => function ($v, array $a, Stub $s, $isNested) {
                if (!$v instanceof Stub) {
                    $b = $a;
                    foreach ($a as $k => $v) {
                        if (!\is_object($v) || $v instanceof \DateTimeInterface || $v instanceof Stub) {
                            continue;
                        }
                        try {
                            $a[$k] = $s = new CutStub($v);
                            if ($b[$k] === $s) {
                                // we've hit a non-typed reference
                                $a[$k] = $v;
                            }
                        } catch (\TypeError $e) {
                            // we've hit a typed reference
                        }
                    }
                }
                return $a;
            },
        ] + ReflectionCaster::UNSET_CLOSURE_FILE_INFO;
    }
    public function __sleep() : array {
        return [
            'data',
        ];
    }
    public function __wakeup() : void {
    }
    
    /**
     * @internal to prevent implementing \Serializable
     */
    protected final function serialize() : void {
    }
    
    /**
     * @internal to prevent implementing \Serializable
     */
    protected final function unserialize(string $data) : void {
    }
    
    /**
     * @return void
     */
    public function reset() {
        $this->data = [];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
DataCollector::$cloner private property
DataCollector::$data protected property
DataCollector::cloneVar protected function Converts the variable into a serializable Data instance.
DataCollector::getCasters protected function 1
DataCollector::reset public function Overrides ResetInterface::reset 11
DataCollector::serialize final protected function @internal to prevent implementing \Serializable
DataCollector::unserialize final protected function @internal to prevent implementing \Serializable
DataCollector::__sleep public function 1
DataCollector::__wakeup public function 1
DataCollectorInterface::collect public function Collects data for the given Request and Response. 14
DataCollectorInterface::getName public function Returns the name of the collector. 14

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal