You are here

public function DependencySerializationTrait::__sleep in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php \Drupal\Core\DependencyInjection\DependencySerializationTrait::__sleep()
3 calls to DependencySerializationTrait::__sleep()
Entity::__sleep in core/lib/Drupal/Core/Entity/Entity.php
ForumManager::__sleep in core/modules/forum/src/ForumManager.php
TermStorage::__sleep in core/modules/taxonomy/src/TermStorage.php
1 method overrides DependencySerializationTrait::__sleep()
TermStorage::__sleep in core/modules/taxonomy/src/TermStorage.php

File

core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php, line 27
Contains \Drupal\Core\DependencyInjection\DependencySerializationTrait.

Class

DependencySerializationTrait
Provides dependency injection friendly methods for serialization.

Namespace

Drupal\Core\DependencyInjection

Code

public function __sleep() {
  $this->_serviceIds = array();
  $vars = get_object_vars($this);
  foreach ($vars as $key => $value) {
    if (is_object($value) && isset($value->_serviceId)) {

      // If a class member was instantiated by the dependency injection
      // container, only store its ID so it can be used to get a fresh object
      // on unserialization.
      $this->_serviceIds[$key] = $value->_serviceId;
      unset($vars[$key]);
    }
    elseif ($value instanceof ContainerInterface) {
      $this->_serviceIds[$key] = 'service_container';
      unset($vars[$key]);
    }
  }
  return array_keys($vars);
}