Beispiel #1
0
 /**
  * Updates the router e.g. check
  * for incoming routes
  */
 public function update()
 {
     // Add routes
     $routeCollection = Config::getInstance()->getElementsByPath('routes');
     foreach ($routeCollection as $routes) {
         if ($routes != false) {
             // Add routes
             foreach ($routes->getChildren() as $child) {
                 $this->addRouteByElement($child);
             }
             // Add layout if exsits
             $layout = $routes->getChildByName('layout');
             if ($layout) {
                 $this->routeLayout = $layout->getContent();
             }
         }
     }
     // Check if route is active
     foreach ($this->routes as $route) {
         if ($this->checkRoute($route)) {
             $this->setRoute($route);
             break;
         }
     }
 }
Beispiel #2
0
 /**
  * Adds all commands for the core project
  * and active project
  */
 public function addAll()
 {
     $this->add(new Project\Create());
     $this->add(new Project\Update());
     $this->add(new Project\Activate());
     $this->add(new Project\Deactivate());
     /**
      * Add commands registered in the config
      */
     $commands = Config::getInstance()->getElementByPath('commands');
     if ($commands) {
         foreach ($commands->getChildren() as $child) {
             $name = $child->getAttribute('name');
             $controller = $child->getAttribute('controller');
             $description = $child->getAttribute('description');
             if ($name && $controller) {
                 if (class_exists($controller)) {
                     $command = new $controller($name);
                     if (!$command instanceof \Fewlines\Core\Command\Command) {
                         throw new Exception\InvalidControllerException(sprintf('Controller must inherit from "%s"', '\\Fewlines\\Core\\Command\\Command'));
                     }
                     if ($description) {
                         $command->setDescription($description);
                     }
                     $this->add($command);
                 } else {
                     throw new Exception\ControllerNotFoundException(sprintf('Controller "%s" not found', $controller));
                 }
             }
         }
     }
 }
Beispiel #3
0
 /**
  * Simple database constructor which inits
  * the required information for a database
  * connection
  *
  * @param string $host
  * @param string $user
  * @param string $password
  * @param string $database
  * @param string $charset
  */
 public function __construct($host = "default", $user = "", $password = "", $database = "", $charset = "")
 {
     $defaultPort = ini_get("mysqli.default_port");
     if ($host == "default") {
         // Get information from the config
         // of the application
         $config = Config::getInstance();
         $dbCfg = $config->getElementByPath('database');
         $host = $dbCfg->getChildByName('host')->getContent();
         $user = $dbCfg->getChildByName('user')->getContent();
         $password = $dbCfg->getChildByName('password')->getContent();
         $database = $dbCfg->getChildByName('database')->getContent();
         $port = $dbCfg->getChildByName('port');
         $charset = $dbCfg->getChildByName('charset');
         $port = false == $port ? $defaultPort : $port->getContent();
         $charset = false == $charset ? self::LINK_CHARSET : $charset->getContent();
     } else {
         // Get port from host (if set)
         $port = end(split(":", $host));
         $port = $port != $host ? $port : $defaultPort;
         $host = $port != $host ? reset(split(":", $host)) : $host;
         $charset = empty($charset) ? self::LINK_CHARSET : $charset;
     }
     // Create link for connection
     $this->link = new Link($host, $user, $password, $database, $port);
     // Set charset for the conenction
     $this->link->set_charset($charset);
 }
Beispiel #4
0
 /**
  * Gets config elements from a element
  *
  * @param  string $path
  * @return array
  */
 public function getConfigs($path)
 {
     return Config::getInstance()->getElementsByPath($path);
 }
Beispiel #5
0
 /**
  * Init all projects defined
  * in the config
  */
 protected final function initProjects()
 {
     $projects = $this->config->getElementByPath('projects');
     if ($projects) {
         $activeCount = 0;
         foreach ($projects->getChildren() as $proj) {
             /**
              * Collect necessary informations
              * from the xml element frame
              */
             $id = $proj->getName();
             $name = $proj->getChildByName('name');
             $description = $proj->getChildByName('description');
             $namespace = $proj->getChildByName('namespace');
             /**
              * Add a new project to the list
              * with the information from
              * the xml config element
              */
             if (!empty($id) && $name && $description) {
                 $project = ProjectManager::addProject($id, $name->getContent(), $description->getContent(), $namespace->getContent());
                 /**
                  * Check if the project is initial
                  * activated and set the flag
                  * as if is so
                  */
                 $isActive = $project->setActive(filter_var($proj->getAttribute('active'), FILTER_VALIDATE_BOOLEAN));
                 if ($isActive) {
                     $activeCount++;
                     if ($activeCount > 1) {
                         // Init environment types manually
                         $this->initEnvironmentTypes();
                         throw new Bootstrap\Exception\TooManyProjectsException('Only one project can be active');
                     } else {
                         // Add config files from this project
                         Config::getInstance()->addConfigFiles(array(array('dir' => $project->getConfigPath(), 'type' => 'xml')));
                         Router::getInstance()->update();
                     }
                 }
             }
         }
     }
 }
Beispiel #6
0
 /**
  * Calls the bootstrap of the project
  * with the given namespace
  *
  * @param  \Fewlines\Core\Application\Application $app
  * @return {lib/php/$ns}\Application\Bootstrap
  */
 public function bootstrap(\Fewlines\Core\Application\Application $app)
 {
     if ($this->hasNsName()) {
         // Get bootstrap class
         $class = $this->getNsName() . BOOTSTRAP_RL_NS;
         // Create and call bootstrap
         if (class_exists($class)) {
             $this->bootstrap = new $class($app);
             $this->bootstrap->autoCall();
         }
         Router::getInstance()->update();
         Config::getInstance()->update();
     }
     return $this->bootstrap;
 }