Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Extension/ExtensionPathResolver.php \Drupal\Core\Extension\ExtensionPathResolver

Factory for getting extension lists by type.

Hierarchy

Expanded class hierarchy of ExtensionPathResolver

4 files declare their use of ExtensionPathResolver
ConfigInstaller.php in core/lib/Drupal/Core/Config/ConfigInstaller.php
ConfigManager.php in core/lib/Drupal/Core/Config/ConfigManager.php
ExtensionPathResolverTest.php in core/tests/Drupal/KernelTests/Core/Bootstrap/ExtensionPathResolverTest.php
LibraryDiscoveryParserTest.php in core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php
1 string reference to 'ExtensionPathResolver'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses ExtensionPathResolver
extension.path.resolver in core/core.services.yml
Drupal\Core\Extension\ExtensionPathResolver

File

core/lib/Drupal/Core/Extension/ExtensionPathResolver.php, line 11

Namespace

Drupal\Core\Extension
View source
class ExtensionPathResolver {

  /**
   * A associative array of ExtensionList objects keyed by type.
   *
   * @var \Drupal\Core\Extension\ExtensionList[]
   */
  protected $extensionLists;

  /**
   * ExtensionPathResolver constructor.
   *
   * @param \Drupal\Core\Extension\ModuleExtensionList $module_extension_list
   *   The module extension list.
   * @param \Drupal\Core\Extension\ProfileExtensionList $profile_extension_list
   *   The profile extension list.
   * @param \Drupal\Core\Extension\ThemeExtensionList $theme_extension_list
   *   The theme extension list.
   * @param \Drupal\Core\Extension\ThemeEngineExtensionList $theme_engine_extension_list
   *   The theme engine extension list.
   */
  public function __construct(ModuleExtensionList $module_extension_list, ProfileExtensionList $profile_extension_list, ThemeExtensionList $theme_extension_list, ThemeEngineExtensionList $theme_engine_extension_list) {
    $this->extensionLists['module'] = $module_extension_list;
    $this->extensionLists['profile'] = $profile_extension_list;
    $this->extensionLists['theme'] = $theme_extension_list;
    $this->extensionLists['theme_engine'] = $theme_engine_extension_list;
  }

  /**
   * Gets the info file path for the extension.
   *
   * @param string $type
   *   The extension type.
   * @param string $name
   *   The extension name.
   *
   * @return string|null
   *   The extension path, or NULL if unknown.
   */
  public function getPathname(string $type, string $name) : ?string {
    if ($type === 'core') {
      return 'core/core.info.yml';
    }
    if (!isset($this->extensionLists[$type])) {
      throw new UnknownExtensionTypeException(sprintf('Extension type %s is unknown.', $type));
    }
    try {
      return $this->extensionLists[$type]
        ->getPathname($name);
    } catch (UnknownExtensionException $e) {

      // Catch the exception. This will result in triggering an error.
      // If the filename is still unknown, create a user-level error message.
      trigger_error(sprintf('The following %s is missing from the file system: %s', $type, $name), E_USER_WARNING);
      return NULL;
    }
  }

  /**
   * Gets the extension directory path.
   *
   * @param string $type
   *   The extension type.
   * @param string $name
   *   The extension name.
   *
   * @return string
   *   The extension info file path.
   *
   * @throws \Drupal\Core\Extension\Exception\UnknownExtensionTypeException
   *   If the extension type is unknown.
   * @throws \Drupal\Core\Extension\Exception\UnknownExtensionException
   *   If the extension is unknown.
   */
  public function getPath(string $type, string $name) : string {
    return dirname($this
      ->getPathname($type, $name));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExtensionPathResolver::$extensionLists protected property A associative array of ExtensionList objects keyed by type.
ExtensionPathResolver::getPath public function Gets the extension directory path.
ExtensionPathResolver::getPathname public function Gets the info file path for the extension.
ExtensionPathResolver::__construct public function ExtensionPathResolver constructor.