Example #1
0
 private function doLoad($key, array $args = array())
 {
     //Is the object not loaded?
     if (!isset($this->loaded[$key])) {
         foreach ($this->containers as $containerKey => &$container) {
             if (!isset($container['path'])) {
                 continue;
             }
             //No, so we need to load all of it's dependancies and initiate it.
             $dirBase = $container['path'];
             $namespaceBase = $container['namespace'];
             if (is_file($dirBaseFolderFile = $dirBase . lcfirst($key) . _DS_ . $key . '.php')) {
                 $className = $namespaceBase . lcfirst($key) . '\\' . $key;
                 if (!class_exists($className)) {
                     require $dirBaseFolderFile;
                 }
                 $this->classNames[$key] = $className;
                 $this->interfaces[$key] = $this->loadClassDependencies($this->classNames[$key]);
                 break;
             } else {
                 if (is_file($dirBaseFile = $dirBase . $key . '.php')) {
                     $className = $namespaceBase . $key;
                     if (!class_exists($className)) {
                         require $dirBaseFile;
                     }
                     $this->classNames[$key] = $className;
                     $this->interfaces[$key] = $this->loadClassDependencies($this->classNames[$key]);
                     break;
                 } else {
                     if (is_dir($dir = $dirBase . $key)) {
                         $localInstance = new Loader();
                         $localInstance->registerContainer($key, $dir . _DS_, $namespaceBase . $key . '\\');
                         $this->classNames[$key] = get_class($this);
                         $this->loaded[$key] = $localInstance;
                         break;
                     }
                 }
             }
         }
         // end of foreach
         if (!isset($this->classNames[$key])) {
             throw new LoaderException(LoaderException::CANNOT_LOAD_KEY, "Loader can't load key {$key}.", $this->classNames, $this->containers, $dirBaseFolderFile, $dirBaseFile, $dir);
         }
     }
     // is it a loader?
     if ($this->classNames[$key] == get_class($this)) {
         //returns the loader
         return $this->loaded[$key];
     }
     $className = $this->classNames[$key];
     $interfaces = $this->interfaces[$key];
     if (in_array('nutshell\\behaviour\\Loadable', $interfaces)) {
         // Initiate
         $this->loaded[$key] = 'Loading';
         $localInstance = $className::getInstance($args);
         $this->loaded[$key] = $localInstance;
         return $localInstance;
     } else {
         throw new LoaderException(LoaderException::CANNOT_LOAD_CLASS, 'Loader failed to load class "' . $className . '". This is likely because the container ' . 'handle you\'re using to handle the loading with doesn\'t impement the "Loadable" behaviour.');
     }
 }
Example #2
0
 /**
  * Loads core components and registers them for loading.
  * 
  * Loads all the required core libraries and then
  * registers their child classes for loading with the
  * core loader.
  * 
  * @access private
  * @return Nutshell
  */
 private function loadCoreComponents()
 {
     require NS_HOME . 'core' . _DS_ . 'Component.php';
     require NS_HOME . 'core' . _DS_ . 'HookManager.php';
     require NS_HOME . 'core' . _DS_ . 'exception' . _DS_ . 'NutshellException.php';
     require NS_HOME . 'core' . _DS_ . 'request' . _DS_ . 'Request.php';
     require NS_HOME . 'core' . _DS_ . 'exception' . _DS_ . 'ConfigException.php';
     require NS_HOME . 'core' . _DS_ . 'config' . _DS_ . 'Config.php';
     require NS_HOME . 'core' . _DS_ . 'config' . _DS_ . 'Framework.php';
     require NS_HOME . 'core' . _DS_ . 'loader' . _DS_ . 'Loader.php';
     require NS_HOME . 'core' . _DS_ . 'loader' . _DS_ . 'HipHopLoader.php';
     require NS_HOME . 'core' . _DS_ . 'plugin' . _DS_ . 'AbstractPlugin.php';
     require NS_HOME . 'core' . _DS_ . 'plugin' . _DS_ . 'Plugin.php';
     require NS_HOME . 'core' . _DS_ . 'plugin' . _DS_ . 'LibraryPlugin.php';
     require NS_HOME . 'core' . _DS_ . 'plugin' . _DS_ . 'PluginExtension.php';
     NutshellException::register();
     Request::register();
     Config::register();
     Loader::register();
     Plugin::register();
     return $this;
 }