Example #1
0
 public function __construct($content = '', $status = 403, $headers = array())
 {
     $content = '<h2>Error 403 - Access Forbidden</h2>';
     $content .= '<p>You do not have permission';
     $content .= ' to access the page you requested</p>';
     parent::__construct($content, $status, $headers);
 }
Example #2
0
 public function __construct($content = '', $status = 404, $headers = array())
 {
     $content = '<h2>The page you requested was not found</h2>';
     $content .= '<p>You may have clicked an expired link or mistyped the ';
     $content .= 'address. Some web addresses are case sensitive</p>';
     parent::__construct($content, $status, $headers);
 }
Example #3
0
 public function testCubexHeaders()
 {
     if (!defined('PHP_START')) {
         define('PHP_START', microtime(true));
     }
     $response = new Response();
     $response->setCubexHeaders();
     $this->assertContains('X-Execution-Time', (string) $response);
     $response = new Response();
     $response->disableCubexHeaders();
     $response->setCubexHeaders();
     $this->assertNotContains('X-Execution-Time', (string) $response);
     $response = new Response();
     $response->disableCubexHeaders();
     $response->enableCubexHeaders();
     $response->setCubexHeaders();
     $this->assertContains('X-Execution-Time', (string) $response);
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function handleException(\Exception $exception)
 {
     if (!$exception instanceof ApiException) {
         $exception = new ApiException($exception->getMessage(), $exception->getCode());
     }
     //Let the end user known the exception message
     $apiResponse = Response::create($exception->getFormatted(new JsonFormat()));
     $apiResponse->headers->set("Content-Type", "application/json");
     return $apiResponse;
 }
Example #5
0
 public function sendContent()
 {
     if (is_array($this->content) || is_object($this->content)) {
         $out = fopen('php://output', 'w');
         foreach ($this->content as $row) {
             fputcsv($out, (array) $row);
         }
         fclose($out);
         return $this;
     }
     return parent::sendContent();
 }
Example #6
0
 public function testHeaders()
 {
     $request = Request::createFromGlobals();
     $kernel = $this->getKernel(Response::create('abc'));
     $resp = $kernel->handle($request, Cubex::MASTER_REQUEST, false);
     if ($resp instanceof Response) {
         $resp->setCubexHeaders();
     }
     $this->assertTrue($resp->headers->has('X-Execution-Time'));
     $this->assertTrue($resp->headers->has('X-Call-Time'));
 }
Example #7
0
 public function testGetLayoutSection()
 {
     $layout = new Layout(new TestLayoutController());
     $view = new TestView();
     $layout->insert('content', $view);
     $response = new TestResponse(Response::create($layout));
     $test = new MockCubexTestCase();
     $test->setLastResponse($response);
     $this->assertSame($view, $test->getLayoutSection());
 }