diff --git a/core/core.services.yml b/core/core.services.yml index fa58e3bbb9..d7a26aa861 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -503,7 +503,7 @@ services: lazy: true extension.list.module: class: Drupal\Core\Extension\ModuleExtensionList - arguments: ['@app.root', 'module', '@cache.default', '@info_parser', '@module_handler', '@state', '@config.factory', '@extension.list.profile', '%container.modules%', '%install_profile%'] + arguments: ['@app.root', 'module', '@cache.default', '@info_parser', '@module_handler', '@state', '@config.factory', '@extension.list.profile', '%install_profile%', '%container.modules%'] extension.list.profile: class: Drupal\Core\Extension\ProfileExtensionList arguments: ['@app.root', 'profile', '@cache.default', '@info_parser', '@module_handler', '@state', '%install_profile%'] diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 6328f137df..b8e7b1a9a0 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -214,16 +214,16 @@ function drupal_get_filename($type, $name, $filename = NULL) { $extension_list = \Drupal::service($service_id); if (isset($filename)) { // Manually add the info file path of an extension. - $extension_list->setFilename($name, $filename); + $extension_list->setPathname($name, $filename); return; } else { try { - return $extension_list->getFilename($name); + return $extension_list->getPathname($name); } catch (\InvalidArgumentException $e) { // Catch the exception and trigger error to maintain existing behavior. - trigger_error(new FormattableMarkup('The following @type is missing from the file system: @name', array('@type' => $type, '@name' => $name)), E_USER_WARNING); + trigger_error(new FormattableMarkup('The following @type is missing from the file system: @name', ['@type' => $type, '@name' => $name]), E_USER_WARNING); } } } diff --git a/core/lib/Drupal/Core/Extension/ExtensionList.php b/core/lib/Drupal/Core/Extension/ExtensionList.php index 5e3bc921eb..b0b3460f21 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ExtensionList.php @@ -78,7 +78,7 @@ * * @var string[]|null */ - protected $fileNames; + protected $pathNames; /** * A list of extension folder names directly added in code (not discovered). @@ -90,7 +90,7 @@ * * @internal */ - protected $addedFileNames = []; + protected $addedPathNames = []; /** * Static version of the added file names during the installer. @@ -99,7 +99,7 @@ * * @internal */ - protected static $staticAddedFileNames; + protected static $staticAddedPathNames; /** * The state. @@ -160,17 +160,17 @@ public function reset() { $this->cache->delete($this->getListCacheId()); $this->extensionInfo = NULL; $this->cache->delete($this->getInfoCacheId()); - $this->fileNames = NULL; + $this->pathNames = NULL; try { - $this->state->delete($this->getFilenamesCacheId()); + $this->state->delete($this->getPathnamesCacheId()); } catch (\Exception $e) { // Ignore exceptions caused by a non existing {key_value} table in the // early installer. } - $this->cache->delete($this->getFilenamesCacheId()); + $this->cache->delete($this->getPathnamesCacheId()); // We explicitly don't reset the addedFileNames as it is sort of a static // cache. // @todo In the long run it would be great to add the reset, but the early @@ -204,7 +204,7 @@ protected function getInfoCacheId() { * @return string * The filename cache ID. */ - protected function getFilenamesCacheId() { + protected function getPathnamesCacheId() { return "system.{$this->type}.files"; } @@ -410,27 +410,27 @@ protected function recalculateInfo() { } /** - * Returns a list of extension file name keyed by extension machine name. + * Returns a list of extension file paths keyed by extension machine name. * * @return string[] */ - public function getFilenames() { - if ($this->fileNames === NULL) { - $cache_id = $this->getFilenamesCacheId(); + public function getPathnames() { + if ($this->pathNames === NULL) { + $cache_id = $this->getPathnamesCacheId(); if ($cache = $this->cache->get($cache_id)) { - $file_names = $cache->data; + $path_names = $cache->data; } // We use $file_names below. - elseif (!$file_names = $this->state->get($cache_id)) { - $file_names = $this->recalculateFilenames(); + elseif (!$path_names = $this->state->get($cache_id)) { + $path_names = $this->recalculatePathnames(); // Store filenames to allow static::getFilename() to retrieve them // without having to rebuild or scan the filesystem. - $this->state->set($cache_id, $file_names); - $this->cache->set($cache_id, $file_names); + $this->state->set($cache_id, $path_names); + $this->cache->set($cache_id, $path_names); } - $this->fileNames = $file_names; + $this->pathNames = $path_names; } - return $this->fileNames; + return $this->pathNames; } /** @@ -439,7 +439,7 @@ public function getFilenames() { * @return string[] * An array of .info.yml file locations keyed by the extension machine name. */ - protected function recalculateFilenames() { + protected function recalculatePathnames() { $extensions = $this->listExtensions(); ksort($extensions); @@ -449,7 +449,7 @@ protected function recalculateFilenames() { } /** - * Sets the filename for an extension. + * Sets the pathname for an extension. * * This method is used in the Drupal bootstrapping phase, when the extension * system is not fully initialized, to manually set locations of modules and @@ -459,23 +459,23 @@ protected function recalculateFilenames() { * * @param string $extension_name * The name of the extension for which the filename is requested. - * @param string $filename - * The filename of the extension which is to be set explicitly rather + * @param string $pathname + * The pathname of the extension which is to be set explicitly rather * than by consulting the dynamic extension listing. * * @internal * * @see ::getFilename */ - public function setFilename($extension_name, $filename) { - $this->addedFileNames[$extension_name] = $filename; + public function setPathname($extension_name, $pathname) { + $this->addedPathNames[$extension_name] = $pathname; // In the early installer the container is rebuilt multiple times. Therefore // we have to keep the added filenames across those rebuilds. This is not a // final design, but rather just a workaround resolved at some point, // hopefully. if (!empty($GLOBALS['install_state'])) { - static::$staticAddedFileNames[$extension_name] = $filename; + static::$staticAddedPathNames[$extension_name] = $pathname; } } @@ -519,18 +519,18 @@ public function setFilename($extension_name, $filename) { * @throws \InvalidArgumentException * If there is no extension with the supplied name. */ - public function getFilename($extension_name) { - if (isset($this->addedFileNames[$extension_name])) { - return $this->addedFileNames[$extension_name]; + public function getPathname($extension_name) { + if (isset($this->addedPathNames[$extension_name])) { + return $this->addedPathNames[$extension_name]; } - elseif (isset($this->fileNames[$extension_name])) { - return $this->fileNames[$extension_name]; + elseif (isset($this->pathNames[$extension_name])) { + return $this->pathNames[$extension_name]; } - elseif (isset(static::$staticAddedFileNames[$extension_name])) { - return static::$staticAddedFileNames[$extension_name]; + elseif (isset(static::$staticAddedPathNames[$extension_name])) { + return static::$staticAddedPathNames[$extension_name]; } - elseif (($file_names = $this->getFilenames()) && isset($file_names[$extension_name])) { - return $file_names[$extension_name]; + elseif (($path_names = $this->getPathnames()) && isset($path_names[$extension_name])) { + return $path_names[$extension_name]; } throw new \InvalidArgumentException("The {$this->type} $extension_name does not exist."); } @@ -549,7 +549,7 @@ public function getFilename($extension_name) { * If there is no extension with the supplied name. */ public function getPath($extension_name) { - return dirname($this->getFilename($extension_name)); + return dirname($this->getPathname($extension_name)); } } diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index 84c4345f14..5fc30aa2a6 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -56,14 +56,14 @@ class ModuleExtensionList extends ExtensionList { * The state. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. - * @param string $install_profile - * The install profile used by the site. * @param \Drupal\Core\Extension\ExtensionList $profile_list * The site profile listing. + * @param string $install_profile + * The install profile used by the site. * @param array[] $container_modules_info * (optional) The module locations coming from the compiled container. */ - public function __construct($root, $type, CacheBackendInterface $cache, InfoParserInterface $info_parser, ModuleHandlerInterface $module_handler, StateInterface $state, ConfigFactoryInterface $config_factory, $install_profile, ExtensionList $profile_list, array $container_modules_info = []) { + public function __construct($root, $type, CacheBackendInterface $cache, InfoParserInterface $info_parser, ModuleHandlerInterface $module_handler, StateInterface $state, ConfigFactoryInterface $config_factory, ExtensionList $profile_list, $install_profile, array $container_modules_info = []) { parent::__construct($root, $type, $cache, $info_parser, $module_handler, $state, $install_profile); $this->configFactory = $config_factory; @@ -71,7 +71,7 @@ public function __construct($root, $type, CacheBackendInterface $cache, InfoPars // Use the information from the container. This is an optimization. foreach ($container_modules_info as $module_name => $info) { - $this->setFilename($module_name, $info['pathname']); + $this->setPathname($module_name, $info['pathname']); } } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index aa404497ca..2c2c6b6ee5 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -12,7 +12,6 @@ use Drupal\Core\Queue\QueueGarbageCollectionInterface; use Drupal\Core\Database\Query\AlterableInterface; use Drupal\Core\Extension\Extension; -use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory; use Drupal\Core\PageCache\RequestPolicyInterface; @@ -1007,11 +1006,11 @@ function _system_rebuild_module_data_ensure_required($module, &$modules) { * An associative array of module information. * * @deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0. - * Use \Drupal::service(\'extension.list.module\')->reset()->listExtensions() + * Use \Drupal::service('extension.list.module')->reset()->listExtensions() * instead. Note: You probably don't need the reset() method. */ function _system_rebuild_module_data() { - @trigger_error('_system_rebuild_module_data() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \Drupal::service(\'extension.list.module\')->reset()->listExtensions(). See https://www.drupal.org/node/2709919', E_USER_DEPRECATED); + @trigger_error("_system_rebuild_module_data() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \\Drupal::service('extension.list.module')->reset()->listExtensions(). See https://www.drupal.org/node/2709919", E_USER_DEPRECATED); return \Drupal::service('extension.list.module')->reset()->listExtensions(); } @@ -1024,7 +1023,7 @@ function _system_rebuild_module_data() { * @deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0. */ function system_rebuild_module_data() { - @trigger_error('system_rebuild_module_data() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \Drupal::service(\'extension.list.module\')->reset()->listExtensions(). See https://www.drupal.org/node/2709919', E_USER_DEPRECATED); + @trigger_error("system_rebuild_module_data() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \\Drupal::service('extension.list.module')->reset()->listExtensions(). See https://www.drupal.org/node/2709919", E_USER_DEPRECATED); return \Drupal::service('extension.list.module')->reset()->listExtensions(); } diff --git a/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php b/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php index 77f24c163e..c24729c58c 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php @@ -22,16 +22,16 @@ class ExtensionListTest extends UnitTestCase { /** * @covers ::getName - * @expectedException \InvalidArgumentException */ public function testGetNameWithNonExistingExtension() { list($cache, $info_parser, $module_handler, $state) = $this->getMocks(); - $test_extension_list = new TestExtension($this->root, 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal()); + $test_extension_list = new TestExtension($this->root, 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal(), 'testing'); $extension_discovery = $this->prophesize(ExtensionDiscovery::class); $extension_discovery->scan('test_extension')->willReturn([]); $test_extension_list->setExtensionDiscovery($extension_discovery->reveal()); + $this->setExpectedException(\InvalidArgumentException::class); $test_extension_list->getName('test_name'); } @@ -46,16 +46,16 @@ public function testGetName() { /** * @covers ::getExtension - * @expectedException \InvalidArgumentException */ public function testGetExtensionWithNonExistingExtension() { list($cache, $info_parser, $module_handler, $state) = $this->getMocks(); - $test_extension_list = new TestExtension($this->root, 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal()); + $test_extension_list = new TestExtension($this->root, 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal(), 'testing'); $extension_discovery = $this->prophesize(ExtensionDiscovery::class); $extension_discovery->scan('test_extension')->willReturn([]); $test_extension_list->setExtensionDiscovery($extension_discovery->reveal()); + $this->setExpectedException(\InvalidArgumentException::class); $test_extension_list->getExtension('test_name'); } @@ -130,37 +130,37 @@ public function testGetAllInstalledInfo() { } /** - * @covers ::getFilenames + * @covers ::getPathnames */ - public function testGetFilenames() { + public function testGetPathnames() { $test_extension_list = $this->setupTestExtensionList(); - $filenames = $test_extension_list->getFilenames(); + $filenames = $test_extension_list->getPathnames(); $this->assertEquals([ 'test_name' => 'vfs://drupal_root/example/test_name/test_name.info.yml', ], $filenames); } /** - * @covers ::getFilename + * @covers ::getPathname */ - public function testGetFilename() { + public function testGetPathname() { $test_extension_list = $this->setupTestExtensionList(); - $filename = $test_extension_list->getFilename('test_name'); - $this->assertEquals('vfs://drupal_root/example/test_name/test_name.info.yml', $filename); + $pathname = $test_extension_list->getPathname('test_name'); + $this->assertEquals('vfs://drupal_root/example/test_name/test_name.info.yml', $pathname); } /** - * @covers ::setFilename - * @covers ::getFilename + * @covers ::setPathname + * @covers ::getPathname */ - public function testSetFilename() { + public function testSetPathname() { $test_extension_list = $this->setupTestExtensionList(); - $test_extension_list->setFilename('test_name', 'vfs://drupal_root/example2/test_name/test_name.info.yml'); - $this->assertEquals('vfs://drupal_root/example2/test_name/test_name.info.yml', $test_extension_list->getFilename('test_name')); + $test_extension_list->setPathname('test_name', 'vfs://drupal_root/example2/test_name/test_name.info.yml'); + $this->assertEquals('vfs://drupal_root/example2/test_name/test_name.info.yml', $test_extension_list->getPathname('test_name')); } /** @@ -197,7 +197,7 @@ protected function setupTestExtensionList($extension_names = ['test_name']) { return Yaml::decode(file_get_contents($args[0])); }); - $test_extension_list = new TestExtension('vfs://drupal_root', 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal()); + $test_extension_list = new TestExtension('vfs://drupal_root', 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal(), 'testing'); $extension_discovery = $this->prophesize(ExtensionDiscovery::class); $extension_scan_result = []; diff --git a/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php b/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php index 0e575a07ec..f17858cf80 100644 --- a/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php +++ b/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php @@ -42,6 +42,17 @@ public function testSetInitialAccountIdException() { $account_proxy->setInitialAccountId(1); } + /** + * @covers ::hasAccount + */ + public function testHasAccount() { + $account_proxy = new AccountProxy(); + $this->assertFalse($account_proxy->hasAccount()); + + $account_proxy->getAccount(); + $this->assertTrue($account_proxy->hasAccount()); + } + } namespace Drupal\Core\Session;