DependencySerializationTrait.php in Zircon Profile 8
File
core/lib/Drupal/Core/DependencyInjection/DependencySerializationTrait.php
View source
<?php
namespace Drupal\Core\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerInterface;
trait DependencySerializationTrait {
protected $_serviceIds = array();
public function __sleep() {
$this->_serviceIds = array();
$vars = get_object_vars($this);
foreach ($vars as $key => $value) {
if (is_object($value) && isset($value->_serviceId)) {
$this->_serviceIds[$key] = $value->_serviceId;
unset($vars[$key]);
}
elseif ($value instanceof ContainerInterface) {
$this->_serviceIds[$key] = 'service_container';
unset($vars[$key]);
}
}
return array_keys($vars);
}
public function __wakeup() {
$container = \Drupal::getContainer();
foreach ($this->_serviceIds as $key => $service_id) {
$this->{$key} = $container
->get($service_id);
}
$this->_serviceIds = array();
}
}