1

Iḿ using ZF3 and I'm building a service that will provide application wide segmented access to the application session container. This service is called SessionContainerManager and will have methods to retrieve and update user identity, user ACLs, etc. My code:

namespace User\Service;

class SessionContainerManager
{
    /**
     * Service container.
     * @var Zend\Service\Container
     */
    private $sessionContainer;


    public function __construct($sessionContainer) 
    {
        $this->sessionContainer = $sessionContainer;
    }

    public function getACLList() 
    {
        return $this->sessionContainer->aclList;
    }

    public function setACLList($aclList) 
    {
        $this->sessionContainer->aclList = $aclList;
    }

    public function getIdentity() 
    {
        return $this->sessionContainer->identity;
    }

    public function setIdentity($identity) 
    {
        $this->sessionContainer->identity = $identity;
    }

}

And its factory:

namespace User\Service\Factory;

use Interop\Container\ContainerInterface;
use User\Service\SessionContainerManager;
use Zend\Session\Container;

class SessionContainerManagerFactory
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {        
        $sessionContainer = $container->get(\Zend\Session\Container::class);

        return new SessionContainerManager($sessionContainer);
    }
}

In module.config:

'service_manager' => [
    'factories' => [
        Service\SessionContainerManager::class => Service\Factory\SessionContainerManagerFactory::class,
    ],

When running the app I'm getting the following error:

File:

    /home/renato/project/dev/fways/php/fways/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:670

Message:

    Unable to resolve service "Zend\Session\Container" to a factory; are you certain you provided it during configuration?

Help appreciated to make this session container to work.

Mendes
  • 17,489
  • 35
  • 150
  • 263

2 Answers2

1

check this link working with Sessions in zf3 Probably you didn't get this package in the first place. If it's not in your composer, try this to add it:

php composer.phar require zendframework/zend-session
fajnalowiec
  • 147
  • 9
-1

That caused by module configuration cached. It was generated at first time to speed up reading configuration. So, after adding new service configuration always remove the cache in data/cache/module-config-cache.application.config.cache.php It will be created automatically if not found.

Dolly Aswin
  • 2,684
  • 1
  • 20
  • 23