Created
January 4, 2012 17:55
-
-
Save caferrari/1561202 to your computer and use it in GitHub Desktop.
VorticePHP2 Loader
This file contains hidden or 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
<?php | |
/** | |
* Simple loader class | |
* | |
* Usage: | |
* $loader = new Vortice\Common\Loader(); | |
* $loader->register('Zend', './Zend/'); | |
* $loader->register('Application', '../app/', 'Application\\'); | |
* $loader->register('Vortice', './'); | |
* | |
* @author Carlos André Ferrari <[email protected]> | |
*/ | |
namespace Vortice\Common; | |
class Loader | |
{ | |
/** | |
* Register a new namespace | |
* | |
* @var string | |
* @var string | |
* @var string | |
* @access public | |
*/ | |
public function register($namespace, $folder, $remove = '') | |
{ | |
spl_autoload_register( | |
function($classname) use ($folder, $namespace, $remove){ | |
if (false == strstr($classname, $namespace)) return; | |
$classname = str_replace($remove, '', $classname); | |
$file = str_replace('\\', DIRECTORY_SEPARATOR, $classname); | |
require_once $folder . $file . '.php'; | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment