/** * @inheritDoc */ public function resolveArguments(ReflectionFunctionAbstract $function) : Closure { $parameters = $function->getParameters(); return function (array $arguments = []) use($function, $parameters) { // Use passed arguments in place of reflected parameters. $provided = array_intersect_key($arguments, $parameters); // Remaining parameters will be resolved by container. $remaining = array_diff_key($parameters, $arguments); $resolved = array_map(function (ReflectionParameter $parameter) use($function) { // Recursively resolve function arguments. $class = $parameter->getClass(); if ($class !== null && $this->container->has($class->getName())) { return $this->container->get($class->getName()); } // Use argument default value if possible. if ($parameter->isDefaultValueAvailable()) { return $parameter->getDefaultValue(); } // The argument can't be resolved by this resolver. throw new ArgumentResolverException($parameter, $function); }, $remaining); $arguments = $provided + $resolved; // Sort combined result array by parameter indexes. ksort($arguments); return $arguments; }; }
/** * Passes exception to error handler before rendering to output * * @param Exception $e * @param OutputInterface $output * @return void */ public function renderException(Exception $e, OutputInterface $output) { if ($this->container->has('error_handler')) { /** @var \Whoops\RunInterface $run */ $run = $this->container->get('error_handler'); // from now on ConsoleApplication will render exception $run->allowQuit(false); $run->writeToOutput(false); // Ignore the return string, parent call will render exception $run->handleException($e); } parent::renderException($e, $output); }
/** * @inheritDoc */ public function next(ServerRequestInterface $request) : ResponseInterface { if (!$request instanceof RequestContract) { // Decorate PSR-7 ServerRequest. $request = new Request($request); } if ($this->container->isCallable($this->route->getDomain())) { if ($this->container->has($this->route->getInput())) { /** @var Input $input */ $input = $this->container->get($this->route->getInput()); $arguments = $input->process($request); } /** @var Payload $payload */ $payload = $this->container->call($this->route->getDomain(), $arguments ?? []); } /** @var Responder $responder */ $responder = $this->container->get($this->route->getResponder()); return $responder->run($request, $payload ?? null); }