123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace Predis;
- class Autoloader
- {
- private $baseDir;
- private $prefix;
-
- public function __construct($baseDirectory = null)
- {
- $this->baseDir = $baseDirectory ?: dirname(__FILE__);
- $this->prefix = __NAMESPACE__ . '\\';
- }
-
- public static function register()
- {
- spl_autoload_register(array(new self, 'autoload'));
- }
-
- public function autoload($className)
- {
- if (0 !== strpos($className, $this->prefix)) {
- return;
- }
- $relativeClassName = substr($className, strlen($this->prefix));
- $classNameParts = explode('\\', $relativeClassName);
- require_once $this->baseDir.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $classNameParts).'.php';
- }
- }
|