Passed
Push — master ( 46002a...2f70a2 )
by Morris
12:59 queued 10s
created
lib/private/ServerContainer.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -40,143 +40,143 @@
 block discarded – undo
40 40
  * @package OC
41 41
  */
42 42
 class ServerContainer extends SimpleContainer {
43
-	/** @var DIContainer[] */
44
-	protected $appContainers;
45
-
46
-	/** @var string[] */
47
-	protected $hasNoAppContainer;
48
-
49
-	/** @var string[] */
50
-	protected $namespaces;
51
-
52
-	/**
53
-	 * ServerContainer constructor.
54
-	 */
55
-	public function __construct() {
56
-		parent::__construct();
57
-		$this->appContainers = [];
58
-		$this->namespaces = [];
59
-		$this->hasNoAppContainer = [];
60
-	}
61
-
62
-	/**
63
-	 * @param string $appName
64
-	 * @param string $appNamespace
65
-	 */
66
-	public function registerNamespace(string $appName, string $appNamespace): void {
67
-		// Cut of OCA\ and lowercase
68
-		$appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1));
69
-		$this->namespaces[$appNamespace] = $appName;
70
-	}
71
-
72
-	/**
73
-	 * @param string $appName
74
-	 * @param DIContainer $container
75
-	 */
76
-	public function registerAppContainer(string $appName, DIContainer $container): void {
77
-		$this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container;
78
-	}
79
-
80
-	/**
81
-	 * @param string $appName
82
-	 * @return DIContainer
83
-	 * @throws QueryException
84
-	 */
85
-	public function getRegisteredAppContainer(string $appName): DIContainer {
86
-		if (isset($this->appContainers[strtolower(App::buildAppNamespace($appName, ''))])) {
87
-			return $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))];
88
-		}
89
-
90
-		throw new QueryException();
91
-	}
92
-
93
-	/**
94
-	 * @param string $namespace
95
-	 * @param string $sensitiveNamespace
96
-	 * @return DIContainer
97
-	 * @throws QueryException
98
-	 */
99
-	protected function getAppContainer(string $namespace, string $sensitiveNamespace): DIContainer {
100
-		if (isset($this->appContainers[$namespace])) {
101
-			return $this->appContainers[$namespace];
102
-		}
103
-
104
-		if (isset($this->namespaces[$namespace])) {
105
-			if (!isset($this->hasNoAppContainer[$namespace])) {
106
-				$applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application';
107
-				if (class_exists($applicationClassName)) {
108
-					$app = new $applicationClassName();
109
-					if (isset($this->appContainers[$namespace])) {
110
-						$this->appContainers[$namespace]->offsetSet($applicationClassName, $app);
111
-						return $this->appContainers[$namespace];
112
-					}
113
-				}
114
-				$this->hasNoAppContainer[$namespace] = true;
115
-			}
116
-
117
-			return new DIContainer($this->namespaces[$namespace]);
118
-		}
119
-		throw new QueryException();
120
-	}
121
-
122
-	public function has($id, bool $noRecursion = false): bool {
123
-		if (!$noRecursion && ($appContainer = $this->getAppContainerForService($id)) !== null) {
124
-			return $appContainer->has($id);
125
-		}
126
-
127
-		return parent::has($id);
128
-	}
129
-
130
-	/**
131
-	 * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
132
-	 */
133
-	public function query(string $name, bool $autoload = true) {
134
-		$name = $this->sanitizeName($name);
135
-
136
-		try {
137
-			return parent::query($name, false);
138
-		} catch (QueryException $e) {
139
-			// Continue with general autoloading then
140
-		}
141
-
142
-		// In case the service starts with OCA\ we try to find the service in
143
-		// the apps container first.
144
-		if (($appContainer = $this->getAppContainerForService($name)) !== null) {
145
-			try {
146
-				return $appContainer->queryNoFallback($name);
147
-			} catch (QueryException $e) {
148
-				// Didn't find the service or the respective app container,
149
-				// ignore it and fall back to the core container.
150
-			}
151
-		} elseif (strpos($name, 'OC\\Settings\\') === 0 && substr_count($name, '\\') >= 3) {
152
-			$segments = explode('\\', $name);
153
-			try {
154
-				$appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]);
155
-				return $appContainer->queryNoFallback($name);
156
-			} catch (QueryException $e) {
157
-				// Didn't find the service or the respective app container,
158
-				// ignore it and fall back to the core container.
159
-			}
160
-		}
161
-
162
-		return parent::query($name, $autoload);
163
-	}
164
-
165
-	/**
166
-	 * @internal
167
-	 * @param string $id
168
-	 * @return DIContainer|null
169
-	 */
170
-	public function getAppContainerForService(string $id): ?DIContainer {
171
-		if (strpos($id, 'OCA\\') !== 0 || substr_count($id, '\\') < 2) {
172
-			return null;
173
-		}
174
-
175
-		try {
176
-			[,$namespace,] = explode('\\', $id);
177
-			return $this->getAppContainer(strtolower($namespace), $namespace);
178
-		} catch (QueryException $e) {
179
-			return null;
180
-		}
181
-	}
43
+    /** @var DIContainer[] */
44
+    protected $appContainers;
45
+
46
+    /** @var string[] */
47
+    protected $hasNoAppContainer;
48
+
49
+    /** @var string[] */
50
+    protected $namespaces;
51
+
52
+    /**
53
+     * ServerContainer constructor.
54
+     */
55
+    public function __construct() {
56
+        parent::__construct();
57
+        $this->appContainers = [];
58
+        $this->namespaces = [];
59
+        $this->hasNoAppContainer = [];
60
+    }
61
+
62
+    /**
63
+     * @param string $appName
64
+     * @param string $appNamespace
65
+     */
66
+    public function registerNamespace(string $appName, string $appNamespace): void {
67
+        // Cut of OCA\ and lowercase
68
+        $appNamespace = strtolower(substr($appNamespace, strrpos($appNamespace, '\\') + 1));
69
+        $this->namespaces[$appNamespace] = $appName;
70
+    }
71
+
72
+    /**
73
+     * @param string $appName
74
+     * @param DIContainer $container
75
+     */
76
+    public function registerAppContainer(string $appName, DIContainer $container): void {
77
+        $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))] = $container;
78
+    }
79
+
80
+    /**
81
+     * @param string $appName
82
+     * @return DIContainer
83
+     * @throws QueryException
84
+     */
85
+    public function getRegisteredAppContainer(string $appName): DIContainer {
86
+        if (isset($this->appContainers[strtolower(App::buildAppNamespace($appName, ''))])) {
87
+            return $this->appContainers[strtolower(App::buildAppNamespace($appName, ''))];
88
+        }
89
+
90
+        throw new QueryException();
91
+    }
92
+
93
+    /**
94
+     * @param string $namespace
95
+     * @param string $sensitiveNamespace
96
+     * @return DIContainer
97
+     * @throws QueryException
98
+     */
99
+    protected function getAppContainer(string $namespace, string $sensitiveNamespace): DIContainer {
100
+        if (isset($this->appContainers[$namespace])) {
101
+            return $this->appContainers[$namespace];
102
+        }
103
+
104
+        if (isset($this->namespaces[$namespace])) {
105
+            if (!isset($this->hasNoAppContainer[$namespace])) {
106
+                $applicationClassName = 'OCA\\' . $sensitiveNamespace . '\\AppInfo\\Application';
107
+                if (class_exists($applicationClassName)) {
108
+                    $app = new $applicationClassName();
109
+                    if (isset($this->appContainers[$namespace])) {
110
+                        $this->appContainers[$namespace]->offsetSet($applicationClassName, $app);
111
+                        return $this->appContainers[$namespace];
112
+                    }
113
+                }
114
+                $this->hasNoAppContainer[$namespace] = true;
115
+            }
116
+
117
+            return new DIContainer($this->namespaces[$namespace]);
118
+        }
119
+        throw new QueryException();
120
+    }
121
+
122
+    public function has($id, bool $noRecursion = false): bool {
123
+        if (!$noRecursion && ($appContainer = $this->getAppContainerForService($id)) !== null) {
124
+            return $appContainer->has($id);
125
+        }
126
+
127
+        return parent::has($id);
128
+    }
129
+
130
+    /**
131
+     * @deprecated 20.0.0 use \Psr\Container\ContainerInterface::get
132
+     */
133
+    public function query(string $name, bool $autoload = true) {
134
+        $name = $this->sanitizeName($name);
135
+
136
+        try {
137
+            return parent::query($name, false);
138
+        } catch (QueryException $e) {
139
+            // Continue with general autoloading then
140
+        }
141
+
142
+        // In case the service starts with OCA\ we try to find the service in
143
+        // the apps container first.
144
+        if (($appContainer = $this->getAppContainerForService($name)) !== null) {
145
+            try {
146
+                return $appContainer->queryNoFallback($name);
147
+            } catch (QueryException $e) {
148
+                // Didn't find the service or the respective app container,
149
+                // ignore it and fall back to the core container.
150
+            }
151
+        } elseif (strpos($name, 'OC\\Settings\\') === 0 && substr_count($name, '\\') >= 3) {
152
+            $segments = explode('\\', $name);
153
+            try {
154
+                $appContainer = $this->getAppContainer(strtolower($segments[1]), $segments[1]);
155
+                return $appContainer->queryNoFallback($name);
156
+            } catch (QueryException $e) {
157
+                // Didn't find the service or the respective app container,
158
+                // ignore it and fall back to the core container.
159
+            }
160
+        }
161
+
162
+        return parent::query($name, $autoload);
163
+    }
164
+
165
+    /**
166
+     * @internal
167
+     * @param string $id
168
+     * @return DIContainer|null
169
+     */
170
+    public function getAppContainerForService(string $id): ?DIContainer {
171
+        if (strpos($id, 'OCA\\') !== 0 || substr_count($id, '\\') < 2) {
172
+            return null;
173
+        }
174
+
175
+        try {
176
+            [,$namespace,] = explode('\\', $id);
177
+            return $this->getAppContainer(strtolower($namespace), $namespace);
178
+        } catch (QueryException $e) {
179
+            return null;
180
+        }
181
+    }
182 182
 }
Please login to merge, or discard this patch.