2022-10-15 11:22:08 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Modules\Auth;
|
|
|
|
|
|
|
|
use CodeIgniter\Router\RouteCollection;
|
|
|
|
use CodeIgniter\Shield\Auth as ShieldAuth;
|
|
|
|
|
|
|
|
class Auth extends ShieldAuth
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Will set the routes in your application to use
|
|
|
|
* the Shield auth routes.
|
|
|
|
*
|
|
|
|
* Usage (in Config/Routes.php):
|
|
|
|
* - auth()->routes($routes);
|
|
|
|
* - auth()->routes($routes, ['except' => ['login', 'register']])
|
2024-04-28 16:39:01 +00:00
|
|
|
*
|
|
|
|
* @param array{except?:list<string>} $config
|
2022-10-15 11:22:08 +00:00
|
|
|
*/
|
|
|
|
public function routes(RouteCollection &$routes, array $config = []): void
|
|
|
|
{
|
2024-04-28 16:39:01 +00:00
|
|
|
$authRoutes = config('AuthRoutes')
|
2022-10-15 11:22:08 +00:00
|
|
|
->routes;
|
|
|
|
|
2024-04-28 16:39:01 +00:00
|
|
|
$routes->group(config('Auth')->gateway, [
|
2022-10-15 11:22:08 +00:00
|
|
|
'namespace' => 'Modules\Auth\Controllers',
|
|
|
|
], static function (RouteCollection $routes) use ($authRoutes, $config): void {
|
|
|
|
foreach ($authRoutes as $name => $row) {
|
|
|
|
if (! isset($config['except']) || ! in_array($name, $config['except'], true)) {
|
|
|
|
foreach ($row as $params) {
|
|
|
|
$options = isset($params[3])
|
|
|
|
? [
|
|
|
|
'as' => $params[3],
|
|
|
|
]
|
|
|
|
: null;
|
|
|
|
$routes->{$params[0]}($params[1], $params[2], $options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|