Пример #1
0
 /**
  * use stacked kernel to include middlewares
  *
  * @return \Stack\StackedHttpKernel
  */
 protected function getStackedKernel()
 {
     /** @see \Illuminate\Foundation\Application::getStackedClient */
     $middlewaresProperty = new \ReflectionProperty($this->kernel, 'middlewares');
     $middlewaresProperty->setAccessible(true);
     $middlewares = $middlewaresProperty->getValue($this->kernel);
     $stack = new Builder();
     foreach ($middlewares as $middleware) {
         list($class, $parameters) = array_values($middleware);
         array_unshift($parameters, $class);
         call_user_func_array(array($stack, 'push'), $parameters);
     }
     return $stack->resolve($this->kernel);
 }
Пример #2
0
 /**
  * @param Request $request
  */
 public function run(Request $request = null)
 {
     /**
      * resolve stack middleware for our apps
      */
     $app = $this->builder->resolve($this);
     /**
      * override current apps with stacked http kernel
      */
     if ($request === null) {
         $request = Request::createFromGlobals();
     }
     $response = $app->handle($request);
     $response->send();
     $this->terminate($request, $response);
 }
Пример #3
0
 public function testWithAppendMiddlewares()
 {
     $app = new Application();
     $app->get('/foo', function () {
         return 'bar';
     });
     $finished = false;
     $app->finish(function () use(&$finished) {
         $finished = true;
     });
     $stack = new Builder();
     $stack->push('functional\\Append', '.A')->push('functional\\Append', '.B');
     $app = $stack->resolve($app);
     $request = Request::create('/foo');
     $response = $app->handle($request);
     $app->terminate($request, $response);
     $this->assertSame('bar.B.A', $response->getContent());
     $this->assertTrue($finished);
 }
Пример #4
0
 /**
  * Run the application
  *
  * @param Request $request
  *
  * @return string
  */
 public function run(Request $request = null)
 {
     if (null === $request) {
         $request = Request::createFromGlobals();
     }
     $this->registerMiddleware('Phprest\\Middleware\\ApiVersion');
     $app = $this->stackBuilder->resolve($this);
     $response = $app->handle($request, self::MASTER_REQUEST, false);
     $response->send();
     $app->terminate($request, $response);
 }
Пример #5
0
 /**
  * @param Request $request
  * @param         $type
  */
 private function doRun(Request $request, $type)
 {
     if (false === $this->isResolved) {
         $this->resolvedApp = $this->builder->resolve($this);
         $this->isResolved = true;
     }
     $request = $request ?: Request::createFromGlobals();
     $response = $this->resolvedApp->handle($request, $type);
     $response->send();
     if ($this->resolvedApp instanceof TerminableInterface) {
         $this->resolvedApp->terminate($request, $response);
     }
 }
Пример #6
0
 /**
  * Return the StackPHP stack.
  * @param Builder $stack
  * @return Builder
  */
 public function getStack(Builder $stack)
 {
     $sessionReject = $this->app->bound('session.reject') ? $this->app['session.reject'] : null;
     $stack->push('Illuminate\\Cookie\\Guard', $this->app['encrypter'])->push('Illuminate\\Cookie\\Queue', $this->app['cookie'])->push('Illuminate\\Session\\Middleware', $this->app['session'], $sessionReject);
     return $stack;
 }
 /** @test */
 public function resolveShouldCallSpecFactories()
 {
     $app = $this->getHttpKernelMock(new Response('ok'));
     $stack = new Builder();
     $stack->push(function ($app) {
         return new Append($app, '.foo');
     });
     $stack->push(function ($app) {
         return new Append($app, '.bar');
     });
     $resolved = $stack->resolve($app);
     $request = Request::create('/');
     $response = $resolved->handle($request);
     $this->assertSame('ok.bar.foo', $response->getContent());
 }
 public function testStackInterceptionWithExceptionCallback()
 {
     $app = new CallableHttpKernel(function (Request $request) {
         return new Response('did not get intercepted');
     });
     //the interceptor will now return a SnapSearchException
     $interceptor = Stub::make('SnapSearchClientPHP\\Interceptor', array('detector' => Stub::make('SnapSearchClientPHP\\Detector', array('request' => function () {
         return true;
     })), 'intercept' => function () {
         throw new SnapSearchException('Oh no something went wrong!');
     }));
     $stack = new Builder();
     //just making sure the callback was actually called, this will be late binded
     $was_this_called = false;
     //making tests compatible with php 5.3
     $self = $this;
     //snapsearch layer
     $stack->push('SnapSearchClientPHP\\StackInterceptor', $interceptor, null, function ($exception, $request) use(&$was_this_called, $self) {
         //the SnapSearchException will be received here
         $self->assertInstanceOf('SnapSearchClientPHP\\SnapSearchException', $exception);
         $self->assertEquals('Oh no something went wrong!', $exception->getMessage());
         //the request object will also be available if something failed
         $self->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Request', $request);
         $was_this_called = true;
     });
     //random layer underneath that will be called because exceptions are ignored in production
     $stack->push(function ($app) {
         return new CallableHttpKernel(function () {
             return new Response('random layer', 200);
         });
     });
     $app = $stack->resolve($app);
     $this->app = $app;
     $request = Request::create('/');
     $response = $this->app->handle($request);
     $this->assertTrue($was_this_called);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('random layer', $response->getContent());
 }