Created
October 11, 2010 08:12
-
-
Save v6ak/620200 to your computer and use it in GitHub Desktop.
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 | |
| 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