public function DependencySerializationTrait::__sleep in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php \Drupal\Core\DependencyInjection\DependencySerializationTrait::__sleep()
- 10 core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php \Drupal\Core\DependencyInjection\DependencySerializationTrait::__sleep()
4 calls to DependencySerializationTrait::__sleep()
- ContextDefinition::__sleep in core/
lib/ Drupal/ Core/ Plugin/ Context/ ContextDefinition.php - Implements magic __sleep() method.
- EntityBase::__sleep in core/
lib/ Drupal/ Core/ Entity/ EntityBase.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 30
Class
- DependencySerializationTrait
- Provides dependency injection friendly methods for serialization.
Namespace
Drupal\Core\DependencyInjectionCode
public function __sleep() {
$this->_serviceIds = [];
$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]);
}
elseif ($value instanceof EntityStorageInterface) {
// If a class member is an entity storage, only store the entity type ID
// the storage is for so it can be used to get a fresh object on
// unserialization. By doing this we prevent possible memory leaks when
// the storage is serialized when it contains a static cache of entity
// objects and additionally we ensure that we'll not have multiple
// storage objects for the same entity type and therefore prevent
// returning different references for the same entity.
$this->_entityStorages[$key] = $value
->getEntityTypeId();
unset($vars[$key]);
}
}
return array_keys($vars);
}