|
- <?php
-
- use App\Http\Controllers\ShowDashboardController;
- use App\Http\Controllers\Locations\CreateLocationController;
- use App\Http\Controllers\Locations\ShowCreateLocationFormController;
- use App\Http\Controllers\Locations\ShowLocationController;
- use App\Http\Controllers\Locations\ShowLocationsController;
- use App\Http\Controllers\Items\AdjustStockController;
- use App\Http\Controllers\Items\CreateItemController;
- use App\Http\Controllers\Items\ReceiveStockController;
- use App\Http\Controllers\Items\ShowAdjustStockFormController;
- use App\Http\Controllers\Items\ShowCreateItemFormController;
- use App\Http\Controllers\Items\ShowItemController;
- use App\Http\Controllers\Items\ShowItemsController;
- use App\Http\Controllers\Items\ShowReceiveStockFormController;
- use App\Http\Controllers\Items\ShowWithdrawStockFormController;
- use App\Http\Controllers\Items\WithdrawStockController;
- use App\Http\Controllers\Users\LogInUserController;
- use App\Http\Controllers\Users\LogOutUserController;
- use App\Http\Controllers\Users\RegisterUserController;
- use App\Http\Controllers\Users\ShowRegisterFormController;
- use Framework\Routing\Router;
-
- return function(Router $router) {
- $router->errorHandler(
- 404, fn() => 'whoops!'
- );
-
- $router->add(
- 'GET', '/',
- [ShowDashboardController::class, 'handle'],
- )->name('show-dashboard');
-
- // locations...
-
- $router->add(
- 'GET', '/locations',
- [ShowLocationsController::class, 'handle'],
- )->name('show-locations');
-
- $router->add(
- 'GET', '/locations/create',
- [ShowCreateLocationFormController::class, 'handle'],
- )->name('show-create-location-form');
-
- $router->add(
- 'POST', '/locations/create',
- [CreateLocationController::class, 'handle'],
- )->name('create-location');
-
- $router->add(
- 'GET', '/locations/view/{location}',
- [ShowLocationController::class, 'handle'],
- )->name('view-location');
-
- // items...
-
- $router->add(
- 'GET', '/items',
- [ShowItemsController::class, 'handle'],
- )->name('show-items');
-
- $router->add(
- 'GET', '/items/create',
- [ShowCreateItemFormController::class, 'handle'],
- )->name('show-create-item-form');
-
- $router->add(
- 'POST', '/items/create',
- [CreateItemController::class, 'handle'],
- )->name('create-item');
-
- $router->add(
- 'GET', '/items/view/{item}',
- [ShowItemController::class, 'handle'],
- )->name('view-item');
-
- // stock movements...
- //
- // note: each of these six paths uses a distinct literal segment
- // (receive-form/receive, withdraw-form/withdraw, adjust-form/adjust).
- // Framework\Routing\Route::matches() does not check the HTTP method
- // once it falls through to its parameterised-path regex, and matches
- // that regex unanchored — so a shorter dynamic route (like view-item
- // above) would otherwise swallow any longer path that starts with the
- // same segments (e.g. "/items/view/{item}/receive"), regardless of
- // method. Giving every dynamic route here its own unique path segment
- // sidesteps that rather than patching the router.
-
- $router->add(
- 'GET', '/items/receive-form/{item}',
- [ShowReceiveStockFormController::class, 'handle'],
- )->name('show-receive-stock-form');
-
- $router->add(
- 'POST', '/items/receive/{item}',
- [ReceiveStockController::class, 'handle'],
- )->name('receive-stock');
-
- $router->add(
- 'GET', '/items/withdraw-form/{item}',
- [ShowWithdrawStockFormController::class, 'handle'],
- )->name('show-withdraw-stock-form');
-
- $router->add(
- 'POST', '/items/withdraw/{item}',
- [WithdrawStockController::class, 'handle'],
- )->name('withdraw-stock');
-
- $router->add(
- 'GET', '/items/adjust-form/{item}',
- [ShowAdjustStockFormController::class, 'handle'],
- )->name('show-adjust-stock-form');
-
- $router->add(
- 'POST', '/items/adjust/{item}',
- [AdjustStockController::class, 'handle'],
- )->name('adjust-stock');
-
- // users...
-
- $router->add(
- 'GET', '/register',
- [ShowRegisterFormController::class, 'handle'],
- )->name('show-register-form');
-
- $router->add(
- 'POST', '/register',
- [RegisterUserController::class, 'handle'],
- )->name('register-user');
-
- $router->add(
- 'POST', '/log-in',
- [LogInUserController::class, 'handle'],
- )->name('log-in-user');
-
- $router->add(
- 'GET', '/log-out',
- [LogOutUserController::class, 'handle'],
- )->name('log-out-user');
- };
|