예제 #1
0
 /**
  * Add classes found in this directory to the class map
  *
  * We keep track of which dirs were scanned on previous requests so we don't need to
  * rescan unless the cache is emptied.
  *
  * @param string $dir Directory of classes
  * @return Elgg_AutoloadManager
  */
 public function addClasses($dir)
 {
     if (!in_array($dir, $this->scannedDirs)) {
         $map = $this->loader->getClassMap();
         $map->mergeMap($this->scanClassesDir($dir));
         $this->scannedDirs[] = $dir;
         $this->altered = true;
     }
     $this->loader->addFallback($dir);
     return $this;
 }
예제 #2
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);
}