コード例 #1
0
ファイル: Standard.php プロジェクト: nextframework/next
 /**
  * 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;
 }
コード例 #2
0
ファイル: Standard.php プロジェクト: nextframework/next
 /**
  * Dispatches the Controller
  *
  * @param Next\Application\Application $application
  *   Application to Configure
  *
  * @param stdClass $data
  *   Data to Configure Application
  *
  * @return Next\HTTP\Response
  *   Response Object
  *
  * @throws Next\Controller\Dispatcher\DispatcherException
  *   ReflectionException was caught
  */
 public function dispatch(Application $application, \stdClass $data)
 {
     try {
         $this->setDispatched(TRUE);
         // Adding Request Params
         $application->getRequest()->setQuery($data->params);
         // Calling Action from Controller at defined Application
         $reflector = new \ReflectionMethod($data->class, $data->method);
         $reflector->invoke(new $data->class($application));
         return $application->getResponse();
     } catch (\ReflectionException $e) {
         throw DispatcherException::reflection($e);
     } catch (ControllerException $e) {
         /**
          * @internal
          * ControllerException's came from Application's Controllers
          * and, as part of Standardization Concept, should be thrown when
          * something is wrong
          *
          * E.g.: Database Query results in FALSE instead of a Recordset Object
          *
          * Doesn't matter the level of DEVELOPMENT MODE Constant, we'll
          * try to create a Template Variable and virtually re-send the Response,
          * by re-rendering the View
          *
          * Now, in Template View, a special variable will be available with
          * Exception Message
          *
          * If the assignment or rendering fails, the Production Handler
          * will be used as fallback
          */
         try {
             $application->getView()->assign('__EXCEPTION__', $e->getMessage())->render();
         } catch (ViewException $e) {
             Handlers::production($e);
         }
     } catch (ViewException $e) {
         /**
          * @internal
          * Catching ViewException grants a nice view for any sort of
          * errors triggered by Next View Class, specially when they come from Magic Methods
          * which is directly related to Template Variables usage.
          *
          * And by forcing a Development Handler we warn lazy
          * programmers they are doing the wrong thing, like trying to hide the error ^^
          */
         if (ob_get_length()) {
             // We want ONLY the Exception Template
             ob_end_clean();
         }
         Handlers::development($e);
     }
 }
コード例 #3
0
 /**
  * Get Response Object
  *
  * @return Next\HTTP\Response
  *   Response Object
  */
 public function getResponse()
 {
     return $this->_application->getResponse();
 }