From 89d0363bb81a32032e938da71a19ec959c48e2bf Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Mon, 21 Oct 2024 23:40:45 +0300 Subject: [PATCH] feat: Added a Method to Load Multiple Files --- webfiori/framework/autoload/ClassLoader.php | 22 ++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/webfiori/framework/autoload/ClassLoader.php b/webfiori/framework/autoload/ClassLoader.php index 9cd8f96f..0d1df0df 100644 --- a/webfiori/framework/autoload/ClassLoader.php +++ b/webfiori/framework/autoload/ClassLoader.php @@ -263,15 +263,31 @@ public static function get(array $options = [ * @return bool If file is exist and class is loaded, true is returned. False * otherwise. */ - public static function map(string $className, string $classWithNs, string $path) { - self::get()->addClassMap($className, $classWithNs, $path); + public static function map(string $className, string $classWithNs, string $filePath) { + self::get()->addClassMap($className, $classWithNs, $filePath); + } + /** + * Load multiple classes from same path which belongs to same namespace. + * + * This helper method can be used to autoload classes which are non-PSR-4 compliant. + * + * @param string $ns The namespace at which classes belongs to. + * + * @param string $path The location at which all classes stored at. + * + * @param array $classes An array that holds the names of the classes. + */ + public static function mapAll(string $ns, string $path, array $classes) { + foreach ($classes as $className) { + self::map($className, $ns.'\\'.$className, $path.DIRECTORY_SEPARATOR.$className.'.php'); + } } /** * Load a class using its specified path. * * This method can be used in case the class that the user tries to load does * not comply with PSR-4 standard for placing classes in correct folder - * with correct namespace. + * with correct namespace. Once loaded, it will be added to the cache. * * @param string $className The name of the class that will be loaded. *