Ejemplo n.º 1
0
 public function testLockedNotModifiable()
 {
     $response = new Response();
     $response->lock();
     // Get initial values
     $protocol_version = $response->protocolVersion();
     $body = $response->body();
     $code = $response->code();
     // Attempt to modify
     try {
         $response->protocolVersion('2.0');
     } catch (LockedResponseException $e) {
     }
     try {
         $response->body('WOOT!');
     } catch (LockedResponseException $e) {
     }
     try {
         $response->code(204);
     } catch (LockedResponseException $e) {
     }
     try {
         $response->prepend('cat');
     } catch (LockedResponseException $e) {
     }
     try {
         $response->append('dog');
     } catch (LockedResponseException $e) {
     }
     // Assert nothing has changed
     $this->assertSame($protocol_version, $response->protocolVersion());
     $this->assertSame($body, $response->body());
     $this->assertSame($code, $response->code());
 }
Ejemplo n.º 2
0
 /**
  * Handle a route's callback
  *
  * This handles common exceptions and their output
  * to keep the "dispatch()" method DRY
  *
  * @param Route $route
  * @param RouteCollection $matched
  * @param int $methods_matched
  * @return void
  */
 protected function handleRouteCallback(Route $route, RouteCollection $matched, $methods_matched)
 {
     // Handle the callback
     $returned = call_user_func($route->getCallback(), $this->request, $this->response, $this->app, $this, $matched, $methods_matched);
     if ($returned instanceof AbstractResponse) {
         $this->response = $returned;
     } else {
         // Otherwise, attempt to append the returned data
         try {
             $this->response->append($returned);
         } catch (LockedResponseException $e) {
             // Do nothing, since this is an automated behavior
         }
     }
 }