Avoid container dance for appName

Sicne the appName is always passed for the DIContainer we can avoid
using the container query logic and instead store and use a property

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2022-11-16 18:54:25 +01:00
parent 87e638b1f8
commit d7ecbe32d2
No known key found for this signature in database
GPG key ID: 4C614C6ED2CDE6DF

View file

@ -79,6 +79,7 @@ use Psr\Log\LoggerInterface;
* @deprecated 20.0.0
*/
class DIContainer extends SimpleContainer implements IAppContainer {
private string $appName;
/**
* @var array
@ -94,8 +95,9 @@ class DIContainer extends SimpleContainer implements IAppContainer {
* @param array $urlParams
* @param ServerContainer|null $server
*/
public function __construct($appName, $urlParams = [], ServerContainer $server = null) {
public function __construct(string $appName, array $urlParams = [], ServerContainer $server = null) {
parent::__construct();
$this->appName = $appName;
$this['appName'] = $appName;
$this['urlParams'] = $urlParams;
@ -437,6 +439,9 @@ class DIContainer extends SimpleContainer implements IAppContainer {
}
public function query(string $name, bool $autoload = true) {
if ($name === 'AppName' || $name === 'appName') {
return $this->appName;
}
try {
return $this->queryNoFallback($name);
} catch (QueryException $firstException) {
@ -461,11 +466,11 @@ class DIContainer extends SimpleContainer implements IAppContainer {
if ($this->offsetExists($name)) {
return parent::query($name);
} elseif ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
} elseif ($this->appName === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
return parent::query($name);
} elseif ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
} elseif ($this->appName === 'core' && strpos($name, 'OC\\Core\\') === 0) {
return parent::query($name);
} elseif (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
} elseif (strpos($name, \OC\AppFramework\App::buildAppNamespace($this->appName) . '\\') === 0) {
return parent::query($name);
}