Skip to content

Commit 0531252

Browse files
authored
Merge pull request #18 from gacela-project/improve-readme-example
Improve readme example
2 parents 8b404ef + 163ed67 commit 0531252

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

README.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,37 @@ composer require gacela-project/router
3636

3737
### Example
3838

39-
Start the example local server:
40-
```bash
41-
php -S localhost:8081 example/example.php
42-
```
43-
44-
You can access the example routes:
4539
```php
46-
# file: example/example.php
47-
Router::configure(static function (Routes $routes, Bindings $bindings) void {
48-
# http://localhost:8081/docs
40+
# `Bindings` and `Handlers` are optional, and you can place them in any order.
41+
42+
Router::configure(static function (Routes $routes, Bindings $bindings, Handlers $handlers) void {
43+
44+
// Custom redirections
4945
$routes->redirect('docs', 'https://gacela-project.com/');
46+
47+
// Matching a route coming from a particular or any custom HTTP methods
48+
$routes->get('custom', CustomController::class, '__invoke');
49+
$routes->...('custom', CustomController::class, 'customAction');
50+
$routes->any('custom', CustomController::class);
5051

51-
# http://localhost:8081?number=456
52+
// Matching a route coming from multiple HTTP methods
5253
$routes->match(['GET', 'POST'], '/', CustomController::class);
5354

54-
# http://localhost:8081/custom/123
55+
// Binding custom dependencies on your controllers
5556
$routes->get('custom/{number}', CustomControllerWithDependencies::class, 'customAction');
5657
$bindings->bind(SomeDependencyInterface::class, SomeDependencyConcrete::class)
5758

58-
# http://localhost:8081/custom
59-
$routes->any('custom', CustomController::class);
59+
// Handle custom Exceptions with class-string|callable
60+
$handlers->handle(NotFound404Exception::class, NotFound404ExceptionHandler::class);
61+
6062
});
6163
```
64+
65+
### Working demo
66+
67+
For a working example run `composer serve` and check the `example/example.php`
68+
69+
> TIP: `composer serve` is equivalent to:
70+
> ```bash
71+
> php -S localhost:8081 example/example.php
72+
> ```

0 commit comments

Comments
 (0)