Custom callable class in route

Slim 4.12, PHP 7.4
My router:

	$app->group('/api/{version:v[0-9]+}', function (RouteCollectorProxy $group) {
		$group->group('/auth', function (RouteCollectorProxy $group) {
			$group->get('/login', "\App\Application\Actions\{version}\Auth\LoginAction");
			$group->get('/logout', "\App\Application\Actions\{version}\Auth\LogoutAction");
		});
	});

How to create callable class with version from request?

I have class LoginAction with namespace \App\Application\Actions\v1.
And for example LoginAction with namespace \App\Application\Actions\v2.

It should work with the ::class syntax.

In practice each new API version does not always have the same routes, so it makes sense to group them separately. Example:

// All routes for version 1
$app->group('/api/v1', function (RouteCollectorProxy $group) {
    $group->group('/auth', function (RouteCollectorProxy $group) {
        $group->get('/login', \App\Application\Actions\Version1\Auth\LoginAction::class);
        $group->get('/logout', \App\Application\Actions\Version1\Auth\LogoutAction::class);
    });
});

// All routes for version 2
$app->group('/api/v2', function (RouteCollectorProxy $group) {
    $group->group('/auth', function (RouteCollectorProxy $group) {
        $group->get('/login', \App\Application\Actions\Version2\Auth\LoginAction::class);
        $group->get('/logout', \App\Application\Actions\Version2\Auth\LogoutAction::class);
    });
});

Thx!
I’m overworked :rofl: