No Code Attached Yet
avatar thynk-media
thynk-media
30 Sep 2024

Steps to reproduce the issue

As soon as I try to load the Endpoint /api/index.php/v1/users, the repsonse is "Unable to load router: api".

Expected result

JRouterApi should be alias for ApiRouter, like SiteRouter and AdministratorRouter.

$container->alias('AdministratorRouter', AdministratorRouter::class)
            ->alias('JRouterAdministrator', AdministratorRouter::class)
$container->alias('SiteRouter', SiteRouter::class)
            ->alias('JRouterSite', SiteRouter::class)

Actual result

JRouterApi is no alias for ApiRouter.


$container->alias('ApiRouter', ApiRouter::class)
            ->share(
                ApiRouter::class,
                function (Container $container) {
                    return new ApiRouter($container->get(ApiApplication::class));
                },
                true
            );

So the Joomla\CMS\Router\Router class will fail at:

$classname = 'JRouter' . ucfirst($client);

if (!class_exists($classname)) {
    throw new \RuntimeException(Text::sprintf('JLIB_APPLICATION_ERROR_ROUTER_LOAD', $client), 500);
}

System information (as much as possible)

Joomla 4.4.8, PHP 8.1.29, Apache Server

avatar thynk-media thynk-media - open - 30 Sep 2024
avatar joomla-cms-bot joomla-cms-bot - change - 30 Sep 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 30 Sep 2024
avatar Hackwar Hackwar - close - 30 Sep 2024
avatar Hackwar
Hackwar - comment - 30 Sep 2024

Thank you for reporting this, unfortunately however, JRouterAPI should not be an alias for ApiRouter, since all J-prefixes are only b/c aliases for Joomla 3, but the API has only been introduced in 4.0. You should not get the router with Router::getInstance(), but with $router = $this->getContainer()->get(ApiRouter::class);. This is not a Joomla bug.

avatar Hackwar Hackwar - change - 30 Sep 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-09-30 10:12:54
Closed_By Hackwar
avatar thynk-media
thynk-media - comment - 30 Sep 2024

I know, but since it is in the core file "Joomla\CMS\Router\Router.php" (line 112 to 116 J! Version 4.4.8) it is core bug, isn't it?

There is a check if 'JRouter' . ucfirst($client) is a existing class (in this case "api"), and when it doesn't exits the programm will exit with JLIB_APPLICATION_ERROR_ROUTER_LOAD. So the core the core expects JRouteApi by itself.

avatar Hackwar
Hackwar - comment - 30 Sep 2024

Yes, but that method itself is deprecated and it is not the right method to retrieve every router. We wont change this. Please use the correct method as described above.

Add a Comment

Login with GitHub to post a comment