53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Mezzio\Application;
|
|
use Mezzio\MiddlewareFactory;
|
|
use Psr\Container\ContainerInterface;
|
|
use Homepage\Infrastructure\Session\Middleware\LoggedInUserMiddleware;
|
|
|
|
/**
|
|
* laminas-router route configuration
|
|
*
|
|
* @see https://docs.laminas.dev/laminas-router/
|
|
*
|
|
* Setup routes with a single request method:
|
|
*
|
|
* $app->get('/', App\Handler\HomePageHandler::class, 'home');
|
|
* $app->post('/album', App\Handler\AlbumCreateHandler::class, 'album.create');
|
|
* $app->put('/album/:id', App\Handler\AlbumUpdateHandler::class, 'album.put');
|
|
* $app->patch('/album/:id', App\Handler\AlbumUpdateHandler::class, 'album.patch');
|
|
* $app->delete('/album/:id', App\Handler\AlbumDeleteHandler::class, 'album.delete');
|
|
*
|
|
* Or with multiple request methods:
|
|
*
|
|
* $app->route('/contact', App\Handler\ContactHandler::class, ['GET', 'POST', ...], 'contact');
|
|
*
|
|
* Or handling all request methods:
|
|
*
|
|
* $app->route('/contact', App\Handler\ContactHandler::class)->setName('contact');
|
|
*
|
|
* or:
|
|
*
|
|
* $app->route(
|
|
* '/contact',
|
|
* App\Handler\ContactHandler::class,
|
|
* Mezzio\Router\Route::HTTP_METHOD_ANY,
|
|
* 'contact'
|
|
* );
|
|
*/
|
|
|
|
return static function (Application $app, MiddlewareFactory $factory, ContainerInterface $container): void {
|
|
$config = $container->get('config');
|
|
|
|
foreach ($config['routes'] as $routeConfig) {
|
|
$app->route(
|
|
name: $routeConfig['name'],
|
|
path: $routeConfig['path'],
|
|
middleware: $routeConfig['middleware'],
|
|
methods: $routeConfig['allowed_methods']
|
|
);
|
|
}
|
|
};
|