divix1988 / laminas-cli-commands

CLI commands for Laminas projects
MIT License
15 stars 4 forks source link

Issue with the Laminus Starter Kits #8

Closed nmcwilli closed 10 months ago

nmcwilli commented 3 years ago

I tested the Login and registration form generator, but receive this when trying to integrate it with the Application Module from the Skeleton Application:

Fatal error: Uncaught Laminas\ServiceManager\Exception\ServiceNotFoundException: Unable to resolve service "Application\SessionManager" to a factory; are you certain you provided it during configuration? in /var/www/html/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:569 Stack trace: #0 /var/www/html/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(644): Laminas\ServiceManager\ServiceManager->getFactory() #1 /var/www/html/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(218): Laminas\ServiceManager\ServiceManager->doCreate() #2 /var/www/html/module/Application/src/Module.php(49): Laminas\ServiceManager\ServiceManager->get() #3 /var/www/html/module/Application/src/Module.php(43): Application\Module->bootstrapSession() #4 /var/www/html/vendor/laminas/laminas-eventmanager/src/EventManager.php(331): Application\Module->onBootstrap() #5 /var/www/html/vendor/laminas/laminas-eventmanager/src/EventManager.php(180): Laminas\EventManager\EventManager->triggerListeners() #6 /var/www/html/vendor/ in /var/www/html/vendor/laminas/laminas-servicemanager/src/ServiceManager.php on line 569

Any suggestions?

It is just the stock skeleton app, with the exact lines of code specified in the generator. Also, the laminus-db and laminas-session are both installed via composer.

divix1988 commented 3 years ago

You are missing definition of the SessionManager in module/[app_name]/src/Module.php.

Insert the following into getServiceConfig() method inside of factories alias:

SessionManager::class => function ($container) {
    $config = $container->get('config');
    $session = $config['session'];
    $sessionConfig = new $session['config']['class']();
    $sessionConfig->setOptions($session['config']['options']);
    $sessionManager = new Session\SessionManager(
        $sessionConfig,
        new $session['storage'](),
        null
    );
    \Laminas\Session\Container::setDefaultManager($sessionManager);

    return $sessionManager;
},