public function testCreateFromRequestDebug()
 {
     $request = new Request(2, 'My.Action', 'method', array(1, 2, 3), false, false);
     $e = new \RuntimeException('This is my exception', 1);
     $response = ExceptionResponse::fromRequest($request, $e, true);
     $this->assertStringStartsWith('{"type":"exception","tid":2,"action":"My.Action","method":"method","where":"#0', json_encode($response));
 }
Exemple #2
0
 /**
  * @param RequestCollection $directRequest
  * @param HttpRequest       $httpRequest
  * @return ResponseCollection
  */
 public function handle(RequestCollection $directRequest, HttpRequest $httpRequest)
 {
     $this->dispatchEvent(RouterEvents::BEGIN_REQUEST, new BeginRequestEvent($directRequest, $httpRequest));
     $invocations = $this->prepareInvocation($directRequest, $httpRequest);
     $responses = array();
     foreach ($invocations as $invocation) {
         /** @var ServiceReference $service */
         /** @var array $arguments */
         list($service, $arguments, $singleRequest) = $invocation;
         try {
             $result = $this->invokeService($service, $arguments, $singleRequest, $httpRequest);
             if ($result instanceof Response) {
                 $responses[] = $result;
             } else {
                 $responses[] = RPCResponse::fromRequest($singleRequest, $result);
             }
         } catch (\Exception $e) {
             /** @var ExceptionEvent $exceptionEvent */
             $exceptionEvent = $this->dispatchEvent(RouterEvents::EXCEPTION, new ExceptionEvent($singleRequest, $httpRequest, $e, ExceptionResponse::fromRequest($singleRequest, $e, $this->debug), isset($service) ? $service : null, isset($arguments) ? $arguments : null));
             $responses[] = $exceptionEvent->getResponse();
         }
     }
     /** @var EndRequestEvent $endRequestEvent */
     $endRequestEvent = $this->dispatchEvent(RouterEvents::END_REQUEST, new EndRequestEvent($directRequest, new ResponseCollection($responses), $httpRequest));
     return $endRequestEvent->getDirectResponse();
 }