コード例 #1
0
ファイル: Page.php プロジェクト: fewlines/component
 /**
  * Gets the value of url.
  *
  * @return DomElement
  */
 public function getUrl()
 {
     if ($this->url && $this->url->hasAttribute('href')) {
         $this->active = Router::getInstance()->getRequest()->getUrl() == $this->url->getAttribute('href');
     }
     return $this->url;
 }
コード例 #2
0
ファイル: View.php プロジェクト: fewlines/core
 /**
  * Inits with the template
  *
  * @param  \Fewlines\Core\Template\Template $template
  */
 public function init(\Fewlines\Core\Template\Template &$template)
 {
     $this->template = $template;
     $this->httpRequest = Router::getInstance()->getRequest();
     $this->httpResponse = $this->httpRequest->getResponse();
     $this->view = $this->template->getView();
     $this->layout = $this->template->getLayout();
     if (method_exists($this, 'postInit')) {
         call_user_func(array($this, 'postInit'));
     }
 }
コード例 #3
0
ファイル: UrlHelper.php プロジェクト: fewlines/core
 /**
  * Gets a route from the config
  * and parse the optional argumuntes
  * for it
  *
  * @param string $id
  * @param array $arguments
  * @return string
  */
 public static function getRouteUrl($id, $arguments = array())
 {
     foreach (Router::getInstance()->getRoutes() as $route) {
         $rId = $route->getId();
         if (!empty($rId) && trim($rId) == trim($id)) {
             return static::parseRouteUrl($route->getFullFrom(), $arguments);
             break;
         }
     }
     return null;
 }
コード例 #4
0
ファイル: Environment.php プロジェクト: fewlines/core
 /**
  * @return \Fewlines\Core\Application\Environment\EnvType|boolean
  */
 private function checkUrlPatterns()
 {
     $url = $this->router->getRequest()->getHost();
     $type = false;
     for ($i = 0, $len = count($this->urlPatterns); $i < $len; $i++) {
         if (preg_match($this->urlPatterns[$i]->getPattern(), $url)) {
             $type = $this->urlPatterns[$i]->getType();
             break;
         }
     }
     return $type;
 }
コード例 #5
0
ファイル: Session.php プロジェクト: fewlines/component
 /**
  * Creates a new session
  *
  * @param string  $name
  * @param *	      $content
  * @param int 	  $lifetime (minutes)
  * @param boolean $encrypt
  * @param string  $path
  */
 public function __construct($name, $content, $lifetime = 0, $encrypt = false, $path = '')
 {
     $cookiePath = Router::getInstance()->getBaseUrl();
     if ($path != '') {
         $cookiePath .= $path;
     }
     $this->type = $lifetime == 0 ? self::SESSION : self::COOKIE;
     // Create a session by type
     switch ($this->type) {
         case self::COOKIE:
             $this->createCookie($name, $content, time() + $lifetime * 60, $encrypt, $cookiePath);
             break;
         case self::SESSION:
             $this->createSession($name, $content);
             break;
     }
 }
コード例 #6
0
ファイル: Navigation.php プロジェクト: fewlines/component
 /**
  * @param  array $parts
  * @return string
  */
 private function parseUrl($parts)
 {
     $urlParts = Router::getInstance()->getRouteUrlParts();
     for ($i = 0, $len = count($parts); $i < $len; $i++) {
         $parts[$parts[$i]->getName()] = (string) $parts[$i];
         unset($parts[$i]);
     }
     return UrlHelper::getBaseUrl(implode('/', array_merge($urlParts, $parts)));
 }
コード例 #7
0
ファイル: Template.php プロジェクト: fewlines/core
 /**
  * Returns the last created instance
  *
  * @return \Fewlines\Core\Template\Template
  */
 public static function getInstance()
 {
     if (true == is_null(self::$instance)) {
         return new self(Router::getInstance()->getRouteUrlParts());
     }
     return self::$instance;
 }
コード例 #8
0
ファイル: Bootstrap.php プロジェクト: fewlines/core
 /**
  * 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();
                     }
                 }
             }
         }
     }
 }
コード例 #9
0
ファイル: Project.php プロジェクト: fewlines/core
 /**
  * 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;
 }
コード例 #10
0
ファイル: View.php プロジェクト: fewlines/core
 /**
  * Set the controller
  * for the route
  *
  * @param string $class
  */
 public function setRouteControllerClass($class)
 {
     $method = strtolower(Router::getInstance()->getRequest()->getHttpMethod());
     $routeMethod = strtolower($this->activeRoute->getType());
     if ($routeMethod == 'any' || $method == $routeMethod) {
         if (true == class_exists($class)) {
             $this->controllerClass = $class;
         } else {
             HttpHeader::set(404, false);
             throw new View\Exception\ControllerClassNotFoundException('The class "' . $this->controllerClass . '" for the
                 controller was not found.');
         }
     } else {
         HttpHeader::set(404, false);
         throw new View\Exception\InvalidHttpMethodException('Invalid HTTP method found');
     }
 }