From 409c455bd1ca6b08e08492a9dc7fa2e39be892d0 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Wed, 26 Feb 2014 12:08:16 +0000 Subject: [PATCH] Encapsulate PSR-0 in \Mibew\Autoloader class --- src/mibew/libs/classes/Mibew/Autoloader.php | 82 +++++++++++++++++++++ src/mibew/libs/common/autoload.php | 39 ---------- src/mibew/libs/init.php | 4 +- 3 files changed, 84 insertions(+), 41 deletions(-) create mode 100644 src/mibew/libs/classes/Mibew/Autoloader.php delete mode 100644 src/mibew/libs/common/autoload.php diff --git a/src/mibew/libs/classes/Mibew/Autoloader.php b/src/mibew/libs/classes/Mibew/Autoloader.php new file mode 100644 index 00000000..db11527e --- /dev/null +++ b/src/mibew/libs/classes/Mibew/Autoloader.php @@ -0,0 +1,82 @@ +basePath . DIRECTORY_SEPARATOR . $file_name + . str_replace('_', DIRECTORY_SEPARATOR, $class_name) . '.php'; + + if (is_file($file_name)) { + include_once($file_name); + } + } + + /** + * Register a new instance as an SPL autoloader. + * + * @param string $base_path Base path for classes-to-files mapping. + * + * @return \Mibew\Autoloader Registered autoloader instance. + */ + public static function register($base_path) + { + $loader = new self($base_path); + spl_autoload_register(array($loader, 'autoload')); + + return $loader; + } + + /** + * Class constructor. + * + * @param string $base_path Base path for classes-to-files mapping. + */ + protected function __construct($base_path) + { + $this->basePath = rtrim($base_path, '/\\'); + } +} diff --git a/src/mibew/libs/common/autoload.php b/src/mibew/libs/common/autoload.php deleted file mode 100644 index 848cff76..00000000 --- a/src/mibew/libs/common/autoload.php +++ /dev/null @@ -1,39 +0,0 @@ -