Skip to content

Instantly share code, notes, and snippets.

@augustohp
Forked from caferrari/Loader.php
Created January 4, 2012 17:57
Show Gist options
  • Save augustohp/1561214 to your computer and use it in GitHub Desktop.
Save augustohp/1561214 to your computer and use it in GitHub Desktop.
VorticePHP2 Loader
<?php
/**
* Simple loader class
*
* Usage: new Vortice\Common\Loader('Zend', './Zend');
* @author Carlos André Ferrari <carlos@ferrari.eti.br>
*/
namespace Vortice\Common;
class Loader
{
/**
* Register a new namespace
*
* @var string
* @var string
* @var string
* @access public
*/
public function __construct($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