Make DI work for all apps

As stated in https://github.com/nextcloud/server/pull/3901#issuecomment-288135309
appid's don't have to match the namespace.

Work around this

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-03-21 20:53:37 +01:00
parent d2b1b02244
commit 67909cf87b
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 13 additions and 6 deletions

View File

@ -373,21 +373,28 @@ class DIContainer extends SimpleContainer implements IAppContainer {
});
}
private function getFallbackNamespace($name) {
$segments = explode('\\', $name);
if (count($segments) >= 2) {
return $segments[0] . '\\' . ucfirst(strtolower($segments[1]));
} else {
return null;
}
}
public function query($name) {
$name = $this->sanitizeName($name);
if ($this->offsetExists($name)) {
return parent::query($name);
} else {
if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) {
$segments = explode('\\', $name);
if (strtolower($segments[1]) === strtolower($this['AppName'])) {
return parent::query($name);
}
} else if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
return parent::query($name);
} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
return parent::query($name);
} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName'])) === 0 ||
$this->getFallbackNamespace($name) === \OC\AppFramework\App::buildAppNamespace($this['AppName'])) {
return parent::query($name);
}
}