Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract interface for route configuration #276

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Here's a basic usage example:

require '/path/to/vendor/autoload.php';

$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\ConfigureRoutes $r) {
$r->addRoute('GET', '/users', 'get_all_users_handler');
// {id} must be a number (\d+)
$r->addRoute('GET', '/user/{id:\d+}', 'get_user_handler');
Expand Down Expand Up @@ -65,7 +65,7 @@ switch ($routeInfo[0]) {
### Defining routes

The routes are defined by calling the `FastRoute\simpleDispatcher()` function, which accepts
a callable taking a `FastRoute\RouteCollector` instance. The routes are added by calling
a callable taking a `FastRoute\ConfigureRoutes` instance. The routes are added by calling
`addRoute()` on the collector instance:

```php
Expand Down Expand Up @@ -147,7 +147,7 @@ Additionally, you can specify routes inside a group. All routes defined inside a
For example, defining your routes as:

```php
$r->addGroup('/admin', function (FastRoute\RouteCollector $r) {
$r->addGroup('/admin', function (FastRoute\ConfigureRoutes $r) {
$r->addRoute('GET', '/do-something', 'handler');
$r->addRoute('GET', '/do-another-thing', 'handler');
$r->addRoute('GET', '/do-something-else', 'handler');
Expand All @@ -173,7 +173,7 @@ routing data and construct the dispatcher from the cached information:
```php
<?php

$dispatcher = FastRoute\cachedDispatcher(function(FastRoute\RouteCollector $r) {
$dispatcher = FastRoute\cachedDispatcher(function(FastRoute\ConfigureRoutes $r) {
$r->addRoute('GET', '/user/{name}/{id:[0-9]+}', 'handler0');
$r->addRoute('GET', '/user/{id:[0-9]+}', 'handler1');
$r->addRoute('GET', '/user/{name}', 'handler2');
Expand Down Expand Up @@ -275,7 +275,7 @@ through the options array:
```php
<?php

$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\RouteCollector $r) {
$dispatcher = FastRoute\simpleDispatcher(function(FastRoute\ConfigureRoutes $r) {
/* ... */
}, [
'routeParser' => 'FastRoute\\RouteParser\\Std',
Expand Down
6 changes: 3 additions & 3 deletions benchmark/DispatcherForBenchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace FastRoute\Benchmark;

use FastRoute\ConfigureRoutes;
use FastRoute\DataGenerator;
use FastRoute\Dispatcher;
use FastRoute\RouteCollector;
use RuntimeException;

use function FastRoute\simpleDispatcher;
Expand All @@ -17,7 +17,7 @@ final class DispatcherForBenchmark
public static function realLifeExample(string $dispatcher): Dispatcher
{
return simpleDispatcher(
static function (RouteCollector $routes): void {
static function (ConfigureRoutes $routes): void {
$routes->addRoute('GET', '/', ['name' => 'home']);
$routes->addRoute('GET', '/page/{page_slug:[a-zA-Z0-9\-]+}', ['name' => 'page.show']);
$routes->addRoute('GET', '/about-us', ['name' => 'about-us']);
Expand Down Expand Up @@ -68,7 +68,7 @@ static function (RouteCollector $routes): void {
public static function manyRoutes(string $dispatcher, int $routeCount = 400): Dispatcher
{
return simpleDispatcher(
static function (RouteCollector $routes) use ($routeCount): void {
static function (ConfigureRoutes $routes) use ($routeCount): void {
for ($i = 0; $i < $routeCount; ++$i) {
$routes->addRoute('GET', '/abc' . $i, ['name' => 'static-' . $i]);
$routes->addRoute('GET', '/abc{foo}/' . $i, ['name' => 'not-static-' . $i]);
Expand Down
Loading
Loading