/** * Resolve constructor or method arguments * * @param array $arguments * @return array */ protected function resolveArguments(array $arguments) { $resolved = []; foreach ($arguments as $argument) { if (is_string($argument) && $this->container->has($argument)) { $resolved[] = $this->container->get($argument); } else { $resolved[] = $argument; } } return $resolved; }
public function __invoke($abstract, $concrete, ContainerInterface $container) { if ($concrete instanceof \Closure) { return new CallableDefinition($abstract, $concrete, $container); } if (is_string($concrete) && $container->has($concrete)) { $container->alias($concrete, $abstract); return; } if (is_string($concrete) && class_exists($concrete)) { return new ClassDefinition($abstract, $concrete, $container); } return $concrete; }
/** * Handle a found route * * @param string|\Closure $handler * @param array $params * @return \Symfony\Component\HttpFoundation\Response */ protected function handleFoundRoute($handler, array $params) { $response = null; if ($handler instanceof \Closure || is_callable($handler)) { $response = call_user_func_array($handler, $params); } if (is_string($handler) && strpos($handler, '@') == true) { list($controller, $method) = explode('@', $handler); $resolved = $this->container->get($controller); $response = call_user_func_array([$resolved, $method], $params); } if (is_null($response)) { throw new \RuntimeException('No method was found in the class name string. Format: ClassName@method'); } return new Response($response); }
/** * Create the listener * * @param callable|string $listener * @return mixed */ protected function createListener($listener) { if (is_string($listener)) { return function () use($listener) { $segments = explode('@', $listener); $resolved = $this->container->get($segments[0]); $method = count($segments) == 2 ? $segments[1] : 'handle'; return call_user_func_array([$resolved, $method], func_get_args()); }; } return $listener; }