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

Breadcrumb

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

function Restorer::restoreStaticProperties

File

vendor/sebastian/global-state/src/Restorer.php, line 46

Class

Restorer

Namespace

SebastianBergmann\GlobalState

Code

public function restoreStaticProperties(Snapshot $snapshot) : void {
    $current = new Snapshot($snapshot->excludeList(), false, false, false, false, true, false, false, false, false);
    $newClasses = array_diff($current->classes(), $snapshot->classes());
    unset($current);
    foreach ($snapshot->staticProperties() as $className => $staticProperties) {
        foreach ($staticProperties as $name => $value) {
            $reflector = new ReflectionProperty($className, $name);
            $reflector->setValue(null, $value);
        }
    }
    foreach ($newClasses as $className) {
        $class = new ReflectionClass($className);
        $defaults = $class->getDefaultProperties();
        foreach ($class->getProperties() as $property) {
            if (!$property->isStatic()) {
                continue;
            }
            $name = $property->getName();
            if ($snapshot->excludeList()
                ->isStaticPropertyExcluded($className, $name)) {
                continue;
            }
            if (!isset($defaults[$name])) {
                continue;
            }
            $property->setValue(null, $defaults[$name]);
        }
    }
}
RSS feed
Powered by Drupal