Exemplo n.º 1
0
 /**
  * @covers ::render
  */
 public function testRender()
 {
     $htmlRender = new HtmlRender(['foo' => 'bar']);
     $output = $htmlRender->render(['_view' => 'tests/View/Test/Fixture/test.view', '_layout' => 'tests/View/Layout/Fixture/test.layout']);
     $this->assertSame('<layout><view>bar</view></layout>', $output);
 }
Exemplo n.º 2
0
 /**
  * Call action
  *
  * @return Response
  *
  * @throws \LogicException If controller action is not set
  */
 public function callAction() : Response
 {
     if (!isset($this->action)) {
         throw new \LogicException('Controller action must be set before being called');
     }
     /**
      * Before controller action hook
      */
     if ($this->beforeAction()) {
         /**
          * Call controller action
          */
         $action = $this->action;
         $this->{$action}();
         /**
          * After controller action hook
          */
         $this->afterAction();
     }
     /**
      * Render view
      */
     if ($this->render && $this->contentType === 'html') {
         if ($this->request->getCookie()->exists('Flash.Message') && $this->request->getCookie()->exists('Flash.Type')) {
             $this->set('_flash', ['message' => $this->request->getCookie()->get('Flash.Message'), 'type' => $this->request->getCookie()->get('Flash.Type')]);
             $this->request->getCookie()->remove('Flash.Message');
             $this->request->getCookie()->remove('Flash.Type');
         }
         /**
          * Set content type header
          */
         $this->headers['content-type'] = 'Content-Type: text/html; charset=utf-8';
         /**
          * Render output
          */
         $render = new HtmlRender($this->variables);
         $output = $render->render(['_view' => $this->getViewTemplate(), '_layout' => $this->getLayoutTemplate()]);
         /**
          * Return response
          */
         return new Response($this->headers, $this->request->getCookie(), $output);
     } elseif ($this->render && $this->contentType === 'json') {
         /**
          * Set content type header
          */
         $this->headers['content-type'] = 'Content-Type: application/javascript;';
         /**
          * Return response
          */
         return new Response($this->headers, null, json_encode($this->variables));
     }
     return new Response($this->headers, null, '');
 }