/** * 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; } } }
/** * 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)); } } } } }
/** * 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); }
/** * Init the environment types from * the config files */ protected final function initEnvironmentTypes() { $environment = Registry::get('environment'); foreach ($this->config->getElementsByPath('environment/type') as $type) { $flags = $type->getAttribute('flags'); $name = $type->getAttribute('name'); /** * If the name is not given "ignore" * this element */ if (!$name) { continue; } /** * Create name with appended * flags to parse them later */ $nameWf = $name; if ($flags) { $nameWf .= Environment::TYPE_FLAG_SEPERTOR; $nameWf .= ltrim($flags, Environment::TYPE_FLAG_SEPERTOR); } $environment->addType($nameWf); /** * Add conditions from type * if they are given */ foreach ($type->getChildrenByName('condition') as $condition) { $type = $condition->getAttribute('type'); $value = $condition->getAttribute('value'); /** * Add a specific type to the environment * defined with some aliases for each * type */ if ($type && $value) { switch ($type) { case 'url': case 'urlpattern': case 'url-pattern': $environment->addUrlPattern($name, $value); break; case 'host': case 'hostname': $environment->addHostname($name, $value); break; } } } } $this->config->setEnvironment($environment); $this->config->applyEnvironment(); }
/** * Gets config elements from a element * * @param string $path * @return array */ public function getConfigs($path) { return Config::getInstance()->getElementsByPath($path); }
/** * 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; }