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

Improve readme example #18

Merged
merged 1 commit into from
Apr 21, 2023
Merged
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
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,37 @@ composer require gacela-project/router

### Example

Start the example local server:
```bash
php -S localhost:8081 example/example.php
```

You can access the example routes:
```php
# file: example/example.php
Router::configure(static function (Routes $routes, Bindings $bindings) void {
# http://localhost:8081/docs
# `Bindings` and `Handlers` are optional, and you can place them in any order.

Router::configure(static function (Routes $routes, Bindings $bindings, Handlers $handlers) void {

// Custom redirections
$routes->redirect('docs', 'https://gacela-project.com/');

// Matching a route coming from a particular or any custom HTTP methods
$routes->get('custom', CustomController::class, '__invoke');
$routes->...('custom', CustomController::class, 'customAction');
$routes->any('custom', CustomController::class);

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

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

# http://localhost:8081/custom
$routes->any('custom', CustomController::class);
// Handle custom Exceptions with class-string|callable
$handlers->handle(NotFound404Exception::class, NotFound404ExceptionHandler::class);

});
```

### Working demo

For a working example run `composer serve` and check the `example/example.php`

> TIP: `composer serve` is equivalent to:
> ```bash
> php -S localhost:8081 example/example.php
> ```