Beispiel #1
0
 /**
  * Render the page, outputs the buffer
  *
  * @param string|optional $name
  *   Template View File to render. If NULL, we'll try to find it
  *
  * @param boolean|optional $search
  *   Flag to condition whether or not we should try to find the
  *   proper Template View File automatically
  *
  * @return Next\HTTP\Response
  *   Response Object
  *
  * @throws Next\Voew\ViewException
  *   Unable to find Template View File
  */
 public function render($name = NULL, $search = TRUE)
 {
     $response = $this->_application->getResponse();
     /**
      * @internal
      * The Template Rendering will not happen if:
      *
      * - It shouldn't, which means Next\View\View::disableRender() was called
      *
      * - Any kind of output was already sent, like a debugging purposes
      *   var_dump() or even a ControllerException which was caught
      */
     if (!$this->_shouldRender || ob_get_length() != 0) {
         return NULL;
     }
     if ($search == FALSE && empty($name)) {
         throw ViewException::unableToFindFile();
     }
     // Adding high priority Partial Views
     foreach ($this->_queue as $partial) {
         if ($partial->getPriority() > self::PRIORITY) {
             $partial->render();
         }
     }
     // Including Template File
     ob_start();
     // ... manually
     if (!$search) {
         $file = stream_resolve_include_path($name);
         if ($file !== FALSE) {
             include $file;
         } else {
             throw ViewException::missingFile($name);
         }
     } else {
         // ... or automatically
         include $this->findFile($name);
     }
     // Adding Main View Content to Response Body
     $response->appendBody(ob_get_clean());
     // Adding low priority Partial Views
     foreach ($this->_queue as $partial) {
         if ($partial->getPriority() < self::PRIORITY) {
             $partial->render();
         }
     }
     /**
      * Something was rendered, so let's disallow another
      * rendering for this Request
      */
     $this->_shouldRender = FALSE;
     return $response;
 }