fix(IRegistrationContext): Use SimpleContainer in registerService factory

Signed-off-by: provokateurin <kate@provokateurin.de>
This commit is contained in:
provokateurin 2026-02-11 10:35:55 +01:00
parent 615d343d96
commit e8d4d435ed
No known key found for this signature in database
5 changed files with 12 additions and 15 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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) {

View file

@ -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

View file

@ -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