Beispiel #1
0
 /**
  * Reset layout and Request
  */
 protected static function resetApp()
 {
     if (self::$app) {
         self::$app->useLayout(true);
     }
     Proxy\Auth::clearIdentity();
     Proxy\Messages::popAll();
     Proxy\Request::setInstance(new Http\Request());
     Proxy\Response::setInstance(new Http\Response());
     Proxy\Response::setPresentation(null);
 }
Beispiel #2
0
 /**
  * Response as Json
  */
 public function process()
 {
     // override response code so javascript can process it
     $this->response->setHeader('Content-Type', 'application/json');
     // setup messages
     if (Messages::count()) {
         $this->response->setHeader('Bluz-Notify', json_encode(Messages::popAll()));
     }
     // prepare body
     if ($body = $this->response->getBody()) {
         // convert to JSON
         $body = json_encode($body);
         // setup content length
         $this->response->setHeader('Content-Length', strlen($body));
         // prepare to JSON output
         $this->response->setBody($body);
     }
 }
Beispiel #3
0
 protected function tearDown()
 {
     Db::delete('users')->where('id IN (?)', [1, 2])->execute();
     Messages::popAll();
 }
Beispiel #4
0
 /**
  * Reset layout and Request
  */
 protected static function resetApp()
 {
     if (self::$app) {
         self::$app->useLayout(true);
         self::$app->resetRouter();
     }
     Proxy\Auth::clearIdentity();
     Proxy\Messages::popAll();
     Proxy\Request::setInstance(RequestFactory::fromGlobals());
     Proxy\Response::setInstance(new Bluz\Response\Response());
 }
Beispiel #5
0
 /**
  * send
  *
  * @throws NotAcceptableException
  */
 public function send()
 {
     $body = $this->getBody();
     $this->sendCookies();
     switch (true) {
         case 'CLI' == $this->type:
             // CLI response
             $response = new CliResponse($body->render('CLI'), $this->getStatusCode());
             break;
         case is_null($body):
         case 204 == $this->getStatusCode():
             $response = new EmptyResponse($this->getStatusCode(), $this->getHeaders());
             break;
         case 301 == $this->getStatusCode():
         case 302 == $this->getStatusCode():
             $response = new RedirectResponse($this->getHeader('Location'), $this->getStatusCode(), $this->getHeaders());
             break;
         case 'JSON' == $this->type:
             // JSON response
             // setup messages
             if (Messages::count()) {
                 $this->setHeader('Bluz-Notify', json_encode(Messages::popAll()));
             }
             // encode body data to JSON
             $response = new JsonResponse($body, $this->getStatusCode(), $this->getHeaders());
             break;
         case 'HTML' == $this->type:
         default:
             // HTML response
             $response = new HtmlResponse((string) $body, $this->getStatusCode(), $this->getHeaders());
             break;
     }
     $emitter = new SapiEmitter();
     $emitter->emit($response);
 }
Beispiel #6
0
 /**
  * Test Messages container
  */
 public function testMessagesPopAllForEmpty()
 {
     $messages = Proxy\Messages::popAll();
     $this->assertArrayHasKey('error', $messages);
     $this->assertArrayHasKey('notice', $messages);
     $this->assertArrayHasKey('success', $messages);
 }