Final Class Yiisoft\Yii\Gii\Helper
| Inheritance | Yiisoft\Yii\Gii\Helper |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| getNamespacePath() | Returns the file path matching the given namespace. | Yiisoft\Yii\Gii\Helper |
Method Details
Returns the file path matching the given namespace.
| public static string getNamespacePath ( string $namespace ) | ||
| $namespace | string |
Namespace. |
| return | string |
File path. |
|---|---|---|
public static function getNamespacePath(string $namespace): string
{
$classLoaderReflection = new ReflectionClass(ClassLoader::class);
$vendorDir = dirname($classLoaderReflection->getFileName(), 2);
$namespaceWithBackSlash = "$namespace\\";
/**
* @psalm-suppress UnresolvableInclude
* @psalm-var array<string, list<string>> $map
*/
$map = require "$vendorDir/composer/autoload_psr4.php";
foreach ($map as $mapNamespace => $mapDirectories) {
if (str_starts_with($namespaceWithBackSlash, trim($mapNamespace, '\\') . '\\')) {
/** @var string $mapDirectory */
$mapDirectory = reset($mapDirectories);
return $mapDirectory . '/' . str_replace('\\', '/', substr($namespace, strlen($mapNamespace)));
}
}
throw new LogicException("Invalid namespace: \"$namespace\".");
}
Signup or Login in order to comment.