コード例 #1
0
 /**
  * @inheritDoc
  */
 protected function getParsedBody($body)
 {
     $body = json_decode($body, true);
     if (json_last_error() !== \JSON_ERROR_NONE) {
         $message = 'JSON ' . json_last_error_msg();
         throw HttpException::badRequest($message);
     }
     return $body;
 }
コード例 #2
0
ファイル: DispatchHandler.php プロジェクト: curtis1000/spark
 /**
  * @param Dispatcher $dispatcher
  * @param string $method
  * @param string $path
  *
  * @return [Action, $arguments]
  *
  * @throws HttpNotFound
  * @throws HttpMethodNotAllowed
  */
 private function dispatch(Dispatcher $dispatcher, $method, $path)
 {
     $route = $dispatcher->dispatch($method, $path);
     $status = array_shift($route);
     if (Dispatcher::FOUND === $status) {
         return $route;
     }
     if (Dispatcher::METHOD_NOT_ALLOWED === $status) {
         $allowed = array_shift($route);
         throw HttpException::methodNotAllowed($path, $method, $allowed);
     }
     throw HttpException::notFound($path);
 }
コード例 #3
0
ファイル: RouteHandler.php プロジェクト: mikegreiling/spark
 /**
  * @param  string $method
  * @param  string $path
  * @return array [$route, $arguments]
  * @throws HttpNotFound
  * @throws HttpMethodNotAllowed
  */
 public function dispatch($method, $path)
 {
     $routeInfo = $this->getDispatcher()->dispatch($method, $path);
     switch ($routeInfo[0]) {
         case Dispatcher::NOT_FOUND:
             throw HttpException::notFound($path);
         case Dispatcher::METHOD_NOT_ALLOWED:
             throw HttpException::methodNotAllowed($path, $method, $routeInfo[1]);
         case Dispatcher::FOUND:
             list(, $route, $arguments) = $routeInfo;
             break;
     }
     return [$route, $arguments];
 }