diff -u a/core/lib/Drupal/Core/DrupalKernel.php a/core/lib/Drupal/Core/DrupalKernel.php --- a/core/lib/Drupal/Core/DrupalKernel.php +++ a/core/lib/Drupal/Core/DrupalKernel.php @@ -174,7 +174,7 @@ } $this->configStorage = BootstrapConfigStorageFactory::get(); - $this->moduleHandler = ModuleHandlerFactory::create($this->configStorage); + $this->moduleHandler = ModuleHandlerFactory::get($this->configStorage); $this->initializeContainer(); $this->booted = TRUE; if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, static::CONTAINER_BASE_CLASS)) { @@ -280,10 +280,11 @@ * changes. */ public function rebuildContainer() { - // If we haven't yet booted, we don't need to do anything. If we have already - // booted, then reboot in order to refresh the bundle list and container. + // If we haven't yet booted, we don't need to do anything. If we have + // already booted, then reboot in order to refresh the bundle list and + // container. if ($this->booted) { - $this->moduleHandler = ModuleHandlerFactory::create($this->configStorage); + $this->moduleHandler = ModuleHandlerFactory::get($this->configStorage); $this->initializeContainer(TRUE); } } @@ -575,6 +576,9 @@ /** * Registers a list of namespaces. + * + * @param array $namespaces + * An array of namespaces.to register. */ protected function registerNamespaces(array $namespaces = array()) { foreach ($namespaces as $prefix => $path) { @@ -583,8 +587,14 @@ } /** - * @param $class - * @param $persist + * Initializes the cached container. + * + * @param string $class + * The classname of the cached container. + * @param bool $persist + * Whether or not to persist the cached container. + * @return ContainerInterface + * The cached container. */ protected function initializeCachedContainer($class, $persist) { $container = NULL; diff -u a/core/lib/Drupal/Core/Extension/ModuleHandler.php a/core/lib/Drupal/Core/Extension/ModuleHandler.php --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ a/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -64,8 +64,6 @@ */ protected $alterFunctions; - protected $moduleData; - /** * Constructs a ModuleHandler object. * @@ -142,40 +140,51 @@ $this->resetImplementations(); } + /** + * Returns the file name for each enabled module. + * + * @return array + * An array of module names. + */ public function getModuleNames() { return array_keys($this->moduleList); } /** * Returns the file name for each enabled module. + * + * @return array + * An array of module filenames. */ public function getModuleFileNames() { return array_values($this->moduleList); } + /** + * Returns the file name for a given enabled module. + * + * @return string + * The module's filename. + */ public function getModuleFileName($module) { return $this->moduleList[$module]; } - public function getModuleDirectory($module) { - return dirname($this->moduleList[$module]); - } - /** - * Returns the file name for each enabled module. + * Returns the directory name for a given enabled module. + * + * @return string + * The module's directory name. */ - public function findModuleFileNames($module_list) { - $filenames = array(); - foreach ($module_list as $module => $weight) { - if ($data = $this->moduleData($module, $module_list)) { - $filenames[$module] = $data->uri; - } - } - return $filenames; + public function getModuleDirectory($module) { + return dirname($this->moduleList[$module]); } /** * Gets the namespaces of each enabled module. + * + * @return array + * An array of module namespaces. */ public function getModuleNamespaces() { $namespaces = array(); diff -u a/core/lib/Drupal/Core/Extension/ModuleHandlerFactory.php a/core/lib/Drupal/Core/Extension/ModuleHandlerFactory.php --- a/core/lib/Drupal/Core/Extension/ModuleHandlerFactory.php +++ a/core/lib/Drupal/Core/Extension/ModuleHandlerFactory.php @@ -10,19 +10,51 @@ use Drupal\Core\Config\StorageInterface; use Drupal\Core\SystemListing; +/** + * A factory for ModuleHandler that is responsible for finding both available + * and enabled modules. + */ class ModuleHandlerFactory { + + /** + * A cache to hold module data once it's been built. + * + * @var array + */ protected $moduleData; + /** + * An constructor. + * + * @param StorageInterface + * A config storage object. + */ public function __construct(StorageInterface $config_storage) { $this->configStorage = $config_storage; } - public static function create(StorageInterface $config_storage) { + /** + * A static shortcut to encapsulate the instantiation of the factory as well + * as creating the ModuleHandler. + * + * @param StorageInterface + * A config storage object. + * @return ModuleHandler + * A module handler. + */ + public static function get(StorageInterface $config_storage) { $factory = new static($config_storage); - return $factory->get(); + return $factory->create(); } - public function get() { + /** + * Factory method that finds available/enabled modules and instantiates a + * new ModuleHandler. + * + * @return ModuleHandler + * An instance of ModuleHandler. + */ + public function create() { $module_info = $this->configStorage->read('system.module'); $enabled_modules = isset($module_info['enabled']) ? $module_info['enabled'] : array(); $module_list = $this->findFileNames($enabled_modules); @@ -31,6 +63,12 @@ /** * Returns the file name for each enabled module. + * + * @param array $module_list + * An associative array of modules where keys are module names and values + * are weight. + * @return array + * An array of module filenames. */ public function findFileNames($module_list) { $filenames = array(); @@ -47,7 +85,9 @@ * * @param $module * The name of the module. - * + * @param array $module_list + * An associative array of modules where keys are module names and values + * are weight. * @return \stdClass|bool * Returns a stdClass object if the module data is found containing at * least an uri property with the module path, for example @@ -60,6 +100,13 @@ return isset($this->moduleData[$module]) ? $this->moduleData[$module] : FALSE; } + /** + * Builds moduleData cache by scanning the filesystem. + * + * @param array $module_list + * An associative array of modules where keys are module names and values + * are weight. + */ protected function buildModuleData($module_list) { // First, find profiles. $profiles_scanner = new SystemListing(); diff -u a/core/modules/simpletest/lib/Drupal/simpletest/ConfigMemoryStorage.php a/core/modules/simpletest/lib/Drupal/simpletest/ConfigMemoryStorage.php --- a/core/modules/simpletest/lib/Drupal/simpletest/ConfigMemoryStorage.php +++ a/core/modules/simpletest/lib/Drupal/simpletest/ConfigMemoryStorage.php @@ -6,6 +6,11 @@ class ConfigMemoryStorage implements StorageInterface { + /** + * The module list that will be returned to the module handler. + * + * @var array + */ protected $moduleList; /** diff -u a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -64,6 +64,11 @@ */ protected $keyValueFactory; + /** + * An instance of ConfigMemoryStorage. + * + * @var ConfigMemoryStorage + */ protected $bootstrapConfig; /** @@ -133,6 +138,12 @@ \Drupal::config('system.theme')->set('default', 'stark'); } + /** + * Getter for $bootstrapConfig. + * + * @return ConfigMemoryStorage + * An instance of ConfigMemoryStorage. + */ public function getBootstrapConfig() { return $this->bootstrapConfig; }