Fatal Error in fresh Laminas API Tools Skeleton installation

Hey there,

I 'm facing a problem with the Laminas API Tools skeleton. I was installing it via composer as described in the documentation. The composer installation process was fine. No error messages or other notices.

Technical background: Windows 10, XAMPP, PHP 8.0.0

When I tried to create a new api in the admin ui, the status said, that the api was created, but did not list the new api. The console stated the following fatal error:

PHP Fatal error: Uncaught Error: Class “ZF\Apigility\Admin\Controller\InputFilter\ModuleInputFilter” not found in C:\xampp\htdocs\api-tools\vendor\laminas\laminas-servicemanager\src\Factory\InvokableFactory.php:33
Stack trace:
#0C:\xampp\htdocs\api-tools\vendor\laminas\laminas-servicemanager\src\ServiceManager.php(665): Laminas\ServiceManager\Factory\InvokableFactory->__invoke(Object(Laminas\ServiceManager\ServiceManager), ‘ZF\Apigility\Ad…’, NULL)
#1 C:\xampp\htdocs\api-tools\vendor\laminas\laminas-servicemanager\src\ServiceManager.php(230): Laminas\ServiceManager\ServiceManager->doCreate(‘ZF\Apigility\Ad…’)
#2 C:\xampp\htdocs\api-tools\vendor\laminas\laminas-servicemanager\src\AbstractPluginManager.php(174): Laminas\ServiceManager\ServiceManager->get(‘ZF\Apigility\Ad…’)
#3 C:\xampp\htdocs\api-tools\vendor\laminas-api-tools\api-tools-content-validation\src\ContentValidationListener.php(509): Laminas\ServiceManager\AbstractPluginManager->get(‘ZF\Apigility\Ad…’)
#4 C:\xampp\htdocs\api-tools\vendor\laminas-api-tools\api-tools-content-validation\src\ContentValidationListener.php(204): Laminas\ApiTools\ContentValidation\ContentValidationListener->hasInputFilter(‘ZF\Apigility\Ad…’)
#5 C:\xampp\htdocs\api-tools\vendor\laminas\laminas-eventmanager\src\EventManager.php(331): Laminas\ApiTools\ContentValidation\ContentValidationListener->onRoute(Object(Laminas\Mvc\MvcEvent))
#6 C:\xampp\htdocs\api-tools\vendor\laminas\laminas-eventmanager\src\EventManager.php(188): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent), Object(Closure))
#7 C:\xampp\htdocs\api-tools\vendor\laminas\laminas-mvc\src\Application.php(310): Laminas\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Laminas\Mvc\MvcEvent))
#8 C:\xampp\htdocs\api-tools\public\index.php(60): Laminas\Mvc\Application->run()
#9 {main}
thrown inC:\xampp\htdocs\api-tools\vendor\laminas\laminas-servicemanager\src\Factory\InvokableFactory.php on line 33

Looks like composer was not installing all dependencies. The whole ZF\Apigility namespace leads to nowhere. I don 't understand, why the apigility namesapce is existing in the current laminas api tools. There are no dependencies in the several composer.json files.

Why this error is occuring? Does anyone facing this, too?

1 Like

Only for legacy reasons but not needed in a fresh installation.

Please check the related issue report, maybe you can also help:

Thanks for the explaination of the legacy. A closer look at the php files in conjunction with your hints has brought some clarity.

Since the related issue report concerns more than one issue, I 'm using this thread to write down what I 've found so far concerning my issue.

The FQN in the exception is …

This FQN was never implemented since the Controller part in the namespace seems to be wrong. In the module.config.php file a legacy reference to ZF\Apigility\Admin\InputFilter\ModuleInputFilter is mentioned. So I guess somewhere in the code the wrong FQN is called and results in a service manager exception.

For reasons I don’t understand, a few namespaces in the module.config.php (laminas-api-tools/api-tools-admin/config/module.config.php) file get mixed up.

It all begins in line 1839. where the alias InputFilter\Module::class is mentioned. This leads directly to line 1765, where the alias definition for the fqn of this input filter is defined.

Normally the alias assignment should be \Laminas\ApiTools\Admin\InputFilter\ModuleInputFilter. But for some reason this one is resolved into ZF\Apigility\Admin\Controller\InputFilter\ModuleInputFilter. I cannot say why, because there 's no hint, why this is happening.

When I change the fqn from InputFilter\ModuleInputFilter::class to \Laminas\ApiTools\Admin\InputFilter\ModuleInputFilter::class it runs perfectly. The lines 1765, 1795 and 1812 are affected. Never the less I 'll keep an eye on it, because this one is somehow curios.

Same behaviour on the other input filter config entries. As long as the entries are noted as InputFilter\ClassName::class it results into ZF\Apigility\Admin\Controller\InputFilter\ClassName. If the fqn is fully written as \Laminas\ApiTools\Admin\InputFilter\ClassName::class it works fine.

I have not yet been able to find the cause of this namespace behaviour. The above shown solution is just a hotfix for one of my clients.

I’m having the same issue

[Tue Jul  6 09:57:30 2021] PHP Fatal error:  Uncaught Error: Class 'ZF\Apigility\Admin\Controller\InputFilter\ModuleInputFilter' not found in /home/omar/workspace/php/lamskel/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php:33
Stack trace:
#0 /home/omar/workspace/php/lamskel/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(665): Laminas\ServiceManager\Factory\InvokableFactory->__invoke()
#1 /home/omar/workspace/php/lamskel/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(230): Laminas\ServiceManager\ServiceManager->doCreate()
#2 /home/omar/workspace/php/lamskel/vendor/laminas/laminas-servicemanager/src/AbstractPluginManager.php(174): Laminas\ServiceManager\ServiceManager->get()
#3 /home/omar/workspace/php/lamskel/vendor/laminas-api-tools/api-tools-content-validation/src/ContentValidationListener.php(509): Laminas\ServiceManager\AbstractPluginManager->get()
#4 /home/omar/workspace/php/lamskel/vendor/laminas-api-tools/api-tools-content-validation/src/ContentValidationListener.php(204): Laminas\ApiTools\Content in /home/omar/workspace/php/lamskel/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php on line 33

Is there an alternative skeleton ?

You can use an earlier version until the problem is solved.

Is there an alternative skeleton ?

I guess not. The issue isn 't the skeleton itself. The bug exists in the laminas-api-tools / api-tools-admin repository. In detail the problem is located in line 164 of the module.config.php file.

Before this use statement the notation of InputFilter\ModuleInputFilter::class or InputFilter\ModuleInputFilter::class refers to the Laminas\ApiTools\Admin namespace, so that those two combine together to \Laminas\ApiTools\Admin\InputFilter\ModuleInputFilter. After the use statement in line 164 the notation of InputFilter\ModuleInputFilter just extends ZF\Apigility\Admin\Controller\InputFilter to ZF\Apigility\Admin\Controller\InputFilter\ModuleInputFilter.

So this issue is caused by a mixup of different namespaces and how they work together. This bug could be fixed by omitting the use statements and simply writing out FQN in full within the configuration, or simply using aliases for the legacy use statements so that conflicts with namespaces can be excluded.

OK, I’m trying 1.5.3 now

Good catch! :+1:t3:

Can you create a pull request on laminas-api-tools/api-tools-admin?

So a solution for now is
composer require -W laminas-api-tools/api-tools-admin 1.9.0

As this bug is introduced from 1.10.0, and beyond