Skip to content

Instantly share code, notes, and snippets.

@caferrari
Created January 4, 2012 17:55
Show Gist options
  • Save caferrari/1561202 to your computer and use it in GitHub Desktop.
Save caferrari/1561202 to your computer and use it in GitHub Desktop.
VorticePHP2 Loader
<?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 <carlos@ferrari.eti.br>
*/
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