3 * An implementation of the PSR-0 Autoloader. This can be replaced at will with
4 * other implementations if necessary.
8 * @category PHPCryptLib
10 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
11 * @copyright 2011 The Authors
12 * @license http://www.opensource.org/licenses/mit-license.html MIT License
13 * @version Build @@version@@
16 namespace CryptLib\Core
;
19 * An implementation of the PSR-0 Autoloader. This can be replaced at will with
20 * other implementations if necessary.
22 * @category PHPCryptLib
24 * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
29 * @var string The namespace prefix for this instance.
31 protected $namespace = '';
34 * @var string The filesystem prefix to use for this instance
39 * Build the instance of the autoloader
41 * @param string $namespace The prefixed namespace this instance will load
42 * @param string $path The filesystem path to the root of the namespace
46 public function __construct($namespace, $path) {
47 $this->namespace = ltrim($namespace, '\\');
48 $this->path
= rtrim($path, '/\\') . DIRECTORY_SEPARATOR
;
54 * @param string $class The class name to load
56 * @return boolean If the loading was successful
58 public function load($class) {
59 $class = ltrim($class, '\\');
60 if (strpos($class, $this->namespace) === 0) {
61 $nsparts = explode('\\', $class);
62 $class = array_pop($nsparts);
64 $path = $this->path
. implode(DIRECTORY_SEPARATOR
, $nsparts);
65 $path .= str_replace('_', DIRECTORY_SEPARATOR
, $class) . '.php';
66 if (file_exists($path)) {
75 * Register the autoloader to PHP
77 * @return boolean The status of the registration
79 public function register() {
80 return spl_autoload_register(array($this, 'load'));
84 * Unregister the autoloader to PHP
86 * @return boolean The status of the unregistration
88 public function unregister() {
89 return spl_autoload_unregister(array($this, 'load'));