Skip to content

Instantly share code, notes, and snippets.

@riaf
Created October 5, 2010 02:21
Show Gist options
  • Save riaf/610854 to your computer and use it in GitHub Desktop.
Save riaf/610854 to your computer and use it in GitHub Desktop.
deprecated. see jp.riaf.util.AutoLoader
<?php
// TODO: Store をクリアする何かが必要
spl_autoload_register(function($name) {
$store_key = array(__DIR__, '__autoload');
if (App::mode() == 'release' && Store::has($store_key)) {
$files = Store::get($store_key);
} else {
$files = array();
$dir = 'libs/';
$itr = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
$pattern = '/^libs\/(.+?)\.php$/';
foreach ($itr as $elem) {
if ($elem->isFile() && preg_match($pattern, $elem->getPathname(), $match)) {
$files[$elem->getBasename('.php')] = str_replace('/', '.', $match[1]);
}
}
Store::set($store_key, $files);
}
if (isset($files[$name])) {
import($files[$name]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment