public function route(string $method, string $pattern, $handler, $name = null, ?RouteInfo $info = null): void
    {
        if ($name instanceof RouteInfo) {
            $info = $name;
            $name = '@' . Route::nextId();
        } elseif ($name === null) {
            $name = '@' . Route::nextId();
        } elseif ($name === '' || $name[0] == '@' || false !== \strpos($name, ':')) {
            throw new \InvalidArgumentException(\sprintf('Invalid route name: "%s"', $name));
        }
        
        if (!$handler instanceof RequestHandlerInterface && !\is_string($handler) && !\is_callable($handler)) {
            $type = \is_object($handler) ? \get_class($handler) : \gettype($handler);
            
            throw new \InvalidArgumentException(\sprintf('Unsupported route handler type: %s', $type));
        }
        
        if (isset($this->routes[$name])) {
            throw new \RuntimeException(\sprintf('Duplicate registration of named route: "%s"', $name));
        }
        
        $produces = $info ? $info->getProducedTypes() : null;
        $consumes = $info ? $info->getConsumedTypes() : null;
        
        $this->routes[$name] = new Route($method, '/' . \trim($pattern, '/'), $handler, $name, $produces, $consumes);
    }
public function route(string $method, string $pattern, $handler, $name = null, ?RouteInfo $info = null): void
    {
        if ($name instanceof RouteInfo) {
            $info = $name;
            $name = '@' . Route::nextId();
        } elseif ($name === null) {
            $name = '@' . Route::nextId();
        } elseif ($name === '' || $name[0] == '@' || false !== \strpos($name, ':')) {
            throw new \InvalidArgumentException(\sprintf('Invalid route name: "%s"', $name));
        }
        
        if (!$handler instanceof RequestHandlerInterface && !\is_string($handler) && !\is_callable($handler)) {
            $type = \is_object($handler) ? \get_class($handler) : \gettype($handler);
            
            throw new \InvalidArgumentException(\sprintf('Unsupported route handler type: %s', $type));
        }
        
        if (isset($this->routes[$name])) {
            throw new \RuntimeException(\sprintf('Duplicate registration of named route: "%s"', $name));
        }
        
        $produces = $info ? $info->getProducedTypes() : null;
        $consumes = $info ? $info->getConsumedTypes() : null;
        
        $this->routes[$name] = new Route($method, '/' . \trim($pattern, '/'), $handler, $name, $produces, $consumes);
    }
public function route ( string $ method , string $ pattern , $ handler , $ name = null , ? RouteInfo $ info = null ) : void { if ( $ name instanceof RouteInfo ) { $ info = $ name ; $ name = '@' . Route :: nextId ( ) ; } elseif ( $ name === null ) { $ name = '@' . Route :: nextId ( ) ; } elseif ( $ name === '' || $ name [ 0 ] == '@' || false !== \ strpos ( $ name , ':' ) ) { throw new \ InvalidArgumentException ( \ sprintf ( 'Invalid route name: "%s"' , $ name ) ) ; } if ( ! $ handler instanceof RequestHandlerInterface && ! \ is_string ( $ handler ) && ! \ is_callable ( $ handler ) ) { $ type = \ is_object ( $ handler ) ? \ get_class ( $ handler ) : \ gettype ( $ handler ) ; throw new \ InvalidArgumentException ( \ sprintf ( 'Unsupported route handler type: %s' , $ type ) ) ; } if ( isset ( $ this -> routes [ $ name ] ) ) { throw new \ RuntimeException ( \ sprintf ( 'Duplicate registration of named route: "%s"' , $ name ) ) ; } $ produces = $ info ? $ info -> getProducedTypes ( ) : null ; $ consumes = $ info ? $ info -> getConsumedTypes ( ) : null ; $ this -> routes [ $ name ] = new Route ( $ method , '/' . \ trim ( $ pattern , '/' ) , $ handler , $ name , $ produces , $ consumes ) ; }
Register a route with the resource.

@param string $method HTTP request method to be handled.
@param string $pattern Path pattern to be matched.
@param callable|RequestHandlerInterface|string $handler Callable or PSR request handler (or a fully-qualified name to load handler using the DI contaienr).
@param string|RouteInfo $name Unique name of the route (can also accept RouteInfo for unnamed routes).
@param RouteInfo $info Additonal route info being used during content negotiation.

@throws \InvalidArgumentException When an invalid route name or handler is given.
@throws \RuntimeException When the given route name is already in use.
Register a route with the resource .