Added yii\di\Instance::__set_state() method

This commit is contained in:
SilverFire - Dmitry Naumenko
2017-03-01 19:29:30 +02:00
parent aafa574a55
commit bfa2390d5a
3 changed files with 46 additions and 0 deletions

View File

@ -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']);
}
}