CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.1 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.1
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
      • Exception
      • Middleware
      • Route
    • TestSuite
    • Utility
    • Validation
    • View

Class RouteCollection

Contains a collection of routes.

Provides an interface for adding/removing routes and parsing/generating URLs with the routes it contains.

Namespace: Cake\Routing

Property Summary

  • $_extensions protected
    list<string>

    Route extensions

  • $_middleware protected
    array

    A map of middleware names and the related objects.

  • $_middlewareGroups protected
    array

    A map of middleware group names and the related middleware names.

  • $_named protected
    array<Cake\Routing\Route\Route>

    The hash map of named routes that are in this collection.

  • $_paths protected
    array<string, array<Cake\Routing\Route\Route>>

    Routes indexed by path prefix.

  • $_routeTable protected
    array<string, array<Cake\Routing\Route\Route>>

    The routes connected to this collection.

  • $staticPaths protected
    array<string, array<Cake\Routing\Route\Route>>

    Routes indexed by static path.

Method Summary

  • _getNames() protected

    Get the set of names from the $url. Accepts both older style array urls, and newer style urls containing '_name'

  • add() public

    Add a route to the collection.

  • getExtensions() public

    Get the extensions that can be handled.

  • getMiddleware() public

    Get an array of middleware given a list of names

  • hasMiddleware() public

    Check if the named middleware has been registered.

  • hasMiddlewareGroup() public

    Check if the named middleware group has been created.

  • match() public

    Reverse route or match a $url array with the connected routes.

  • middlewareExists() public

    Check if the named middleware or middleware group has been registered.

  • middlewareGroup() public

    Add middleware to a middleware group

  • named() public

    Get the connected named routes.

  • parseRequest() public

    Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.

  • registerMiddleware() public

    Register a middleware with the RouteCollection.

  • routes() public

    Get all the connected routes as a flat list.

  • setExtensions() public

    Set the extensions that the route collection can handle.

Method Detail

_getNames() ¶ protected

_getNames(array $url): list<string>

Get the set of names from the $url. Accepts both older style array urls, and newer style urls containing '_name'

Parameters
array $url

The url to match.

Returns
list<string>

add() ¶ public

add(Cake\Routing\Route\Route $route, array<string, mixed> $options = []): void

Add a route to the collection.

Parameters
Cake\Routing\Route\Route $route

The route object to add.

array<string, mixed> $options optional

Additional options for the route. Primarily for the _name option, which enables named routes.

Returns
void

getExtensions() ¶ public

getExtensions(): list<string>

Get the extensions that can be handled.

Returns
list<string>

getMiddleware() ¶ public

getMiddleware(array<string> $names): array

Get an array of middleware given a list of names

Parameters
array<string> $names

The names of the middleware or groups to fetch

Returns
array
Throws
InvalidArgumentException
when a requested middleware does not exist.

hasMiddleware() ¶ public

hasMiddleware(string $name): bool

Check if the named middleware has been registered.

Parameters
string $name

The name of the middleware to check.

Returns
bool

hasMiddlewareGroup() ¶ public

hasMiddlewareGroup(string $name): bool

Check if the named middleware group has been created.

Parameters
string $name

The name of the middleware group to check.

Returns
bool

match() ¶ public

match(array $url, array $context): string

Reverse route or match a $url array with the connected routes.

Returns either the URL string generated by the route, or throws an exception on failure.

Parameters
array $url

The URL to match.

array $context

The request context to use. Contains _base, _port, _host, _scheme and params keys.

Returns
string
Throws
Cake\Routing\Exception\MissingRouteException
When no route could be matched.

middlewareExists() ¶ public

middlewareExists(string $name): bool

Check if the named middleware or middleware group has been registered.

Parameters
string $name

The name of the middleware to check.

Returns
bool

middlewareGroup() ¶ public

middlewareGroup(string $name, array<string> $middlewareNames): $this

Add middleware to a middleware group

Parameters
string $name

Name of the middleware group

array<string> $middlewareNames

Names of the middleware

Returns
$this
Throws
InvalidArgumentException

named() ¶ public

named(): array<Cake\Routing\Route\Route>

Get the connected named routes.

Returns
array<Cake\Routing\Route\Route>

parseRequest() ¶ public

parseRequest(Psr\Http\Message\ServerRequestInterface $request): array

Takes the ServerRequestInterface, iterates the routes until one is able to parse the route.

Parameters
Psr\Http\Message\ServerRequestInterface $request

The request to parse route data from.

Returns
array
Throws
Cake\Routing\Exception\MissingRouteException
When a URL has no matching route.

registerMiddleware() ¶ public

registerMiddleware(string $name, Psr\Http\Server\MiddlewareInterface|Closure|string $middleware): $this

Register a middleware with the RouteCollection.

Once middleware has been registered, it can be applied to the current routing scope or any child scopes that share the same RouteCollection.

Parameters
string $name

The name of the middleware. Used when applying middleware to a scope.

Psr\Http\Server\MiddlewareInterface|Closure|string $middleware

The middleware to register.

Returns
$this
Throws
RuntimeException

routes() ¶ public

routes(): array<Cake\Routing\Route\Route>

Get all the connected routes as a flat list.

Routes will not be returned in the order they were added.

Returns
array<Cake\Routing\Route\Route>

setExtensions() ¶ public

setExtensions(array<string> $extensions, bool $merge = true): $this

Set the extensions that the route collection can handle.

Parameters
array<string> $extensions

The list of extensions to set.

bool $merge optional

Whether to merge with or override existing extensions. Defaults to true.

Returns
$this

Property Detail

$_extensions ¶ protected

Route extensions

Type
list<string>

$_middleware ¶ protected

A map of middleware names and the related objects.

Type
array

$_middlewareGroups ¶ protected

A map of middleware group names and the related middleware names.

Type
array

$_named ¶ protected

The hash map of named routes that are in this collection.

Type
array<Cake\Routing\Route\Route>

$_paths ¶ protected

Routes indexed by path prefix.

Type
array<string, array<Cake\Routing\Route\Route>>

$_routeTable ¶ protected

The routes connected to this collection.

Type
array<string, array<Cake\Routing\Route\Route>>

$staticPaths ¶ protected

Routes indexed by static path.

Type
array<string, array<Cake\Routing\Route\Route>>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs