diff --git a/core/core.services.yml b/core/core.services.yml index 212a84a..efa4b34 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -475,10 +475,10 @@ services: - { name: service_collector, tag: 'module_install.uninstall_validator', call: addUninstallValidator } arguments: ['@app.root', '@module_handler', '@kernel', '@router.builder'] lazy: true - module_listing: + extension.list.module: class: Drupal\Core\Extension\ModuleExtensionList - arguments: ['@app.root', 'module', '@cache.default', '@info_parser', '@module_handler', '@config.factory', '@profile_listing'] - profile_listing: + arguments: ['@app.root', 'module', '@cache.default', '@info_parser', '@module_handler', '@config.factory', '@extension.list.profile'] + extension.list.profile: class: Drupal\Core\Extension\ProfileExtensionList arguments: ['@app.root', 'profile', '@cache.default', '@info_parser', '@module_handler'] content_uninstall_validator: diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 79c1e10..5f5a19a 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -201,14 +201,17 @@ function drupal_get_filename($type, $name, $filename = NULL) { } if ($type === 'module' || $type === 'profile') { - $service = $type . '_listing'; + $service_id = 'extension.list.' . $type; + /** @var \Drupal\Core\Extension\ExtensionList $extension_list */ + $extension_list = \Drupal::service($service_id); if (isset($filename)) { // Manually add the info file path of an extension. - return \Drupal::service($service)->setFilename($name, $filename); + $extension_list->setFilename($name, $filename); + return; } else { try { - return \Drupal::service($service)->getFilename($name); + return $extension_list->getFilename($name); } catch (\InvalidArgumentException $e) { // Catch the exception and trigger error to maintain existing behavior. diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index a232757..f83bc7c 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -780,9 +780,10 @@ protected function initializeContainer() { if (isset($this->container)) { // Save the id of the currently logged in user. if ($this->container->initialized('current_user')) { + /** @var \Drupal\Core\Session\AccountProxyInterface $current_user */ $current_user = $this->container->get('current_user'); // Ensure to not accidentally initialize the user. - $current_user_id = $current_user->accountIsInitialized() ? $current_user->id() : 0; + $current_user_id = $current_user->hasAccount() ? $current_user->id() : 0; } // If there is a session, close and save it. diff --git a/core/lib/Drupal/Core/Extension/ExtensionList.php b/core/lib/Drupal/Core/Extension/ExtensionList.php index 3d3ed04..925d319 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ExtensionList.php @@ -12,7 +12,7 @@ abstract class ExtensionList { /** - * The type of the extension, either 'module', 'theme' or 'profile'. + * The type of the extension, such as "module" or "theme". * * @var string */ @@ -33,9 +33,9 @@ protected $cache; /** - * Default information added to every extension. + * Default values to be merged into *.info.yml file arrays. * - * @var array + * @var mixed[] */ protected $defaults = []; @@ -54,7 +54,7 @@ protected $moduleHandler; /** - * The static cached extensions. + * The statically cached extensions. * * @var \Drupal\Core\Extension\Extension[] */ @@ -63,7 +63,8 @@ /** * Static caching for extension info. * - * @var array + * @var array[] + * Keys are extension names, and values their info arrays (mixed[]). */ protected $extensionInfo; @@ -128,25 +129,43 @@ protected function getExtensionDiscovery() { */ public function reset() { $this->extensions = NULL; - $this->cache->delete($this->getCacheId()); + $this->cache->delete($this->getListCacheId()); $this->extensionInfo = NULL; - $this->cache->delete("system.{$this->type}.info"); + $this->cache->delete($this->getInfoCacheId()); $this->fileNames = NULL; - $this->cache->delete("system.{$this->type}.files"); + $this->cache->delete($this->getFilenameCacheId()); $this->addedFileNames = NULL; return $this; } /** - * Returns the used cache ID. + * Returns the extension list cache ID. * * @return string */ - protected function getCacheId() { + protected function getListCacheId() { return 'core.extension_listing.' . $this->type; } /** + * Returns the extension info cache ID. + * + * @return string + */ + protected function getInfoCacheId() { + return "system.{$this->type}.info"; + } + + /** + * Returns the extension filenames cache ID. + * + * @return string + */ + protected function getFilenameCacheId() { + return "system.{$this->type}.files"; + } + + /** * Determines if an extension exists in the filesystem. * * @param string $name @@ -205,12 +224,12 @@ public function listExtensions() { if (isset($this->extensions)) { return $this->extensions; } - if ($cache = $this->cache->get($this->getCacheId())) { + if ($cache = $this->cache->get($this->getListCacheId())) { $this->extensions = $cache->data; return $this->extensions; } $extensions = $this->doListExtensions(); - $this->cache->set($this->getCacheId(), $extensions); + $this->cache->set($this->getListCacheId(), $extensions); $this->extensions = $extensions; return $this->extensions; } @@ -266,7 +285,7 @@ protected function doListExtensions() { * The name of an extension whose information shall be returned. If * $name does not exist or is not enabled, an empty array will be returned. * - * @return array + * @return mixed[] * An associative array of extension information. * * @throws \InvalidArgumentException @@ -287,18 +306,19 @@ public function getInfo($name) { * This function returns the contents of the .info.yml file for each installed * extension. * - * @return array + * @return array[] * An associative array of extension information keyed by name. If no * records are available, an empty array is returned. */ public function getAllInfo() { if (!isset($this->extensionInfo)) { - if ($cache = $this->cache->get("system.{$this->type}.info")) { + $cache_key = "system.{$this->type}.info"; + if ($cache = $this->cache->get($cache_key)) { $info = $cache->data; } else { $info = $this->recalculateInfo(); - $this->cache->set("system.{$this->type}.info", $info); + $this->cache->set($cache_key, $info); } $this->extensionInfo = $info; } @@ -311,7 +331,7 @@ public function getAllInfo() { * The information is placed in cache with the "system.{extension_type}.info" * key. * - * @return array + * @return array[] * An array of arrays of .info.yml entries keyed by the extension name. */ protected function recalculateInfo() { @@ -329,12 +349,13 @@ protected function recalculateInfo() { */ public function getFilenames() { if (!isset($this->fileNames)) { - if ($cache = $this->cache->get("system.{$this->type}.files")) { + $cache_id = $this->getFilenameCacheId(); + if ($cache = $this->cache->get($cache_id)) { $file_names = $cache->data; } else { $file_names = $this->recalculateFilenames(); - $this->cache->set("system.{$this->type}.files", $file_names); + $this->cache->set($cache_id, $file_names); } $this->fileNames = $file_names; } diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index a428389..c41a650 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -717,7 +717,7 @@ public function getModuleDirectories() { * {@inheritdoc} */ public function getName($module) { - return \Drupal::service('module_listing')->getName($module); + return \Drupal::service('extension.list.module')->getName($module); } } diff --git a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php index e41b55b..1cc2d35 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php @@ -308,7 +308,7 @@ public function getModuleDirectories(); * in if no matching module is found. * * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. - * Use \Drupal::service('module_listing')->getName() instead. + * Use \Drupal::service('extension.list.module')->getName() instead. */ public function getName($module); diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index ef41a0f..73064ef 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -166,7 +166,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { $module_filenames[$name] = $current_module_filenames[$name]; } else { - $module_path = \Drupal::service('module_listing')->getPath($name); + $module_path = \Drupal::service('extension.list.module')->getPath($name); $pathname = "$module_path/$name.info.yml"; $filename = file_exists($module_path . "/$name.module") ? "$name.module" : NULL; $module_filenames[$name] = new Extension($this->root, 'module', $pathname, $filename); @@ -182,10 +182,10 @@ public function install(array $module_list, $enable_dependencies = TRUE) { $this->moduleHandler->load($module); module_load_install($module); - // Clear the static cache of module_listing to pick up the - // new module, since it merges the installation status of modules into - // its statically cached list. - \Drupal::service('module_listing')->reset(); + // Clear the static cache of the "extension.list.module" service to pick + // up the new module, since it merges the installation status of modules + // into its statically cached list. + \Drupal::service('extension.list.module')->reset(); // Update the kernel to include it. $this->updateKernel($module_filenames); @@ -437,10 +437,10 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { // Remove any potential cache bins provided by the module. $this->removeCacheBins($module); - // Clear the static cache of module_listing to pick up the - // new module, since it merges the installation status of modules into - // its statically cached list. - \Drupal::service('module_listing')->reset(); + // Clear the static cache of the "extension.list.module" service to pick + // up the new module, since it merges the installation status of modules + // into its statically cached list. + \Drupal::service('extension.list.module')->reset(); // Clear plugin manager caches. \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions(); diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php index 63cf9a1..7c48619 100644 --- a/core/lib/Drupal/Core/Session/AccountProxy.php +++ b/core/lib/Drupal/Core/Session/AccountProxy.php @@ -45,7 +45,7 @@ public function setAccount(AccountInterface $account) { /** * {@inheritdoc} */ - public function accountIsInitialized() { + public function hasAccount() { return isset($this->account); } diff --git a/core/lib/Drupal/Core/Session/AccountProxyInterface.php b/core/lib/Drupal/Core/Session/AccountProxyInterface.php index 8969bb2..b7525aa 100644 --- a/core/lib/Drupal/Core/Session/AccountProxyInterface.php +++ b/core/lib/Drupal/Core/Session/AccountProxyInterface.php @@ -6,6 +6,7 @@ * Defines an interface for a service which has the current account stored. * * @ingroup user_api + * @internal */ interface AccountProxyInterface extends AccountInterface { @@ -44,11 +45,11 @@ public function getAccount(); public function setInitialAccountId($account_id); /** - * Returns whether the account is already initialized. + * Checks whether an account is currently wrapped. * * @return bool - * TRUE, when the account was initialized already. + * TRUE, if an account is currently wrapped. FALSE otherwise. */ - public function accountIsInitialized(); + public function hasAccount(); }