Overview
  • Namespace
  • Class

Namespaces

  • Slim
    • Exception
    • Handlers
      • Strategies
    • Http
    • Interfaces
      • Http

Classes

  • App
  • CallableResolver
  • Collection
  • Container
  • DefaultServicesProvider
  • DeferredCallable
  • Routable
  • Route
  • RouteGroup
  • Router

Traits

  • CallableResolverAwareTrait
  • MiddlewareAwareTrait

Class Router

Router

This class organizes Slim application route objects. It is responsible for registering route objects, assigning names to route objects, finding routes that match the current HTTP request, and creating URLs for a named route.

Slim\Router implements Slim\Interfaces\RouterInterface
Namespace: Slim
Located at Router.php

Methods summary

public
# __construct( FastRoute\RouteParser $parser = null )

Create new router

Create new router

Parameters

$parser
public Slim\Router
# setBasePath( string $basePath )

Set the base path used in pathFor()

Set the base path used in pathFor()

Parameters

$basePath

Returns

Slim\Router
public Slim\Router
# setCacheFile( string|false $cacheFile )

Set path to fast route cache file. If this is false then route caching is disabled.

Set path to fast route cache file. If this is false then route caching is disabled.

Parameters

$cacheFile

Returns

Slim\Router
public
# setContainer( Psr\Container\ContainerInterface $container )

Parameters

$container
public Slim\Interfaces\RouteInterface
# map( string[] $methods, string $pattern, callable $handler )

Add route

Add route

Parameters

$methods
Array of HTTP methods
$pattern
The route pattern
$handler
The route callable

Returns

Slim\Interfaces\RouteInterface

Throws

InvalidArgumentException
if the route pattern isn't a string

Implementation of

Slim\Interfaces\RouterInterface::map()
public array
# dispatch( Psr\Http\Message\ServerRequestInterface $request )

Dispatch router for HTTP request

Dispatch router for HTTP request

Parameters

$request
The current HTTP request object

Returns

array

Link

https://github.com/nikic/FastRoute/blob/master/src/Dispatcher.php

Implementation of

Slim\Interfaces\RouterInterface::dispatch()
protected Slim\Interfaces\RouteInterface
# createRoute( string[] $methods, string $pattern, callable $callable )

Create a new Route object

Create a new Route object

Parameters

$methods
Array of HTTP methods
$pattern
The route pattern
$callable
The route callable

Returns

Slim\Interfaces\RouteInterface
protected FastRoute\Dispatcher
# createDispatcher( )

Returns

FastRoute\Dispatcher
public
# setDispatcher( FastRoute\Dispatcher $dispatcher )

Parameters

$dispatcher
public Slim\Route[]
# getRoutes( )

Get route objects

Get route objects

Returns

Slim\Route[]
public Slim\Route
# getNamedRoute( string $name )

Get named route object

Get named route object

Parameters

$name
Route name

Returns

Slim\Route

Throws

RuntimeException
If named route does not exist

Implementation of

Slim\Interfaces\RouterInterface::getNamedRoute()
public
# removeNamedRoute( string $name )

Remove named route

Remove named route

Parameters

$name
Route name

Throws

RuntimeException
If named route does not exist
protected string
# processGroups( )

Process route groups

Process route groups

Returns

string
A group pattern to prefix routes with
public Slim\Interfaces\RouteGroupInterface
# pushGroup( string $pattern, callable $callable )

Add a route group to the array

Add a route group to the array

Parameters

$pattern
$callable

Returns

Slim\Interfaces\RouteGroupInterface

Implementation of

Slim\Interfaces\RouterInterface::pushGroup()
public Slim\RouteGroup|boolean
# popGroup( )

Removes the last route group from the array

Removes the last route group from the array

Returns

Slim\RouteGroup|boolean
The RouteGroup if successful, else False

Implementation of

Slim\Interfaces\RouterInterface::popGroup()
public Slim\Interfaces\RouteInterface
# lookupRoute( $identifier )

Parameters

$identifier

Returns

Slim\Interfaces\RouteInterface

Implementation of

Slim\Interfaces\RouterInterface::lookupRoute()
public string
# relativePathFor( string $name, array $data = [], array $queryParams = [] )

Build the path for a named route excluding the base path

Build the path for a named route excluding the base path

Parameters

$name
Route name
$data
Named argument replacement data
$queryParams
Optional query string parameters

Returns

string

Throws

RuntimeException
If named route does not exist
InvalidArgumentException
If required data not provided

Implementation of

Slim\Interfaces\RouterInterface::relativePathFor()
public string
# pathFor( string $name, array $data = [], array $queryParams = [] )

Build the path for a named route including the base path

Build the path for a named route including the base path

Parameters

$name
Route name
$data
Named argument replacement data
$queryParams
Optional query string parameters

Returns

string

Throws

RuntimeException
If named route does not exist
InvalidArgumentException
If required data not provided

Implementation of

Slim\Interfaces\RouterInterface::pathFor()
public string
# urlFor( string $name, array $data = [], array $queryParams = [] )

Build the path for a named route.

Build the path for a named route.

This method is deprecated. Use pathFor() from now on.

Parameters

$name
Route name
$data
Named argument replacement data
$queryParams
Optional query string parameters

Returns

string

Throws

RuntimeException
If named route does not exist
InvalidArgumentException
If required data not provided

Constants summary

Constants inherited from Slim\Interfaces\RouterInterface

ALLOWED_METHODS, DISPATCH_STATUS

Properties summary

protected Psr\Container\ContainerInterface $container

Container Interface

Container Interface

#
protected FastRoute\RouteParser $routeParser

Parser

Parser

#
protected string $basePath

Base path used in pathFor()

Base path used in pathFor()

# ''
protected string|False $cacheFile

Path to fast route cache file. Set to false to disable route caching

Path to fast route cache file. Set to false to disable route caching

# false
protected Slim\Route[] $routes

Routes

Routes

# []
protected integer $routeCounter

Route counter incrementer

Route counter incrementer

# 0
protected Slim\RouteGroup[] $routeGroups

Route groups

Route groups

# []
protected FastRoute\Dispatcher $dispatcher
#
API documentation generated by ApiGen