src/Chiron/Routing/Resolver/ControllerResolver.php
public function resolve($toResolve): callable
    {
        $resolved = $toResolve;

        if (! is_callable($toResolve) && is_string($toResolve)) {
            $class = $toResolve;
            $method = '__invoke';

            // check for chiron callable as "class@method"
            if (preg_match(static::PATTERN, $toResolve, $matches)) {
                $class = $matches[1];
                $method = $matches[2];
            }
            // check if the class is present un the container
            if ($this->container instanceof ContainerInterface && $this->container->has($class)) {
                $class = $this->container->get($class);
            } else {
                // if not present, try to instantitate it with the autoloader
                if (! class_exists($class)) {
                    throw new \RuntimeException(sprintf('Callable "%s" does not exist', $class));
                }
                // do not instantiate the classe when you use the magic method for generic static methods.
                // TODO : regarder si il est possible d'améliorer le code comme ca => https://github.com/middlewares/utils/blob/master/src/RequestHandlerContainer.php#L84
                // TODO : ou comme ici => https://github.com/PHP-DI/Invoker/blob/master/src/CallableResolver.php#L122
                if (! method_exists($class, '__callStatic')) {
                    $class = new $class();
                }
            }

            // For a class that implements RequestHandlerInterface, we will call the handle() method.
            if ($class instanceof RequestHandlerInterface) {
                $method = 'handle';
            }

            $resolved = [$class, $method];
        }

        if (! is_callable($resolved)) {
            throw new \InvalidArgumentException(sprintf(
                '(%s) is not resolvable.',
                is_array($toResolve) || is_object($toResolve) || is_null($toResolve) ? json_encode($toResolve) : $toResolve
            ));
        }

        return $resolved;
    }
public function resolve($toResolve): callable
    {
        $resolved = $toResolve;

        if (! is_callable($toResolve) && is_string($toResolve)) {
            $class = $toResolve;
            $method = '__invoke';

            // check for chiron callable as "class@method"
            if (preg_match(static::PATTERN, $toResolve, $matches)) {
                $class = $matches[1];
                $method = $matches[2];
            }
            // check if the class is present un the container
            if ($this->container instanceof ContainerInterface && $this->container->has($class)) {
                $class = $this->container->get($class);
            } else {
                // if not present, try to instantitate it with the autoloader
                if (! class_exists($class)) {
                    throw new \RuntimeException(sprintf('Callable "%s" does not exist', $class));
                }
                // do not instantiate the classe when you use the magic method for generic static methods.
                // TODO : regarder si il est possible d'améliorer le code comme ca => https://github.com/middlewares/utils/blob/master/src/RequestHandlerContainer.php#L84
                // TODO : ou comme ici => https://github.com/PHP-DI/Invoker/blob/master/src/CallableResolver.php#L122
                if (! method_exists($class, '__callStatic')) {
                    $class = new $class();
                }
            }

            // For a class that implements RequestHandlerInterface, we will call the handle() method.
            if ($class instanceof RequestHandlerInterface) {
                $method = 'handle';
            }

            $resolved = [$class, $method];
        }

        if (! is_callable($resolved)) {
            throw new \InvalidArgumentException(sprintf(
                '(%s) is not resolvable.',
                is_array($toResolve) || is_object($toResolve) || is_null($toResolve) ? json_encode($toResolve) : $toResolve
            ));
        }

        return $resolved;
    }
public function resolve ( $ toResolve ) : callable { $ resolved = $ toResolve ; if ( ! is_callable ( $ toResolve ) && is_string ( $ toResolve ) ) { $ class = $ toResolve ; $ method = '__invoke' ; // check for chiron callable as "class@method" if ( preg_match ( static :: PATTERN , $ toResolve , $ matches ) ) { $ class = $ matches [ 1 ] ; $ method = $ matches [ 2 ] ; } // check if the class is present un the container if ( $ this -> container instanceof ContainerInterface && $ this -> container -> has ( $ class ) ) { $ class = $ this -> container -> get ( $ class ) ; } else { // if not present, try to instantitate it with the autoloader if ( ! class_exists ( $ class ) ) { throw new \ RuntimeException ( sprintf ( 'Callable "%s" does not exist' , $ class ) ) ; } // do not instantiate the classe when you use the magic method for generic static methods. // TODO : regarder si il est possible d'améliorer le code comme ca => https://github.com/middlewares/utils/blob/master/src/RequestHandlerContainer.php#L84 // TODO : ou comme ici => https://github.com/PHP-DI/Invoker/blob/master/src/CallableResolver.php#L122 if ( ! method_exists ( $ class , '__callStatic' ) ) { $ class = new $ class ( ) ; } } // For a class that implements RequestHandlerInterface, we will call the handle() method. if ( $ class instanceof RequestHandlerInterface ) { $ method = 'handle' ; } $ resolved = [ $ class , $ method ] ; } if ( ! is_callable ( $ resolved ) ) { throw new \ InvalidArgumentException ( sprintf ( '(%s) is not resolvable.' , is_array ( $ toResolve ) || is_object ( $ toResolve ) || is_null ( $ toResolve ) ? json_encode ( $ toResolve ) : $ toResolve ) ) ; } return $ resolved ; }
Resolve toResolve into a callable that that the router can dispatch.

If toResolve is of the format 'class@method', then try to extract 'class'
from the container otherwise instantiate it and then dispatch 'method'.

@param callable|string $toResolve

@throws \RuntimeException         if the callable does not exist
@throws \InvalidArgumentException if the callable is not resolvable

@return callable
Resolve toResolve into a callable that that the router can dispatch .