@@ -34,105 +34,105 @@ |
||
| 34 | 34 | * @package OC |
| 35 | 35 | */ |
| 36 | 36 | class ServerContainer extends SimpleContainer { |
| 37 | - /** @var DIContainer[] */ |
|
| 38 | - protected $appContainers; |
|
| 39 | - |
|
| 40 | - /** @var string[] */ |
|
| 41 | - protected $hasNoAppContainer; |
|
| 42 | - |
|
| 43 | - /** @var string[] */ |
|
| 44 | - protected $namespaces; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * ServerContainer constructor. |
|
| 48 | - */ |
|
| 49 | - public function __construct() { |
|
| 50 | - parent::__construct(); |
|
| 51 | - $this->appContainers = []; |
|
| 52 | - $this->namespaces = []; |
|
| 53 | - $this->hasNoAppContainer = []; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param string $appName |
|
| 58 | - * @param string $appNamespace |
|
| 59 | - */ |
|
| 60 | - public function registerNamespace($appName, $appNamespace) { |
|
| 61 | - // Cut of OCA\ and lowercase |
|
| 62 | - $appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1)); |
|
| 63 | - $this->namespaces[$appNamespace] = $appName; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param string $appName |
|
| 68 | - * @param DIContainer $container |
|
| 69 | - */ |
|
| 70 | - public function registerAppContainer($appName, DIContainer $container) { |
|
| 71 | - $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param string $namespace |
|
| 76 | - * @param string $sensitiveNamespace |
|
| 77 | - * @return DIContainer |
|
| 78 | - * @throws QueryException |
|
| 79 | - */ |
|
| 80 | - protected function getAppContainer($namespace, $sensitiveNamespace) { |
|
| 81 | - if (isset($this->appContainers[$namespace])) { |
|
| 82 | - return $this->appContainers[$namespace]; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if (isset($this->namespaces[$namespace])) { |
|
| 86 | - if (!isset($this->hasNoAppContainer[$namespace])) { |
|
| 87 | - $applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application'; |
|
| 88 | - if (class_exists($applicationClassName)) { |
|
| 89 | - new $applicationClassName(); |
|
| 90 | - if (isset($this->appContainers[$namespace])) { |
|
| 91 | - return $this->appContainers[$namespace]; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - $this->hasNoAppContainer[$namespace] = true; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return new DIContainer($this->namespaces[$namespace]); |
|
| 98 | - } |
|
| 99 | - throw new QueryException(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param string $name name of the service to query for |
|
| 104 | - * @return mixed registered service for the given $name |
|
| 105 | - * @throws QueryException if the query could not be resolved |
|
| 106 | - */ |
|
| 107 | - public function query($name) { |
|
| 108 | - $name = $this->sanitizeName($name); |
|
| 109 | - |
|
| 110 | - if (isset($this[$name])) { |
|
| 111 | - return $this[$name]; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // In case the service starts with OCA\ we try to find the service in |
|
| 115 | - // the apps container first. |
|
| 116 | - if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 117 | - $segments = explode('\\', $name); |
|
| 118 | - try { |
|
| 119 | - $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]); |
|
| 120 | - return $appContainer->queryNoFallback($name); |
|
| 121 | - } catch (QueryException $e) { |
|
| 122 | - // Didn't find the service or the respective app container, |
|
| 123 | - // ignore it and fall back to the core container. |
|
| 124 | - } |
|
| 125 | - } else if (strpos($name, 'OC\\Settings\\') === 0 && substr_count($name, '\\') >= 3) { |
|
| 126 | - $segments = explode('\\', $name); |
|
| 127 | - try { |
|
| 128 | - $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]); |
|
| 129 | - return $appContainer->queryNoFallback($name); |
|
| 130 | - } catch (QueryException $e) { |
|
| 131 | - // Didn't find the service or the respective app container, |
|
| 132 | - // ignore it and fall back to the core container. |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return parent::query($name); |
|
| 137 | - } |
|
| 37 | + /** @var DIContainer[] */ |
|
| 38 | + protected $appContainers; |
|
| 39 | + |
|
| 40 | + /** @var string[] */ |
|
| 41 | + protected $hasNoAppContainer; |
|
| 42 | + |
|
| 43 | + /** @var string[] */ |
|
| 44 | + protected $namespaces; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * ServerContainer constructor. |
|
| 48 | + */ |
|
| 49 | + public function __construct() { |
|
| 50 | + parent::__construct(); |
|
| 51 | + $this->appContainers = []; |
|
| 52 | + $this->namespaces = []; |
|
| 53 | + $this->hasNoAppContainer = []; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param string $appName |
|
| 58 | + * @param string $appNamespace |
|
| 59 | + */ |
|
| 60 | + public function registerNamespace($appName, $appNamespace) { |
|
| 61 | + // Cut of OCA\ and lowercase |
|
| 62 | + $appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1)); |
|
| 63 | + $this->namespaces[$appNamespace] = $appName; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param string $appName |
|
| 68 | + * @param DIContainer $container |
|
| 69 | + */ |
|
| 70 | + public function registerAppContainer($appName, DIContainer $container) { |
|
| 71 | + $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param string $namespace |
|
| 76 | + * @param string $sensitiveNamespace |
|
| 77 | + * @return DIContainer |
|
| 78 | + * @throws QueryException |
|
| 79 | + */ |
|
| 80 | + protected function getAppContainer($namespace, $sensitiveNamespace) { |
|
| 81 | + if (isset($this->appContainers[$namespace])) { |
|
| 82 | + return $this->appContainers[$namespace]; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if (isset($this->namespaces[$namespace])) { |
|
| 86 | + if (!isset($this->hasNoAppContainer[$namespace])) { |
|
| 87 | + $applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application'; |
|
| 88 | + if (class_exists($applicationClassName)) { |
|
| 89 | + new $applicationClassName(); |
|
| 90 | + if (isset($this->appContainers[$namespace])) { |
|
| 91 | + return $this->appContainers[$namespace]; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + $this->hasNoAppContainer[$namespace] = true; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return new DIContainer($this->namespaces[$namespace]); |
|
| 98 | + } |
|
| 99 | + throw new QueryException(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param string $name name of the service to query for |
|
| 104 | + * @return mixed registered service for the given $name |
|
| 105 | + * @throws QueryException if the query could not be resolved |
|
| 106 | + */ |
|
| 107 | + public function query($name) { |
|
| 108 | + $name = $this->sanitizeName($name); |
|
| 109 | + |
|
| 110 | + if (isset($this[$name])) { |
|
| 111 | + return $this[$name]; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // In case the service starts with OCA\ we try to find the service in |
|
| 115 | + // the apps container first. |
|
| 116 | + if (strpos($name, 'OCA\\') === 0 && substr_count($name, '\\') >= 2) { |
|
| 117 | + $segments = explode('\\', $name); |
|
| 118 | + try { |
|
| 119 | + $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]); |
|
| 120 | + return $appContainer->queryNoFallback($name); |
|
| 121 | + } catch (QueryException $e) { |
|
| 122 | + // Didn't find the service or the respective app container, |
|
| 123 | + // ignore it and fall back to the core container. |
|
| 124 | + } |
|
| 125 | + } else if (strpos($name, 'OC\\Settings\\') === 0 && substr_count($name, '\\') >= 3) { |
|
| 126 | + $segments = explode('\\', $name); |
|
| 127 | + try { |
|
| 128 | + $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]); |
|
| 129 | + return $appContainer->queryNoFallback($name); |
|
| 130 | + } catch (QueryException $e) { |
|
| 131 | + // Didn't find the service or the respective app container, |
|
| 132 | + // ignore it and fall back to the core container. |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return parent::query($name); |
|
| 137 | + } |
|
| 138 | 138 | } |