Author: Matthieu Napoli (matthieu@mnapoli.fr)
 /**
  * {@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()));
     }
 }
Exemplo n.º 2
0
 /**
  * @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());
     }
 }
Exemplo n.º 3
0
 /**
  * {@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);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function resolve($toResolve)
 {
     return $this->callableResolver->resolve($toResolve);
 }