forked from ircmaxell/PHP-PasswordLib
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure bootstrap system, add optional autoloader
- Loading branch information
Showing
14 changed files
with
130 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* An implementation of the PSR-0 Autoloader. This can be replaced at will with | ||
* other implementations if necessary. | ||
* | ||
* PHP version 5.3 | ||
* | ||
* @category PHPCryptLib | ||
* @package Core | ||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com> | ||
* @copyright 2011 The Authors | ||
* @license http://www.opensource.org/licenses/mit-license.html MIT License | ||
* @version Build @@version@@ | ||
*/ | ||
|
||
namespace CryptLib\Core; | ||
|
||
/** | ||
* An implementation of the PSR-0 Autoloader. This can be replaced at will with | ||
* other implementations if necessary. | ||
* | ||
* @category PHPCryptLib | ||
* @package Core | ||
* @author Anthony Ferrara <ircmaxell@ircmaxell.com> | ||
*/ | ||
class AutoLoader { | ||
|
||
/** | ||
* @var string The namespace prefix for this instance. | ||
*/ | ||
protected $namespace = ''; | ||
|
||
/** | ||
* @var string The filesystem prefix to use for this instance | ||
*/ | ||
protected $path = ''; | ||
|
||
/** | ||
* Build the instance of the autoloader | ||
* | ||
* @param string $namespace The prefixed namespace this instance will load | ||
* @param string $path The filesystem path to the root of the namespace | ||
* | ||
* @return void | ||
*/ | ||
public function __construct($namespace, $path) { | ||
$this->namespace = ltrim($namespace, '\\'); | ||
$this->path = rtrim($path, '/\\') . DIRECTORY_SEPARATOR; | ||
} | ||
|
||
/** | ||
* Try to load a class | ||
* | ||
* @param string $class The class name to load | ||
* | ||
* @return boolean If the loading was successful | ||
*/ | ||
public function load($class) { | ||
$class = ltrim($class, '\\'); | ||
if (strpos($class, $this->namespace) === 0) { | ||
$nsparts = explode('\\', $class); | ||
$class = array_pop($nsparts); | ||
$nsparts[] = ''; | ||
$path = $this->path . implode(DIRECTORY_SEPARATOR, $nsparts); | ||
$path .= str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; | ||
if (file_exists($path)) { | ||
require $path; | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Register the autoloader to PHP | ||
* | ||
* @return boolean The status of the registration | ||
*/ | ||
public function register() { | ||
return spl_autoload_register(array($this, 'load')); | ||
} | ||
|
||
/** | ||
* Unregister the autoloader to PHP | ||
* | ||
* @return boolean The status of the unregistration | ||
*/ | ||
public function unregister() { | ||
return spl_autoload_unregister(array($this, 'load')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.