コード例 #1
0
ファイル: Container.php プロジェクト: syrma-php/web-container
 /**
  * @param RequestHandlerInterface|callable $requestHandler
  *
  * @return Executor
  */
 public function createExecutor($requestHandler)
 {
     if (is_callable($requestHandler)) {
         $requestHandler = new CallbackRequestHandler($requestHandler);
     } elseif (!$requestHandler instanceof RequestHandlerInterface) {
         throw new \InvalidArgumentException(sprintf('Expected argument of type "RequestHandlerInterface" or "callable", "%s" given', is_object($requestHandler) ? get_class($requestHandler) : gettype($requestHandler)));
     }
     $executor = new Executor($this->getServer(), $requestHandler, $this->getExceptionHandler());
     $executor->setLogger($this->getLogger());
     return $executor;
 }
コード例 #2
0
 public function testExecuteWithExceptionAndInternalException()
 {
     $startFn = function (ServerContextInterface $context, RequestHandlerInterface $requestHandler) {
         $request = $this->getMock(Requestinterface::class);
         /* @var RequestInterface $request */
         $response = $requestHandler->handle($request);
         $this->assertEquals('TestContent', (string) $response->getBody());
     };
     $stopCounter = 0;
     $stopFn = function () use(&$stopCounter) {
         ++$stopCounter;
     };
     $requestHandler = new CallbackRequestHandler(function () {
         $stream = new Stream('php://temp', 'r+');
         $stream->write('TestContent');
         throw new \RuntimeException('', 0, new ServerStopWithResponseException(new Response($stream), 'FooBar'));
     });
     $executor = new Executor(new ServerStub($startFn, $stopFn), $requestHandler, new ExceptionHandlerStub());
     $executor->execute(new ServerContext());
     $this->assertEquals(1, $stopCounter);
 }