Skip to content

Commit

Permalink
Adjust router syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Feb 2, 2020
1 parent e4af7ae commit 208aa7b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions guide/en/start/hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class AppRouterFactory
public function __invoke(ContainerInterface $container)
{
$routes = [
Route::get('/say')->to(new ActionCaller(Hello::class, 'say', $container)),
Route::get('/say/{message}')->to(new ActionCaller(Hello::class, 'say', $container)),
Route::get('/say', new ActionCaller(Hello::class, 'say', $container)),
Route::get('/say/{message}', new ActionCaller(Hello::class, 'say', $container)),
];

return (new RouterFactory(new FastRouteFactory(), $routes))($container);
Expand Down
10 changes: 5 additions & 5 deletions guide/en/structure/action.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use \Psr\Http\Message\ServerRequestInterface;
use \Psr\Http\Message\ResponseInterface;
use Yiisoft\Router\Route;

Route::get('/')->to(function (ServerRequestInterface $request) use ($responseFactory): ResponseInterface {
Route::get('/', function (ServerRequestInterface $request) use ($responseFactory): ResponseInterface {
$response = $responseFactory->createResponse();
$response->getBody()->write('You are at homepage.');
return $response;
Expand All @@ -25,7 +25,7 @@ a good idea would be moving the handling to a class method. Callback middleware
```php
use Yiisoft\Router\Route;

Route::get('/')->to(new ActionCaller(FrontPageAction::class, 'run', $container)),
Route::get('/', new ActionCaller(FrontPageAction::class, 'run', $container)),
```

The class itself would like:
Expand All @@ -49,8 +49,8 @@ For many cases it makes sense to group handling for multiple routes into a singl
```php
use Yiisoft\Router\Route;

Route::get('/post/index')->to(new ActionCaller(PostController::class, 'actionIndex', $container)),
Route::get('/post/view/{id:\d+}')->to(new ActionCaller(PostController::class, 'actionView', $container)),
Route::get('/post/index', new ActionCaller(PostController::class, 'actionIndex', $container)),
Route::get('/post/view/{id:\d+}', new ActionCaller(PostController::class, 'actionView', $container)),
```

The class itself would look like the following:
Expand Down Expand Up @@ -81,7 +81,7 @@ middleware:
use Yiisoft\Router\Route;
use Yiisoft\Yii\Web\Middleware\WebActionsCaller;

Route::anyMethod('/post/{action:\w+}')->to(new WebActionsCaller(PostController::class, $container)),
Route::anyMethod('/post/{action:\w+}', new WebActionsCaller(PostController::class, $container)),
```

## Autowiring
Expand Down
2 changes: 1 addition & 1 deletion guide/en/structure/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AppRouterFactory

$routes = [
// ...
Route::get('/basic-auth')->to(new Chain($basicAuth, $authorizedAction)),
Route::get('/basic-auth', new Chain($basicAuth, $authorizedAction)),
];

return (new RouterFactory(new FastRouteFactory(), $routes))($container);
Expand Down

0 comments on commit 208aa7b

Please sign in to comment.