Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
*/
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;

Expand All @@ -36,7 +38,7 @@ public function getName(): string {
}

/**
* @psalm-return callable(\Psr\Container\ContainerInterface): mixed
* @psalm-return callable(SimpleContainer): mixed
*/
public function getFactory(): callable {
return $this->factory;
Expand Down
14 changes: 1 addition & 13 deletions lib/private/AppFramework/Utility/SimpleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@
/**
* @template T
* @param class-string<T>|string $id
* @return T|mixed
* @psalm-template S as class-string<T>|string
* @psalm-param S $id
* @psalm-return (S is class-string<T> ? T : mixed)
* @return ($id is class-string<T> ? T : mixed)
*/
public function get(string $id): mixed {
return $this->query($id);
Expand Down Expand Up @@ -126,7 +123,7 @@
public function resolve($name, array $chain = []) {
$baseMsg = 'Could not resolve ' . $name . '!';
try {
$class = new ReflectionClass($name);

Check failure on line 126 in lib/private/AppFramework/Utility/SimpleContainer.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-security

TaintedCallable

lib/private/AppFramework/Utility/SimpleContainer.php:126:33: TaintedCallable: Detected tainted text (see https://psalm.dev/243)
if ($class->isInstantiable()) {
return $this->buildClass($class, $chain);
} else {
Expand Down Expand Up @@ -172,15 +169,6 @@
$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);
Expand Down
6 changes: 4 additions & 2 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ public function __construct(
$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);
Expand Down Expand Up @@ -1212,7 +1212,9 @@ public function __construct(
});

$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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace OCP\AppFramework\Bootstrap;

use OC\AppFramework\Utility\SimpleContainer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed but this is in OC, so using that in OCP is bad :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if it breaks something, then we can revert it 🙈

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It breaks our policy that OCP should not expose OC

use OCP\AppFramework\IAppContainer;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\Calendar\ICalendarProvider;
Expand Down Expand Up @@ -68,7 +69,7 @@ public function registerDashboardWidget(string $widgetClass): void;
*
* @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
Expand Down
3 changes: 2 additions & 1 deletion lib/public/IContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +76,7 @@ public function registerParameter($name, $value);
* 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
Expand Down
Loading