Beispiel #1
0
 public function test_it_can_resolve_a_given_type_from_the_container()
 {
     $abstract = 'abstract';
     $parameters = ['foo' => 'bar'];
     $this->wrappedMock->shouldReceive('make')->with($abstract, $parameters)->once()->andReturn('resolved');
     $this->assertEquals('resolved', $this->container->make($abstract, $parameters));
 }
Beispiel #2
0
 /**
  * Retrieves the handler for a specified command
  *
  * @param string $commandName
  *
  * @throws MissingHandlerException
  * @return object
  */
 public function getHandlerForCommand($commandName)
 {
     $handler = $this->getHandlerClassName($commandName);
     if (!class_exists($handler)) {
         throw MissingHandlerException::forCommand($commandName);
     }
     return $this->container->make($handler);
 }
 /**
  * @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);
     }
 }
Beispiel #4
0
 /**
  * Dispatch the request
  *
  * @param Route $route
  *
  * @throws NotFoundHttpException
  * @return mixed
  */
 public function dispatch(Route $route)
 {
     $action = $route->action();
     list($class, $method) = explode('@', $action['uses']);
     if (!method_exists($instance = $this->container->make($class), $method)) {
         throw new NotFoundHttpException();
     }
     $parameters = $this->resolver->resolve(new ReflectionMethod($instance, $method), $route->parameters());
     return $this->container->call([$instance, $method], $parameters);
 }
 /**
  * @param ReflectionFunctionAbstract $reflector
  * @param array                      $parameters
  *
  * @return mixed
  */
 public function resolve(ReflectionFunctionAbstract $reflector, array $parameters = []) : array
 {
     $reflected = $reflector->getParameters();
     $resolved = [];
     foreach ($reflected as $param) {
         if ($class = $param->getClass()) {
             $resolved[$param->name] = $this->container->make($class->name);
         } elseif (isset($parameters[$param->name])) {
             $resolved[$param->name] = $parameters[$param->name];
         }
     }
     return $resolved;
 }
Beispiel #6
0
 /**
  * Resolve the middleware stack from the laravel container
  * @param  array     $middleware
  * @param  Container $container
  * @return array
  */
 protected function resolveMiddleware(array $middleware = [], Container $container)
 {
     $m = [];
     foreach ($middleware as $class) {
         $m[] = $container->make($class);
     }
     return $m;
 }