mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
fix(IRegistrationContext): Use SimpleContainer in registerService factory
Signed-off-by: provokateurin <kate@provokateurin.de>
This commit is contained in:
parent
615d343d96
commit
e8d4d435ed
5 changed files with 12 additions and 15 deletions
|
|
@ -8,13 +8,15 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace OC\AppFramework\Bootstrap;
|
||||
|
||||
use OC\AppFramework\Utility\SimpleContainer;
|
||||
|
||||
/**
|
||||
* @psalm-immutable
|
||||
*/
|
||||
class ServiceFactoryRegistration extends ARegistration {
|
||||
/**
|
||||
* @var callable
|
||||
* @psalm-var callable(\Psr\Container\ContainerInterface): mixed
|
||||
* @psalm-var callable(SimpleContainer): mixed
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
|
|
@ -36,7 +38,7 @@ class ServiceFactoryRegistration extends ARegistration {
|
|||
}
|
||||
|
||||
/**
|
||||
* @psalm-return callable(\Psr\Container\ContainerInterface): mixed
|
||||
* @psalm-return callable(SimpleContainer): mixed
|
||||
*/
|
||||
public function getFactory(): callable {
|
||||
return $this->factory;
|
||||
|
|
|
|||
|
|
@ -172,15 +172,6 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer {
|
|||
$this[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The given closure is call the first time the given service is queried.
|
||||
* The closure has to return the instance for the given service.
|
||||
* Created instance will be cached in case $shared is true.
|
||||
*
|
||||
* @param string $name name of the service to register another backend for
|
||||
* @param Closure $closure the closure to be called on service creation
|
||||
* @param bool $shared
|
||||
*/
|
||||
public function registerService($name, Closure $closure, $shared = true) {
|
||||
$wrapped = function () use ($closure) {
|
||||
return $closure($this);
|
||||
|
|
|
|||
|
|
@ -958,7 +958,7 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
|
||||
$ini = $c->get(IniGetWrapper::class);
|
||||
$config = $c->get(IConfig::class);
|
||||
$ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
|
||||
$ttl = $config->getSystemValueInt('filelocking.ttl', max(3600, (int)($ini->getNumeric('max_execution_time') ?? 0)));
|
||||
if ($config->getSystemValueBool('filelocking.enabled', true) || (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
|
||||
/** @var Factory $memcacheFactory */
|
||||
$memcacheFactory = $c->get(ICacheFactory::class);
|
||||
|
|
@ -1212,7 +1212,9 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
});
|
||||
|
||||
$this->registerService(ISession::class, function (ContainerInterface $c) {
|
||||
return $c->get(IUserSession::class)->getSession();
|
||||
/** @var Session $session */
|
||||
$session = $c->get(IUserSession::class);
|
||||
return $session->getSession();
|
||||
}, false);
|
||||
|
||||
$this->registerService(IShareHelper::class, function (ContainerInterface $c) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCP\AppFramework\Bootstrap;
|
||||
|
||||
use OC\AppFramework\Utility\SimpleContainer;
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
use OCP\Authentication\TwoFactorAuth\IProvider;
|
||||
use OCP\Calendar\ICalendarProvider;
|
||||
|
|
@ -68,7 +69,7 @@ interface IRegistrationContext {
|
|||
*
|
||||
* @param string $name
|
||||
* @param callable $factory
|
||||
* @psalm-param callable(\Psr\Container\ContainerInterface): mixed $factory
|
||||
* @psalm-param callable(SimpleContainer): mixed $factory
|
||||
* @param bool $shared If set to true the factory result will be cached otherwise every query will call the factory again
|
||||
*
|
||||
* @return void
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
namespace OCP;
|
||||
|
||||
use Closure;
|
||||
use OC\AppFramework\Utility\SimpleContainer;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
|
@ -75,7 +76,7 @@ interface IContainer extends ContainerInterface {
|
|||
* In case the parameter is false the service will be recreated on every call.
|
||||
*
|
||||
* @param string $name
|
||||
* @param \Closure $closure
|
||||
* @param \Closure(SimpleContainer): mixed $closure
|
||||
* @param bool $shared
|
||||
* @return void
|
||||
* @since 6.0.0
|
||||
|
|
|
|||
Loading…
Reference in a new issue