You are here

private function Snapshot::snapshotStaticAttributes in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/sebastian/global-state/src/Snapshot.php \SebastianBergmann\GlobalState\Snapshot::snapshotStaticAttributes()

Creates a snapshot of all static attributes in user-defined classes.

1 call to Snapshot::snapshotStaticAttributes()
Snapshot::__construct in vendor/sebastian/global-state/src/Snapshot.php
Creates a snapshot of the current global state.

File

vendor/sebastian/global-state/src/Snapshot.php, line 374

Class

Snapshot
A snapshot of global state.

Namespace

SebastianBergmann\GlobalState

Code

private function snapshotStaticAttributes() {
  foreach ($this->classes as $className) {
    $class = new ReflectionClass($className);
    $snapshot = array();
    foreach ($class
      ->getProperties() as $attribute) {
      if ($attribute
        ->isStatic()) {
        $name = $attribute
          ->getName();
        if ($this->blacklist
          ->isStaticAttributeBlacklisted($className, $name)) {
          continue;
        }
        $attribute
          ->setAccessible(true);
        $value = $attribute
          ->getValue();
        if ($this
          ->canBeSerialized($value)) {
          $snapshot[$name] = unserialize(serialize($value));
        }
      }
    }
    if (!empty($snapshot)) {
      $this->staticAttributes[$className] = $snapshot;
    }
  }
}