Merge pull request #3982 from dhensby/pulls/safe-unnesting

Safe unnesting of Config and Injector
This commit is contained in:
Damian Mooyman 2015-06-26 10:08:29 +12:00
commit 8e1da86bf1
2 changed files with 212 additions and 194 deletions

View File

@ -272,7 +272,16 @@ class Injector {
* @return Injector Reference to restored active Injector instance
*/
public static function unnest() {
return self::set_inst(self::$instance->nestedFrom);
if (self::inst()->nestedFrom) {
self::set_inst(self::inst()->nestedFrom);
}
else {
user_error(
"Unable to unnest root Injector, please make sure you don't have mis-matched nest/unnest",
E_USER_WARNING
);
}
return self::inst();
}
/**

View File

@ -237,7 +237,16 @@ class Config {
* @return Config Reference to new active Config instance
*/
public static function unnest() {
return self::set_instance(self::$instance->nestedFrom);
if (self::inst()->nestedFrom) {
self::set_instance(self::inst()->nestedFrom);
}
else {
user_error(
"Unable to unnest root Config, please make sure you don't have mis-matched nest/unnest",
E_USER_WARNING
);
}
return self::inst();
}
/**