[FEATURE] Added support for class hinting on routes as requested by #491

This commit is contained in:
Simon Sessingø
2021-03-21 05:55:18 +01:00
parent e78040aabd
commit 21d180ebc9
9 changed files with 69 additions and 35 deletions
+15 -2
View File
@@ -33,6 +33,7 @@ You can donate any amount of your choice by [clicking here](https://www.paypal.c
- [Helper functions](#helper-functions)
- [Routes](#routes)
- [Basic routing](#basic-routing)
- [Class hinting](#class-hinting)
- [Available methods](#available-methods)
- [Multiple HTTP-verbs](#multiple-http-verbs)
- [Route parameters](#route-parameters)
@@ -404,6 +405,14 @@ SimpleRouter::get('/', function() {
});
```
### Class hinting
You can use class hinting to load a class & method like this:
```php
SimpleRouter::get('/', [MyClass::class, 'myMethod']);
```
### Available methods
Here you can see a list over all available routes:
@@ -785,12 +794,17 @@ SimpleRouter::group(['middleware' => \Demo\Middlewares\Site::class, 'exceptionHa
SimpleRouter::get('/answers/{id}', 'ControllerAnswers@show', ['where' => ['id' => '[0-9]+']]);
/**
* Class hinting is supported too
*/
SimpleRouter::get('/answers/{id}', [ControllerAnswers::class, 'show'], ['where' => ['id' => '[0-9]+']]);
/**
* Restful resource (see IRestController interface for available methods)
*/
SimpleRouter::resource('/rest', ControllerRessource::class);
SimpleRouter::resource('/rest', ControllerResource::class);
/**
@@ -811,7 +825,6 @@ SimpleRouter::group(['middleware' => \Demo\Middlewares\Site::class, 'exceptionHa
});
SimpleRouter::get('/page/404', 'ControllerPage@notFound', ['as' => 'page.notfound']);
```
---