Do not try to autoload built in types
This avoids calls to the autoloader (or chain of autoloaders) to see if for example 'principalPrefix' class can be found. While we already know it is a string. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
05058b0135
commit
357263a70b
|
@ -80,12 +80,12 @@ class PluginManagerTest extends TestCase {
|
||||||
|
|
||||||
$server->method('query')
|
$server->method('query')
|
||||||
->will($this->returnValueMap([
|
->will($this->returnValueMap([
|
||||||
['\OCA\DAV\ADavApp\PluginOne', 'dummyplugin1'],
|
['\OCA\DAV\ADavApp\PluginOne', true, 'dummyplugin1'],
|
||||||
['\OCA\DAV\ADavApp\PluginTwo', 'dummyplugin2'],
|
['\OCA\DAV\ADavApp\PluginTwo', true, 'dummyplugin2'],
|
||||||
['\OCA\DAV\ADavApp\CollectionOne', 'dummycollection1'],
|
['\OCA\DAV\ADavApp\CollectionOne', true, 'dummycollection1'],
|
||||||
['\OCA\DAV\ADavApp\CollectionTwo', 'dummycollection2'],
|
['\OCA\DAV\ADavApp\CollectionTwo', true, 'dummycollection2'],
|
||||||
['\OCA\DAV\ADavApp2\PluginOne', 'dummy2plugin1'],
|
['\OCA\DAV\ADavApp2\PluginOne', true, 'dummy2plugin1'],
|
||||||
['\OCA\DAV\ADavApp2\CollectionOne', 'dummy2collection1'],
|
['\OCA\DAV\ADavApp2\CollectionOne', true, 'dummy2collection1'],
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$expectedPlugins = [
|
$expectedPlugins = [
|
||||||
|
|
|
@ -374,17 +374,12 @@ class DIContainer extends SimpleContainer implements IAppContainer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function query(string $name, bool $autoload = true) {
|
||||||
* @param string $name
|
|
||||||
* @return mixed
|
|
||||||
* @throws QueryException if the query could not be resolved
|
|
||||||
*/
|
|
||||||
public function query($name) {
|
|
||||||
try {
|
try {
|
||||||
return $this->queryNoFallback($name);
|
return $this->queryNoFallback($name);
|
||||||
} catch (QueryException $firstException) {
|
} catch (QueryException $firstException) {
|
||||||
try {
|
try {
|
||||||
return $this->getServer()->query($name);
|
return $this->getServer()->query($name, $autoload);
|
||||||
} catch (QueryException $secondException) {
|
} catch (QueryException $secondException) {
|
||||||
if ($firstException->getCode() === 1) {
|
if ($firstException->getCode() === 1) {
|
||||||
throw $secondException;
|
throw $secondException;
|
||||||
|
|
|
@ -65,7 +65,8 @@ class SimpleContainer extends Container implements IContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$parameters[] = $this->query($resolveName);
|
$builtIn = $parameter->hasType() && $parameter->getType()->isBuiltin();
|
||||||
|
$parameters[] = $this->query($resolveName, !$builtIn);
|
||||||
} catch (QueryException $e) {
|
} catch (QueryException $e) {
|
||||||
// Service not found, use the default value when available
|
// Service not found, use the default value when available
|
||||||
if ($parameter->isDefaultValueAvailable()) {
|
if ($parameter->isDefaultValueAvailable()) {
|
||||||
|
@ -105,23 +106,18 @@ class SimpleContainer extends Container implements IContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function query(string $name, bool $autoload = true) {
|
||||||
/**
|
|
||||||
* @param string $name name of the service to query for
|
|
||||||
* @return mixed registered service for the given $name
|
|
||||||
* @throws QueryException if the query could not be resolved
|
|
||||||
*/
|
|
||||||
public function query($name) {
|
|
||||||
$name = $this->sanitizeName($name);
|
$name = $this->sanitizeName($name);
|
||||||
if ($this->offsetExists($name)) {
|
if ($this->offsetExists($name)) {
|
||||||
return $this->offsetGet($name);
|
return $this->offsetGet($name);
|
||||||
} else {
|
} else if ($autoload) {
|
||||||
$object = $this->resolve($name);
|
$object = $this->resolve($name);
|
||||||
$this->registerService($name, function () use ($object) {
|
$this->registerService($name, function () use ($object) {
|
||||||
return $object;
|
return $object;
|
||||||
});
|
});
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
throw new QueryException('Could not resolve ' . $name . '!');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -113,12 +113,7 @@ class ServerContainer extends SimpleContainer {
|
||||||
throw new QueryException();
|
throw new QueryException();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function query(string $name, bool $autoload = true) {
|
||||||
* @param string $name name of the service to query for
|
|
||||||
* @return mixed registered service for the given $name
|
|
||||||
* @throws QueryException if the query could not be resolved
|
|
||||||
*/
|
|
||||||
public function query($name) {
|
|
||||||
$name = $this->sanitizeName($name);
|
$name = $this->sanitizeName($name);
|
||||||
|
|
||||||
if (isset($this[$name])) {
|
if (isset($this[$name])) {
|
||||||
|
@ -147,6 +142,6 @@ class ServerContainer extends SimpleContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::query($name);
|
return parent::query($name, $autoload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,11 +61,12 @@ interface IContainer {
|
||||||
* Look up a service for a given name in the container.
|
* Look up a service for a given name in the container.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
* @param bool $autoload Should we try to autoload the service. If we are trying to resolve built in types this makes no sense for example
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws QueryException if the query could not be resolved
|
* @throws QueryException if the query could not be resolved
|
||||||
* @since 6.0.0
|
* @since 6.0.0
|
||||||
*/
|
*/
|
||||||
public function query($name);
|
public function query(string $name, bool $autoload = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A value is stored in the container with it's corresponding name
|
* A value is stored in the container with it's corresponding name
|
||||||
|
|
|
@ -81,8 +81,8 @@ class ActionProviderStoreTest extends TestCase {
|
||||||
$this->serverContainer->expects($this->exactly(2))
|
$this->serverContainer->expects($this->exactly(2))
|
||||||
->method('query')
|
->method('query')
|
||||||
->will($this->returnValueMap([
|
->will($this->returnValueMap([
|
||||||
[EMailProvider::class, $provider1],
|
[EMailProvider::class, true, $provider1],
|
||||||
['OCA\Contacts\Provider1', $provider2]
|
['OCA\Contacts\Provider1', true, $provider2]
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$providers = $this->actionProviderStore->getProviders($user);
|
$providers = $this->actionProviderStore->getProviders($user);
|
||||||
|
@ -106,7 +106,7 @@ class ActionProviderStoreTest extends TestCase {
|
||||||
$this->serverContainer->expects($this->once())
|
$this->serverContainer->expects($this->once())
|
||||||
->method('query')
|
->method('query')
|
||||||
->will($this->returnValueMap([
|
->will($this->returnValueMap([
|
||||||
[EMailProvider::class, $provider1],
|
[EMailProvider::class, true, $provider1],
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$providers = $this->actionProviderStore->getProviders($user);
|
$providers = $this->actionProviderStore->getProviders($user);
|
||||||
|
|
Loading…
Reference in New Issue