class ExtensionPathResolver in Drupal 10
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Extension/ExtensionPathResolver.php \Drupal\Core\Extension\ExtensionPathResolver
Factory for getting extension lists by type.
Hierarchy
- class \Drupal\Core\Extension\ExtensionPathResolver
Expanded class hierarchy of ExtensionPathResolver
5 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 - LibraryDiscoveryParser.php in core/
lib/ Drupal/ Core/ Asset/ LibraryDiscoveryParser.php - LibraryDiscoveryParserTest.php in core/
tests/ Drupal/ Tests/ Core/ Asset/ LibraryDiscoveryParserTest.php - Contains \Drupal\Tests\Core\Asset\LibraryDiscoveryParserTest.
1 string reference to 'ExtensionPathResolver'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses ExtensionPathResolver
File
- core/
lib/ Drupal/ Core/ Extension/ ExtensionPathResolver.php, line 11
Namespace
Drupal\Core\ExtensionView 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));
}
}