/**
  * Create a RoutePathCompilationException from a route
  * and an optional previous exception
  *
  * @param Route $route          The route that failed to compile
  * @param Exception $previous   The previous exception
  * @return RoutePathCompilationException
  */
 public static function createFromRoute(Route $route, Exception $previous = null)
 {
     $error = null !== $previous ? $previous->getMessage() : null;
     $code = null !== $previous ? $previous->getCode() : null;
     $message = sprintf(static::MESSAGE_FORMAT, $route->getPath());
     $message .= ' ' . sprintf(static::FAILURE_MESSAGE_TITLE_FORMAT, $error);
     $exception = new static($message, $code, $previous);
     $exception->setRoute($route);
     return $exception;
 }
Beispiel #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 array $methods_matched
  * @return void
  */
 protected function handleRouteCallback(Route $route, RouteCollection $matched, array $methods_matched)
 {
     // Handle the callback
     $returned = call_user_func($route->getCallback(), $this->request, $this->response, $this->service, $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
         }
     }
 }
Beispiel #3
0
 public function testGetPathFor()
 {
     // Test data
     $test_path = '/test';
     $test_name = 'Test Route Thing';
     $route = new Route($this->getTestCallable());
     $route->setPath($test_path);
     $route->setName($test_name);
     $this->klein_app->routes()->addRoute($route);
     // Make sure it fails if not prepared
     try {
         $this->klein_app->getPathFor($test_name);
     } catch (Exception $e) {
         $this->assertTrue($e instanceof OutOfBoundsException);
     }
     $this->klein_app->routes()->prepareNamed();
     $returned_path = $this->klein_app->getPathFor($test_name);
     $this->assertNotEmpty($returned_path);
     $this->assertSame($test_path, $returned_path);
 }
Beispiel #4
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
  * @access protected
  * @return void
  */
 protected function handleRouteCallback(Route $route, RouteCollection $matched, $methods_matched)
 {
     // Handle the callback
     try {
         $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
             }
         }
     } catch (DispatchHaltedException $e) {
         throw $e;
     } catch (HttpExceptionInterface $e) {
         // Call our http error handlers
         $this->httpError($e, $matched, $methods_matched);
         throw new DispatchHaltedException();
     } catch (Exception $e) {
         $this->error($e);
     }
 }
Beispiel #5
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testMethodSetWithIncorrectType()
 {
     $route = new Route($this->getTestCallable());
     // Test setting with the WRONG type
     $route->setMethod(100);
 }