Last active
October 4, 2017 22:14
-
-
Save paulofreitas/4bf6bb93338052494a94fa933cbb4b7e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function namespace_path($namespace) | |
{ | |
try { | |
return (new ReflectionClass($namespace))->getFileName(); | |
} catch (ReflectionException $e) { | |
$autoloader = require base_path('vendor/autoload.php'); | |
$namespaceParts = array_filter(explode('\\', $namespace)); | |
$namespacePrefix = array_shift($namespaceParts) . '\\'; | |
if ($namespacePrefixMapping = array_get($autoloader->getPrefixesPsr4(), $namespacePrefix)) { | |
return realpath(array_shift($namespacePrefixMapping)) | |
. DIRECTORY_SEPARATOR | |
. implode(DIRECTORY_SEPARATOR, $namespaceParts); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment