Unable to resolve service "HttpRouter" to a factory

Fatal error: Uncaught Laminas\ServiceManager\Exception\ServiceNotFoundException: Unable to resolve service “HttpRouter” to a factory

There is two factory is missing. Router and HttpRouter. After adding this line into global.php

'Router' => 'Laminas\Router\RouterFactory', Router issue fixed but when I adding
` ‘HttpRouter’ => ‘Laminas\Router\RouterFactory’, it going into infinite loop to getFactory method in ServiceManager.php

I found calling this $serviceManager->get('Router') but not finding where ‘HttpRouter’ is getting call. It should be called like $serviceManager->get('HttpRouter');

To answer your question, I can’t see your this page and what do you mean by this and that? I’ve no idea why you’re dumping the application object and what are you trying to prove.
Laminas has not yet debunked legacy names of Zend Framework as it will create a massive backward compatibility issue. That is the reason why duplicate keys exist. It shows clearly you’ve no idea about the Zend Framework skeleton application and Laminas MVC skeleton application. I would suggest you first get a first-hand experience with it. Thanks!

Updated my question with more details after enabling xdebug.

The first thing to note when using a framework, you can’t change some specific keys and want to make it work as you wish. That is why there are some framework-specific keys you can’t change. Changing ‘Router’ with ‘HttpRouter’ with whose permission. Can I change your gender if I wish it?
Why are you adding these keys in globa.php and how are you adding it? Adding any key anywhere will work in your opinion?
The solution that I can give you is to disable modules one by one and make it equivalent to a Laminas Minimum framework requirement and then see what is the result. Then start enabling modules which are built by you or by your team.

@Avinash_Dalvi not sure which version you are currently running but you may want to take a look here (latest version):

There is aliases setup for ‘HttpRouter’, ‘router’ and ‘Router’ two of which point to the service identifier RouteStackInterface which is the identifier that points to the RouterFactory.

1 Like

It is possible that he or his team may not have been working from the skeleton application. There is many ways to use Laminas libraries without starting with the MVC skeleton :wink:

@Tyrsson, You’re showing a complete reference not just a line. Having an alias and the actual factory name is the same thing? Can I do the following? Also, he is in well-capable hands on the Slack channel.

'factories' => [
   'HttpRouter' => MyNamespace\Factory\MyAnonomusFactory::class,

class MyAnonoummusFactory extends ImaginaryFactory {


Aliases should point to a service identifier or to another alias.

It’s not a “factory name” per-say. Its a service identifier. The service identifier should map to a factory that returns an instance of that service.

The general rule of thumb is that only core services with historically significant identifiers (ie ‘EventManager’) should use plain string identifiers. All other services should be mapped to class-string identifiers matching the service for which the factory returns an instance. We see why when using the FactoryInterface the $requestedName argument holds the requested service class-string, which is whatever was mapped to the factory. In your example above using the $requestedName to create an instance of the requested service would fail.

The real question for the OP is why is the default mappings not being read and used by the framework?

The thing to remember about slack is that those conversations have a maximum lifespan of 90 days. After that the information is lost to anyone that may find themselves having the same issues.

1 Like

The root cause for the loop is due to mapping the HttpRouter to the RouterFactory instead of the HttpRouterFactory. You can not call an instance of the requested service from the container inside the factory that is supposed to create the service instance.

RouterFactory: (This line is causing the loop)

The root cause of your issues is that those mappings should already be provided by the MVC layer as far as I am aware. Of course this depends on which version of the components you are using. I’m not sure which version moved the configuration to Module.php/ConfigProvider.php classes.

It may help if you could tell us if you have a /config/modules.config.php file present in the tree?

1 Like

“laminas/laminas-dependency-plugin”: “2.6.0”,
“laminas/laminas-authentication”: “2.16.0”,
“laminas/laminas-code”: “4.13.0”,
“laminas/laminas-config”: “3.9.0”,
“laminas/laminas-crypt”: “3.11.0”,
“laminas/laminas-db”: “2.19.0”,
“laminas/laminas-di”: “3.13.0”,
“laminas/laminas-dom”: “2.14.0”,
“laminas/laminas-eventmanager”: “3.13.0”,
“laminas/laminas-feed”: “2.22.0”,
“laminas/laminas-file”: “2.13.0”,
“laminas/laminas-filter”: “2.34.0”,
“laminas/laminas-form”: “3.19.2”,
“laminas/laminas-http”: “2.19.0”,
“laminas/laminas-i18n”: “2.26.0”,
“laminas/laminas-inputfilter”: “2.30.0”,
“laminas/laminas-json”: “3.6.0”,
“laminas/laminas-ldap”: “2.18.1”,
“laminas/laminas-loader”: “2.10.0”,
“laminas/laminas-log”: “2.17.0”,
“laminas/laminas-mail”: “2.25.1”,
“laminas/laminas-math”: “3.7.0”,
“laminas/laminas-memory”: “2.11.0”,
“laminas/laminas-mime”: “2.12.0”,
“laminas/laminas-modulemanager”: “2.15.0”,
“laminas/laminas-mvc”: “3.7.0”,
“laminas/laminas-navigation”: “2.19.1”,
“laminas/laminas-paginator”: “2.18.1”,
“laminas/laminas-permissions-acl”: “2.16.0”,
“laminas/laminas-permissions-rbac”: “3.6.0”,
“laminas/laminas-progressbar”: “2.13.0”,
“laminas/laminas-serializer”: “2.17.0”,
“laminas/laminas-server”: “2.17.0”,
“laminas/laminas-servicemanager”: “^3.11.2”,
“laminas/laminas-session”: “2.20.0”,
“laminas/laminas-soap”: “2.13.0”,
“laminas/laminas-stdlib”: “3.19.0”,
“laminas/laminas-tag”: “2.11.0”,
“laminas/laminas-test”: “4.10.0”,
“laminas/laminas-text”: “2.11.0”,
“laminas/laminas-uri”: “2.11.0”,
“laminas/laminas-validator”: “2.52.0”,
“ocramius/package-versions”: “2.8.0”,
“laminas/laminas-xmlrpc”: “2.19.0”,
“laminas/laminas-view”: “2.34.0”,
“laminas/laminas-router”: “^3.13”

I am using modules.config.php under /modules/Application/config/module.config.php

Issue got resolved after adding
'HttpRouter' => 'Laminas\Router\Http\HttpRouterFactory',
Thanks all for help.

Just to summarised this issue. Allowed memory size got exhausted because one factory was calling under infinite loop.

How I found issue ? After enabling Xdebug i got to know exact error otherwise it was just showing “This page isn’t working” which is standard one. If you want to know exact issue xdebug is good tool to find out root cause.

How I solved issue ?

There was two factory was not able to load because missing configuration for factories. Which was Router and HttpRouter. To solve that I added below lines which was there in my old code before upgrading laminas.

'Router' => 'Laminas\Router\Http\RouterFactory',

'HttpRouter' => 'Laminas\Router\Http\RouterFactory',

But actual issue was laminas-router/src/RouterFactory.php at 5e55c60ac9bd88624025a86895551daaac6a01e6 · laminas/laminas-router · GitHub this line was calling again HttpRouter, it become infinite loop. like h Router is pointing to HttpRouter in this file but in factories I was pointing to HttpRouter.

I solved this to finding right factory.

'Router' => 'Laminas\Router\RouterFactory',

'HttpRouter' => 'Laminas\Router\Http\HttpRouterFactory',

These factories are provided by the component and the component autowires them. The important question that needs to be answered is why your application is not reading the default configuration. My guess is that you are not using the laminas component installer and therefore they are not being added to the /config/modules.config.php file.

You may want to read this:

1 Like

Something is absolutely wrong here, nothing needs to be configured manually because everything is already there. :man_shrugging:t2:

1 Like

I’ve tracked it down to their Module files are not being read. They are in the middle of a migration and do not have a /config/application.config.php / /config/modules.config.php file present. Which means, as we know, the autowiring is not being read.


Thanks for suggestion. I Moved changes to application.config.php for missing modules and its works.

1 Like