12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace Predis;
- class Autoloader
- {
- private $directory;
- private $prefix;
- private $prefixLength;
-
- public function __construct($baseDirectory = __DIR__)
- {
- $this->directory = $baseDirectory;
- $this->prefix = __NAMESPACE__ . '\\';
- $this->prefixLength = strlen($this->prefix);
- }
-
- public static function register($prepend = false)
- {
- spl_autoload_register(array(new self, 'autoload'), true, $prepend);
- }
-
- public function autoload($className)
- {
- if (0 === strpos($className, $this->prefix)) {
- $parts = explode('\\', substr($className, $this->prefixLength));
- $filepath = $this->directory.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts).'.php';
- if (is_file($filepath)) {
- require($filepath);
- }
- }
- }
- }
|