Skip to content

Instantly share code, notes, and snippets.

@samdark
Forked from yiiliveext/routes.php
Last active March 20, 2021 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samdark/87c56aaeb8b21208ebbfc91633792f8c to your computer and use it in GitHub Desktop.
Save samdark/87c56aaeb8b21208ebbfc91633792f8c to your computer and use it in GitHub Desktop.
routes
<?php
declare(strict_types=1);
// GET /api/post is executed as:
//
// FormatDataResponse -> FormatDataResponseAsJson -> AccessCheck -> FormatDataResponsAsXml
// -> action
// -> FormatDataResponsAsXml -> AccessCheck -> FormatDataResponseAsJson -> FormatDataResponse
return [
// Variant 1
Group::create(null)
->pipe(FormatDataResponse::class)
->routes([
Group::create('/api')
->pipe(FormatDataResponseAsJson::class)
->pipe(AccessCheck::class)
->routes([
Route::get('/post')
->pipe(FormatDataResponsAsXml::class)
->action([PostController::class, 'index']),
Route::post('/post')
->action([PostController::class, 'add'])
]),
]),
// Variant 2 (current version)
Group::create(null, [
Group::create('/api', [
Route::get('/post', [PostController::class, 'index'])
->addMiddleware(FormatDataResponsAsXml::class),
Route::post('/post', [PostController::class, 'add']),
])->addMiddleware(AccessCheck::class)
->addMiddleware(FormatDataResponseAsJson::class),
])->addMiddleware(FormatDataResponse::class)
];
@shokhaa
Copy link

shokhaa commented Mar 20, 2021

#[Route('/edit/{id}', name: 'users.edit')]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment