Exemplo n.º 1
0
 /**
  * @param Throwable $e
  *
  * @return ErrorResponse
  */
 public function render(Throwable $e) : ErrorResponse
 {
     if ($this->app->isLocal()) {
         return $this->whoops->render($e);
     } else {
         return $this->formatter->render($e);
     }
 }
Exemplo n.º 2
0
 public function test_run_a_request_through_the_stack()
 {
     $this->app->shouldReceive('getContainer')->andReturn($this->container);
     $this->container->shouldReceive('make')->with(ReturnNext::class)->once()->andReturn(new ReturnNext());
     $this->container->shouldReceive('make')->with(ReturnSomeResponse::class)->once()->andReturn(new ReturnSomeResponse());
     $response = $this->stack->run($this->request)->through([ReturnNext::class, ReturnSomeResponse::class]);
     $this->assertEquals('Html body', $response->body());
 }
Exemplo n.º 3
0
 /**
  * @return callable
  */
 protected function send() : callable
 {
     return function ($next, $pipe) {
         $run = $this->app->getContainer()->make($pipe);
         return $run($this->request, function () use($next) {
             return $next;
         });
     };
 }
Exemplo n.º 4
0
 /**
  * @param Application $app
  *
  * @return array
  */
 private function getConfigFiles(Application $app) : array
 {
     $files = [];
     $configPath = realpath($app->configPath());
     foreach (new RegexIterator(new DirectoryIterator($configPath), "/\\.php\$/i") as $file) {
         $files[basename($file->getRealPath(), '.php')] = $file->getRealPath();
     }
     return $files;
 }
Exemplo n.º 5
0
 /**
  * @param Application $app
  */
 public function bootstrap(Application $app)
 {
     foreach ($app->getRegistry()->getDefinitions() as $abstract => $concrete) {
         if (is_string($concrete) || is_callable($concrete)) {
             $this->container->bind($abstract, $concrete);
         } else {
             $this->container->instance($abstract, $concrete);
         }
     }
 }
Exemplo n.º 6
0
 /**
  * @param Router $router
  *
  * @return mixed
  */
 public function loadRoutes(Router $router)
 {
     $binders = $this->config->get($this->app->getContext() . '.routes', []);
     foreach ($binders as $binder) {
         if (!class_exists($binder)) {
             throw new InvalidArgumentException('RouteBinder [' . $binder . '] does not exist');
         }
         $this->container->make($binder)->bind($router);
     }
 }
Exemplo n.º 7
0
 private function setUpDependencies(bool $fail = false)
 {
     $dispatcher = \Mockery::mock(DispatchRequest::class);
     $dispatcher->shouldReceive('__invoke')->once()->andReturn($response = new Response(new ZendResponse()));
     $container = \Mockery::mock(Container::class);
     $container->shouldReceive('make')->with(Request::class)->andReturn(\Mockery::mock(Request::class));
     $container->shouldReceive('make')->with(DispatchRequest::class)->once()->andReturn($dispatcher);
     $this->app->shouldReceive('getContainer')->andReturn($container);
     $this->app->shouldReceive('setExceptionRunner')->once()->with(\Mockery::type(ExceptionRunner::class));
     $this->app->shouldReceive('setContext')->once()->with('web');
     $this->app->shouldReceive('bootstrap')->once();
     if ($fail) {
         $this->emitter->shouldReceive('emit')->andThrow(\InvalidArgumentException::class);
     } else {
         $this->emitter->shouldReceive('emit')->with($response, 1)->once();
     }
 }
Exemplo n.º 8
0
 /**
  * @param Application $app
  */
 public function bootstrap(Application $app)
 {
     $this->loader->load($app->path());
 }
Exemplo n.º 9
0
 /**
  * Returns the definition to register in the container.
  *
  * Definitions must be indexed by their entry ID. For example:
  *
  *     return [
  *         'logger' => ...
  *         'mailer' => ...
  *     ];
  *
  * @return array
  */
 public function getDefinitions()
 {
     return [CommandBus::class => function () {
         return new TacticianBus($this->app->getContainer(), [new CommandHandlerMiddleware(new ClassNameExtractor(), new HandlerLocator($this->app->getContainer()), new HandleInflector())]);
     }];
 }
Exemplo n.º 10
0
 /**
  * @param Throwable $e
  * @param           $handler
  */
 private function handle(Throwable $e, $handler)
 {
     $handler = $this->app->getContainer()->make($handler);
     $handler->handle($e);
 }
Exemplo n.º 11
0
 /**
  * @return Request
  */
 protected function request() : Request
 {
     return $this->app->getContainer()->make(Request::class);
 }
Exemplo n.º 12
0
 /**
  * Returns the definition to register in the container.
  *
  * Definitions must be indexed by their entry ID. For example:
  *
  *     return [
  *         'logger' => ...
  *         'mailer' => ...
  *     ];
  *
  * @return array
  */
 public function getDefinitions()
 {
     return [FactoryContract::class => function () {
         return new TwigFactory(new Twig_Environment(new Twig_Loader_Filesystem($this->app->viewsPath()), ['cache' => $this->app->storagePath('views')]));
     }];
 }