Skip to content

Instantly share code, notes, and snippets.

@v6ak
Created October 11, 2010 08:12
Show Gist options
  • Select an option

  • Save v6ak/620200 to your computer and use it in GitHub Desktop.

Select an option

Save v6ak/620200 to your computer and use it in GitHub Desktop.
<?php
namespace V6;
/**
* @author Vít Šesták 'v6ak'
* @license BSD
*/
final class NamespacedLoader {
private $path;
function __construct($path) {
$this->path = $path;
}
public function load($name){
// If loading fails, the autoloading system detects that the class is not loaded and asks the next loader to load the class.
// Well, it does not report permission denied and so on. It can be fixed using file_exists, but it is not atomic.
@include_once $this->path.'/'. \str_replace('\\', '/', $name) . '.php';
}
public function register(){
\spl_autoload_register(array($this, 'load'));
}
public static function registerForPath($path){
$loader = new self($path);
$loader->register();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment