Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param  string                     $uri         base URI for this component
  * @param  string                     $namespace   this applications base namespace
  * @param  array                      $paths       path to the application component
  * @param  Component                  $parent      parent Component instance
  * @param  Fuel\Config\Datacontainer  $config      Config Container instance
  * @param  Input                      $input       Input Container instance
  * @param  Composer\ClassLoader       $autoloader  Autoloader instance
  * @param  InjectionFactory           $factory     factory object to construct external objects
  *
  * @since  2.0.0
  */
 public function __construct($app, $uri, $namespace, $paths, $routeable, $parent, $config, $input, $autoloader, InjectionFactory $factory)
 {
     // store the component object factory
     $this->factory = $factory;
     // store the app
     $this->app = $app;
     // unify the URI
     $this->uri = trim($uri, '/');
     // and the namespace
     $this->namespace = trim($namespace, '\\');
     // and the routeable flag
     $this->routeable = (bool) $routeable;
     // TODO: needs a better solution than hardcoding paths!
     // process and verify the paths
     foreach ($paths = (array) $paths as $path) {
         // get what we think is the root path
         $path = realpath($path . DS . '..' . DS);
         // check if this is a valid component
         if (is_dir($path . DS . 'classes') and !in_array($path, $this->paths)) {
             // store it
             $this->paths[] = $path;
             // and add it to the autoloader if needed
             $prefixes = $autoloader->getPrefixesPsr4();
             if (!isset($prefixes[$this->namespace . '\\']) or !in_array($path . DS . 'classes', $prefixes[$this->namespace . '\\'])) {
                 $autoloader->addPsr4($this->namespace . '\\', $path . DS . 'classes');
             }
         }
     }
     // if the parent is a Component too
     if ($parent instanceof Component) {
         // make a backlink to link parent and child
         $parent->setChild($this);
     } else {
         // setup the global config defaults
         $config->addPath(realpath(__DIR__ . DS . '..' . DS . 'defaults') . DS);
         // import global data
         $input->fromGlobals();
         // assign the configuration container to this input instance
         $input->setConfig($config);
     }
     // add the paths to the config
     foreach ($this->paths as $path) {
         $config->addPath($path . DS);
     }
     // store the config container
     $this->config = $config;
     // load the application configuration
     $this->config->load('config', null);
     // load the file config
     $this->config->load('file', true);
     // load the lang config
     $this->config->load('lang', true);
     // store our parent object
     $this->parent = $parent ?: $app;
     // create the router instance
     $this->router = $this->factory->createRouterInstance($this);
     // and load any defined routes in this module
     $this->loadRoutes();
     // store the input instance
     $this->input = $input;
     // and finally run the component bootstrap if present
     $this->runBootstrap();
 }