Phprest\Application::handle PHP Method

handle() public method

Handle the request.
public handle ( Request $request, integer $type = self::MASTER_REQUEST, boolean $catch = true ) : Response
$request Symfony\Component\HttpFoundation\Request
$type integer
$catch boolean
return Symfony\Component\HttpFoundation\Response
    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        // Passes the request to the container
        $this->getContainer()->add('Symfony\\Component\\HttpFoundation\\Request', $request);
        try {
            $this->emit('request.received', $request);
            $dispatcher = $this->getRouter()->getDispatcher();
            $response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo());
            $this->emit('response.created', $request, $response);
            return $response;
        } catch (\Exception $e) {
            if (!$catch) {
                throw $e;
            }
            $response = call_user_func($this->exceptionDecorator, $e);
            if (!$response instanceof Response) {
                throw new \LogicException('Exception decorator did not return an instance of Symfony\\Component\\HttpFoundation\\Response');
            }
            $this->emit('response.created', $request, $response);
            return $response;
        }
    }

Usage Example

Example #1
0
 /**
  * @param BaseRequest $request
  * @param int $type
  * @param bool $catch
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handle(BaseRequest $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $request = new Request($request);
     $mimeProcResult = $this->processMime((new FormatNegotiator())->getBest($request->headers->get('Accept', '*/*'))->getValue());
     $request->setApiVersion(str_pad($mimeProcResult->apiVersion, 3, '.0'));
     return $this->app->handle($request, $type, $catch);
 }