예제 #1
0
파일: Renderer.php 프로젝트: fewlines/core
 /**
  * Renders a template
  *
  * @param string $layout
  * @param array $args
  * @param boolean $force
  */
 protected static final function renderTemplate($layout, $args = array(), $force = false)
 {
     Buffer::start();
     $template = Template::getInstance();
     $hasLayout = $template->getLayout() instanceof \Fewlines\Core\Template\Layout;
     if ($force == true || $force == false && !$hasLayout) {
         $template->setLayout($layout)->setAutoView()->renderAll($args);
     } else {
         if ($hasLayout) {
             $template->setAutoView()->renderAll($args);
         }
     }
 }
예제 #2
0
파일: Header.php 프로젝트: fewlines/core
    /**
     * Sets the defined code
     *
     * @param number $code
     */
    public static function set($code, $throw = true)
    {
        // Check for recursion
        if (self::$running == true) {
            throw new Header\Exception\StillRunningException('
				Could not (re)set the header, another process
				is still running. Recursion?
			');
        }
        self::$running = true;
        // Check if status message is given
        if (!array_key_exists($code, self::$messages)) {
            $code = self::DEFAULT_ERROR_CODE;
        }
        // Build message
        $message = self::$messages[$code]['status'];
        if (!empty(self::$messages[$code]['message'])) {
            $message = self::$messages[$code]['message'];
        }
        // Set status to the header
        self::setStatus(self::$messages[$code]['status']);
        // Check if a view was set
        if (array_key_exists($code, self::$codeViews)) {
            $throw = false;
            /**
             * Clear previous outputs
             * completely
             */
            Buffer::clear(true);
            /**
             * Render new template
             * with the given view path
             * and layout
             */
            $template = Template::getInstance();
            $template->setLayout(self::$codeViews[$code]['layout']);
            $template->setView(self::$codeViews[$code]['routing']['view']);
            $project = ProjectManager::getActiveProject();
            $ctrlClass = '\\' . $project->getNsName() . CONTROLLER_V_RL_NS . '\\' . self::$codeViews[$code]['routing']['ctrl'];
            if (!class_exists($ctrlClass) || !is_string(self::$codeViews[$code]['routing']['ctrl'])) {
                $project = ProjectManager::getDefaultProject();
                $ctrlClass = '\\' . $project->getNsName() . CONTROLLER_V_RL_NS . '\\Error';
            }
            $template->getView()->setControllerClass($ctrlClass);
            $template->getView()->setAction(self::$codeViews[$code]['routing']['action']);
            $template->renderAll();
            // Check end to recognize recursion
            self::$running = false;
            // Abort to prevent further actions
            exit;
        } else {
            if (true == $throw) {
                self::$running = false;
                // Throw HTTP exception
                throw new Header\Exception\HttpException($message);
            }
        }
        self::$running = false;
    }
예제 #3
0
파일: Renderer.php 프로젝트: fewlines/core
 /**
  * Returns the content of
  * a rendered element
  *
  * @param  string $viewPath
  * @param  array  $config
  * @param  string $wrapper
  * @return string
  */
 public function render($viewPath, $config = array(), $wrapper = '')
 {
     $view = PathHelper::getRealViewPath(ltrim($viewPath, DR_SP), '', Template::getInstance()->getLayout()->getName());
     $path = $view;
     // Handle relative path
     if (!PathHelper::isAbsolute($viewPath)) {
         $backtrace = debug_backtrace();
         $viewIndex = PathHelper::getFirstViewIndexFromDebugBacktrace($backtrace);
         if (false === $viewIndex) {
             throw new Exception\NoViewOriginFoundException('The view "' . $view . '" could not be
                 include. You can render relative path\'s
                 only from an other view.');
         }
         $file = PathHelper::normalizePath($backtrace[$viewIndex]['file']);
         $dir = pathinfo($file, PATHINFO_DIRNAME);
         $path = PathHelper::getRealViewFile(PathHelper::normalizePath($dir . DR_SP . $viewPath));
         $view = PathHelper::normalizePath(realpath($path));
         if ($view == $file) {
             throw new Exception\RenderRecursionException('The view "' . $view . '" is including itself (Recursion).');
             exit;
         }
     }
     /**
      * Default check & render
      */
     if (!$view || !file_exists($view)) {
         if (!$view) {
             $view = $path;
         }
         throw new Exception\ViewIncludeNotFoundException('The view "' . $view . '" was not found
             and could not be included');
     }
     $content = $this->getRenderedHtml($view, $config);
     if (!empty($wrapper)) {
         $content = sprintf($wrapper, $content);
     }
     return $content;
 }
예제 #4
0
파일: View.php 프로젝트: fewlines/core
 /**
  * @param  string $view
  * @return string
  */
 public function render($view)
 {
     return $this->template->renderView($view);
 }
예제 #5
0
파일: View.php 프로젝트: fewlines/core
 /**
  * Init the controller of a route
  *
  * @return null|*
  */
 public function initRouteController()
 {
     $this->routeController = new $this->controllerClass();
     if (true == $this->routeController instanceof \Fewlines\Core\Controller\View) {
         $template = Template::getInstance();
         $this->routeController->init($template);
         return $this->callRouteMethod($this->activeRoute->getToMethod(), $this->activeRoute->getVarsRecursive());
     } else {
         throw new View\Exception\ControllerInitialisationGoneWrongException('The route controller could not be initialized.
             Must be instance of \\Fewlines\\Controller\\View');
     }
     return null;
 }