Search code examples
composer-phplaminas

Unable to resolve service Laminas MVC Cache Storage


Unable to Resolve Service:

How does one resolve a service via a /conf/autoload/local.php config file.

Error:

Fatal error: Uncaught Laminas\ServiceManager\Exception\ServiceNotFoundException: Unable to resolve service "Laminas\Cache\Storage\Adapter\Memory"to a factory; are you certain you provided it during configuration? in /var/www/vhosts/.../portal/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:586

This issue came about while updating to PHP8.2 and using composer. The application runs fine on php7.4...

I've tried using docs https://docs.laminas.dev/laminas-cache/v4/storage/adapter/ but not really a clear set of instructions for config initialisation.

I cannot figure out why this requirement has suddenly appeared.

UPDATE: The issue was a combination of version conflicts and incorrect configuration options. Required this: https://docs.laminas.dev/laminas-cache/v3/application-integration/usage-in-a-laminas-mvc-application/ for global.php config setup.

  1. Additions to Module.php solved the initial problem

  2. 'default-cache' setting in config resolved the secondary issue

    'Laminas\Cache', 'Laminas\Cache\Storage\Adapter\Memory', 'Laminas\Cache\Storage\Adapter\Filesystem',

and

'caches' => [
        'default-cache' => [
            'adapter' => Laminas\Cache\Storage\Adapter\Filesystem::class,
            'options' => [
                'cache_dir' => __DIR__ . '/../../data/cache',
            ],
        ],
    ],

Thanks to @Ermenegildo


Solution

  • In your config/modules.config.php file, check that the following modules are enabled:

    return [
        // ...
        'Laminas\Cache',
        'Laminas\Cache\Storage\Adapter\Memory',
        // ...
    ];
    

    Considering the error message you get, I think you enabled only the first one.

    If the configuration cache is enabled, don't forget to clear it.