diff --git a/build/rector.php b/build/rector.php index 1cc613499c6..a119d84fd59 100644 --- a/build/rector.php +++ b/build/rector.php @@ -52,6 +52,7 @@ class NextcloudNamespaceSkipVoter implements ClassNameImportSkipVoterInterface { $config = RectorConfig::configure() ->withPaths([ $nextcloudDir . '/apps', + $nextcloudDir . '/status.php', // $nextcloudDir . '/config', // $nextcloudDir . '/core', // $nextcloudDir . '/lib', diff --git a/lib/autoloader.php b/lib/autoloader.php index 41b272a457c..7084eb93c89 100644 --- a/lib/autoloader.php +++ b/lib/autoloader.php @@ -22,10 +22,8 @@ class Autoloader { /** * Optional low-latency memory cache for class to path mapping. - * - * @var \OC\Memcache\Cache */ - protected $memoryCache; + protected ?ICache $memoryCache = null; /** * Autoloader constructor. @@ -127,15 +125,15 @@ class Autoloader { * @throws AutoloadNotAllowedException */ public function load(string $class): bool { + if (class_exists($class, false)) { + return false; + } + $pathsToRequire = null; if ($this->memoryCache) { $pathsToRequire = $this->memoryCache->get($class); } - if (class_exists($class, false)) { - return false; - } - if (!is_array($pathsToRequire)) { // No cache or cache miss $pathsToRequire = []; diff --git a/lib/base.php b/lib/base.php index aa463e206a3..e9fdd48f90c 100644 --- a/lib/base.php +++ b/lib/base.php @@ -188,8 +188,6 @@ class OC { } public static function checkConfig(): void { - $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); - // Create config if it does not already exist $configFilePath = self::$configDir . '/config.php'; if (!file_exists($configFilePath)) { @@ -201,6 +199,7 @@ class OC { if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled() || !$configFileWritable && \OCP\Util::needUpgrade()) { $urlGenerator = Server::get(IURLGenerator::class); + $l = Server::get(\OCP\L10N\IFactory::class)->get('lib'); if (self::$CLI) { echo $l->t('Cannot write into "config" directory!') . "\n"; @@ -711,6 +710,7 @@ class OC { self::performSameSiteCookieProtection($config); if (!defined('OC_CONSOLE')) { + $eventLogger->start('check_server', 'Run a few configuration checks'); $errors = OC_Util::checkServer($systemConfig); if (count($errors) > 0) { if (!self::$CLI) { @@ -745,6 +745,7 @@ class OC { } elseif (self::$CLI && $config->getSystemValueBool('installed', false)) { $config->deleteAppValue('core', 'cronErrors'); } + $eventLogger->end('check_server'); } // User and Groups @@ -752,6 +753,7 @@ class OC { self::$server->getSession()->set('user_id', ''); } + $eventLogger->start('setup_backends', 'Setup group and user backends'); Server::get(\OCP\IUserManager::class)->registerBackend(new \OC\User\Database()); Server::get(\OCP\IGroupManager::class)->addBackend(new \OC\Group\Database()); @@ -770,6 +772,7 @@ class OC { // Run upgrades in incognito mode OC_User::setIncognitoMode(true); } + $eventLogger->end('setup_backends'); self::registerCleanupHooks($systemConfig); self::registerShareHooks($systemConfig); diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php index 2b04d291730..260f54ecfcc 100644 --- a/lib/private/AppFramework/Bootstrap/Coordinator.php +++ b/lib/private/AppFramework/Bootstrap/Coordinator.php @@ -83,10 +83,10 @@ class Coordinator { $appNameSpace = App::buildAppNamespace($appId); $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; try { - if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) { + if (class_exists($applicationClassName) && is_a($applicationClassName, IBootstrap::class, true)) { $this->eventLogger->start("bootstrap:register_app:$appId:application", "Load `Application` instance for $appId"); try { - /** @var IBootstrap|App $application */ + /** @var IBootstrap&App $application */ $apps[$appId] = $application = $this->serverContainer->query($applicationClassName); } catch (QueryException $e) { // Weird, but ok diff --git a/lib/private/AppFramework/Utility/SimpleContainer.php b/lib/private/AppFramework/Utility/SimpleContainer.php index 24918992ea3..9af65a37ab8 100644 --- a/lib/private/AppFramework/Utility/SimpleContainer.php +++ b/lib/private/AppFramework/Utility/SimpleContainer.php @@ -153,13 +153,13 @@ class SimpleContainer implements ArrayAccess, ContainerInterface, IContainer { return $closure($this); }; $name = $this->sanitizeName($name); - if (isset($this[$name])) { - unset($this[$name]); + if (isset($this->container[$name])) { + unset($this->container[$name]); } if ($shared) { - $this[$name] = $wrapped; + $this->container[$name] = $wrapped; } else { - $this[$name] = $this->container->factory($wrapped); + $this->container[$name] = $this->container->factory($wrapped); } } diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php index d073132516d..2a60287254b 100644 --- a/lib/private/Route/Router.php +++ b/lib/private/Route/Router.php @@ -54,9 +54,9 @@ class Router implements IRouter { protected LoggerInterface $logger, IRequest $request, private IConfig $config, - private IEventLogger $eventLogger, + protected IEventLogger $eventLogger, private ContainerInterface $container, - private IAppManager $appManager, + protected IAppManager $appManager, ) { $baseUrl = \OC::$WEBROOT; if (!($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { @@ -116,9 +116,11 @@ class Router implements IRouter { $this->loaded = true; $routingFiles = $this->getRoutingFiles(); + $this->eventLogger->start('route:load:attributes', 'Loading Routes from attributes'); foreach (\OC_App::getEnabledApps() as $enabledApp) { $this->loadAttributeRoutes($enabledApp); } + $this->eventLogger->end('route:load:attributes'); } else { if (isset($this->loadedApps[$app])) { return; @@ -140,6 +142,7 @@ class Router implements IRouter { } } + $this->eventLogger->start('route:load:files', 'Loading Routes from files'); foreach ($routingFiles as $app => $file) { if (!isset($this->loadedApps[$app])) { if (!$this->appManager->isAppLoaded($app)) { @@ -160,6 +163,7 @@ class Router implements IRouter { $this->root->addCollection($collection); } } + $this->eventLogger->end('route:load:files'); if (!isset($this->loadedApps['core'])) { $this->loadedApps['core'] = true; @@ -265,6 +269,7 @@ class Router implements IRouter { $this->loadRoutes(); } + $this->eventLogger->start('route:url:match', 'Symfony url matcher call'); $matcher = new UrlMatcher($this->root, $this->context); try { $parameters = $matcher->match($url); @@ -283,6 +288,7 @@ class Router implements IRouter { throw $e; } } + $this->eventLogger->end('route:url:match'); $this->eventLogger->end('route:match'); return $parameters; diff --git a/lib/private/ServerContainer.php b/lib/private/ServerContainer.php index 9f887b2d48a..b5bcbdaeb6f 100644 --- a/lib/private/ServerContainer.php +++ b/lib/private/ServerContainer.php @@ -128,18 +128,17 @@ class ServerContainer extends SimpleContainer { } catch (QueryException $e) { // Continue with general autoloading then } - } - - // In case the service starts with OCA\ we try to find the service in - // the apps container first. - if (($appContainer = $this->getAppContainerForService($name)) !== null) { - try { - return $appContainer->queryNoFallback($name); - } catch (QueryException $e) { - // Didn't find the service or the respective app container - // In this case the service won't be part of the core container, - // so we can throw directly - throw $e; + // In case the service starts with OCA\ we try to find the service in + // the apps container first. + if (($appContainer = $this->getAppContainerForService($name)) !== null) { + try { + return $appContainer->queryNoFallback($name); + } catch (QueryException $e) { + // Didn't find the service or the respective app container + // In this case the service won't be part of the core container, + // so we can throw directly + throw $e; + } } } elseif (str_starts_with($name, 'OC\\Settings\\') && substr_count($name, '\\') >= 3) { $segments = explode('\\', $name); diff --git a/status.php b/status.php index e4d4bab7e45..e1b95d9396b 100644 --- a/status.php +++ b/status.php @@ -1,33 +1,42 @@ getSystemConfig(); + $systemConfig = Server::get(SystemConfig::class); $installed = (bool)$systemConfig->getValue('installed', false); $maintenance = (bool)$systemConfig->getValue('maintenance', false); # see core/lib/private/legacy/defaults.php and core/themes/example/defaults.php # for description and defaults - $defaults = new \OCP\Defaults(); + $defaults = new Defaults(); + $serverVersion = Server::get(ServerVersion::class); $values = [ 'installed' => $installed, 'maintenance' => $maintenance, - 'needsDbUpgrade' => \OCP\Util::needUpgrade(), - 'version' => implode('.', \OCP\Util::getVersion()), - 'versionstring' => \OCP\Server::get(\OCP\ServerVersion::class)->getVersionString(), + 'needsDbUpgrade' => Util::needUpgrade(), + 'version' => implode('.', $serverVersion->getVersion()), + 'versionstring' => $serverVersion->getVersionString(), 'edition' => '', 'productname' => $defaults->getProductName(), - 'extendedSupport' => \OCP\Util::hasExtendedSupport() + 'extendedSupport' => Util::hasExtendedSupport() ]; if (OC::$CLI) { print_r($values); @@ -38,5 +47,5 @@ try { } } catch (Exception $ex) { http_response_code(500); - \OCP\Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'remote','exception' => $ex]); + Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'remote','exception' => $ex]); }