/**
  * @param Request  $req
  * @param Response $res
  * @param array    $allowedMethods
  *
  * @return Response
  */
 public function __invoke($req, $res, $allowedMethods)
 {
     if ($req->isHtml()) {
         $res->render(new View('method_not_allowed', ['title' => 'Method Not Allowed', 'allowedMethods' => $allowedMethods]));
     }
     return $res->setCode(405);
 }
 public function testRenderException()
 {
     $request = $this->makeRequest();
     $response = new Response($request);
     $this->setExpectedException('UnderflowException', 'You must set controller before calling this method.');
     $response->render('tpl');
 }
 /**
  * @param Request  $req
  * @param Response $res
  *
  * @return Response
  */
 public function __invoke($req, $res)
 {
     if ($req->isHtml()) {
         $res->render(new View('not_found', ['title' => 'Not Found']));
     }
     return $res->setCode(404);
 }
 /**
  * @param Request    $req
  * @param Response   $res
  * @param \Exception $e
  *
  * @return Response
  */
 public function __invoke($req, $res, \Exception $e)
 {
     $this->app['logger']->error('An uncaught exception occurred while handling a request.', ['exception' => $e]);
     if ($req->isHtml()) {
         $res->render(new View('exception', ['title' => 'Internal Server Error', 'exception' => $e]));
     }
     return $res->setCode(500);
 }
Example #5
0
 /**
  * Returns the rendered html
  * @return the rendered html
  */
 public function render()
 {
     parent::render();
     if ($this->renderAs === 'blank') {
         $template = new \OCP\Template($this->appName, $this->templateName);
     } else {
         $template = new \OCP\Template($this->appName, $this->templateName, $this->renderAs);
     }
     foreach ($this->params as $key => $value) {
         $template->assign($key, $value, false);
     }
     return $template->fetchPage();
 }
Example #6
0
 /**
  * Returns the rendered json
  * @return the rendered json
  */
 public function render()
 {
     parent::render();
     ob_start();
     if ($this->error) {
         \OCP\JSON::error($this->data);
     } else {
         \OCP\JSON::success($this->data);
     }
     $result = ob_get_contents();
     ob_end_clean();
     return $result;
 }
Example #7
0
 public function run()
 {
     try {
         if (!$this->router->match($this->request->getMethod(), $this->request->getUrl())) {
             throw new \Exception('No route match url', 404);
         }
         $controllerClass = '\\Controllers\\' . ucfirst($this->router->getController()) . 'Controller';
         $action = $this->router->getAction() . 'Action';
         $controller = new $controllerClass($this);
         $response = call_user_func_array(array($controller, $action), $this->router->getParameters());
         $response->setApp($this);
         $response->render();
     } catch (\Exception $e) {
         $code = $e->getCode() === 404 ? 404 : 500;
         $response = new Response($code . '.html', array('msg' => $e->getMessage()));
         $response->setApp($this);
         $response->render();
     }
 }
Example #8
0
 /**
  * 1) Initialise the Request
  * 2) Grab the AssetType based on the request and initialise it
  * 3) Instantiate the Response class, set the headers, and then return the content
  *
  * Rap everything in a Try/Catch block for error handling
  *
  * @param Request $Request
  * @param array $options
  *
  * @return string
  *
  * @catch NotFoundException
  * @catch ErrorException
  */
 public static function run(Request $Request, $options = array())
 {
     try {
         /**
          * Merge in default options
          */
         $options = array_merge(self::$defaultOptions, $options);
         /**
          * Set the header controller. Can be overwritten by the dispatcher options
          */
         if (isset($options['headerController']) && $options['headerController'] instanceof Asset\HeaderSetter) {
             $headerController = $options['headerController'];
         } else {
             $headerController = new Asset\HeaderSetter();
         }
         /**
          * Initialise the Request
          */
         $Request->init();
         /**
          * Grab the correct AssetType
          */
         $AssetType = Asset\Registry::getClass($Request);
         /**
          * Initialise the AssetType
          */
         $AssetType->init();
         /**
          * Create a response
          */
         $Response = new Response($AssetType);
         $Response->setHeaderController($headerController);
         /**
          * Set the headers if told to do so
          */
         if ($options['setHeaders']) {
             /**
              * Set the headers.
              */
             $Response->setHeaders($options['maxAge']);
         }
         /**
          * If the content hasn't been modified return null so only headers are sent
          * otherwise return the content
          */
         return $Response->notModified ? null : $Response->render();
     } catch (Asset\NotFoundException $e) {
         if (isset($headerController) && $headerController instanceof Asset\HeaderSetter) {
             $headerController->statusCode('HTTP/1.0', 404, 'Not Found');
             $headerController->headerField('Status', '404 Not Found');
         }
         return 'Not Found Error: ' . static::getErrors($e);
     } catch (Asset\Type\CompilationException $e) {
         if (isset($AssetType) && $AssetType instanceof Asset\Type) {
             $AssetType->cleanUpAfterError();
         }
         return 'Compilation Error: ' . static::getErrors($e);
     } catch (ErrorException $e) {
         return 'Error: ' . static::getErrors($e);
     }
 }
Example #9
0
 public function get()
 {
     $response = new Response();
     return $response->render('partials/table', array('this' => $this), $fetch = true);
 }
 public function getSummary()
 {
     $response = new Response();
     return $response->render('partials/debug.tpl', array('profiler' => $this), true);
 }
Example #11
0
 public function render()
 {
     $vars = $this->getVars();
     $response = new Response();
     return $response->render('partials/form.tpl', $vars, $fetch = true);
 }
Example #12
0
 public function run()
 {
     // Se usa un contexto global para el render
     return Response::render('homepage');
 }
Example #13
0
 /**
  * Simply sets the headers and returns the file contents
  * @return the file contents
  */
 public function render()
 {
     parent::render();
     return $this->content;
 }
Example #14
0
<?php

try {
    require_once '../config/core.conf.php';
    header('Content-type: text/html; charset=' . Lang::$encoding);
    //$profiler = new Profiler();
    $controller = new ActionController();
    $controller->handle();
    //$profiler->stop();
    //echo $profiler->getSummary();
} catch (Exception $e) {
    $response = new Response();
    if ($e instanceof AutoloadException || $e instanceof ViewException) {
        $response->render('500');
    }
    if ($e instanceof ActionControllerException) {
        $response->render('404');
    }
    $class_exception = get_class($e);
    $msg_exception = $class_exception . ' : ' . $e->getMessage();
    Logger::log($msg_exception);
    if (CORE_DEBUG) {
        echo '<pre>' . $msg_exception . '</pre>';
    }
}
Example #15
0
 /**
  * Returns a RedirectResponse to the given URL.
  *
  * @param string  $url    The URL to redirect to
  * @param integer $status The status code to use for the Response
  *
  * @return RedirectResponse
  */
 public function redirect($url, $status = 302)
 {
     $this->redirectWithHtml($url);
     $this->response->addHeader('location', $url);
     return $this->response->render();
 }
Example #16
0
 /**
  * Simply sets the headers and returns the file contents
  * @return the file contents
  */
 public function render()
 {
     parent::render();
 }