Esempio n. 1
0
/**
 * Sets up autoloading and creates the service provider (DIC)
 *
 * Setup global class map and loader instances and add the core classes to the map.
 * We can't load this from dataroot because we don't know it yet, and we'll need
 * several classes before we can find out!
 *
 * @throws RuntimeException
 * @access private
 */
function _elgg_create_service_provider()
{
    // manually load classes needed for autoloading
    $dir = dirname(dirname(__FILE__)) . '/classes';
    foreach (array('Elgg_ClassMap', 'Elgg_ClassLoader', 'Elgg_AutoloadManager') as $class) {
        if (!class_exists($class)) {
            $file = "{$dir}/" . strtr($class, '_\\', '//') . ".php";
            include $file;
            if (!class_exists($class, false)) {
                throw new RuntimeException("Could not load {$class} in {$file}.");
            }
        }
    }
    $loader = new Elgg_ClassLoader(new Elgg_ClassMap());
    // until the cache can be loaded, just setup PSR-0 autoloading
    // out of the classes directory. No need to build a full map.
    $loader->addFallback($dir);
    $loader->register();
    $manager = new Elgg_AutoloadManager($loader);
    return new Elgg_Di_ServiceProvider($manager);
}