From 6a6351a27545bd1410b4df5df7e53da1e9bbc43c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 31 Oct 2020 19:38:51 +0100 Subject: [PATCH] search for include path --- Autoloader.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Autoloader.php b/Autoloader.php index 513720503..d99631e96 100644 --- a/Autoloader.php +++ b/Autoloader.php @@ -34,7 +34,6 @@ final class Autoloader */ private static $paths = [ __DIR__ . '/../', - __DIR__ . '/../../', ]; /** @@ -61,10 +60,34 @@ final class Autoloader self::$paths[] = $path; } + /** + * Find include paths for class + * + * @param string $class Class name + * + * @return array + * + * @since 1.0.0 + */ + public static function findPaths(string $class) : array + { + $found = []; + $class = \ltrim($class, '\\'); + $class = \str_replace(['_', '\\'], '/', $class); + + foreach (self::$paths as $path) { + if (\is_file($file = $path . $class . '.php')) { + $found[] = $file; + } + } + + return $found; + } + /** * Loading classes by namespace + class name. * - * @param string $class Class path + * @param string $class Class name * * @example Autoloader::defaultAutoloader('\phpOMS\Autoloader') // void *