mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 06:15:19 +08:00
Added yii\di\Instance::__set_state()
method
This commit is contained in:
@ -161,4 +161,22 @@ class Instance
|
||||
return Yii::$container->get($this->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores class state after using `var_export()`
|
||||
*
|
||||
* @param array $state
|
||||
* @return Instance
|
||||
* @throws InvalidConfigException when $state property does not contain `id` parameter
|
||||
* @see var_export()
|
||||
* @since 2.0.12
|
||||
*/
|
||||
public static function __set_state($state)
|
||||
{
|
||||
if (!isset($state['id'])) {
|
||||
throw new InvalidConfigException('Failed to instantiate class "Instance". Required parameter "id" is missing');
|
||||
}
|
||||
|
||||
return new self($state['id']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user