/** * {@inheritdoc} */ public function getController(Request $request) { if (!($controller = $request->attributes->get('_controller'))) { throw new \LogicException(sprintf('Controller for URI "%s" could not be found because the "_controller" parameter is missing.', $request->getPathInfo())); } try { return $this->callableResolver->resolve($controller); } catch (NotCallableException $e) { throw new \InvalidArgumentException(sprintf('Controller for URI "%s" is not callable: %s', $request->getPathInfo(), $e->getMessage())); } }
/** * @param string $name * @return array|callable */ public function convertCallback($name) { // original pattern if ($this->isValid($name)) { return parent::convertCallback($name); } // try to resolve callback from container try { return $this->resolver->resolve($name); } catch (NotCallableException $e) { throw new \InvalidArgumentException($e->getMessage()); } }
/** * {@inheritdoc} */ public function call($callable, array $parameters = array()) { if ($this->callableResolver) { $callable = $this->callableResolver->resolve($callable); } if (!is_callable($callable)) { throw new NotCallableException(sprintf('%s is not a callable', is_object($callable) ? 'Instance of ' . get_class($callable) : var_export($callable, true))); } $callableReflection = CallableReflection::create($callable); $args = $this->parameterResolver->getParameters($callableReflection, $parameters, array()); // Sort by array key because call_user_func_array ignores numeric keys ksort($args); // Check all parameters are resolved $diff = array_diff_key($callableReflection->getParameters(), $args); if (!empty($diff)) { /** @var \ReflectionParameter $parameter */ $parameter = reset($diff); throw new NotEnoughParametersException(sprintf('Unable to invoke the callable because no value was given for parameter %d ($%s)', $parameter->getPosition() + 1, $parameter->name)); } return call_user_func_array($callable, $args); }
/** * {@inheritdoc} */ public function resolve($toResolve) { return $this->callableResolver->resolve($toResolve); }