public function configure($object, array $options = [])
 {
     $manager = new Session\SessionManager();
     $manager->setStorage(new Session\Storage\ArrayStorage());
     $manager->setSaveHandler(new Session\SaveHandler\Cache(new CacheStorageAdapterMemory()));
     $manager->setConfig(new Session\Config\StandardConfig());
     $session = new Session\Container('Default', $manager);
     $object->getServiceLocator()->set('Zend\\Session\\Container', $session);
 }
Esempio n. 2
0
 public function getServiceConfig()
 {
     return array('factories' => array('Zend\\Session\\SessionManager' => function ($sm) {
         $db = $sm->get('Zend\\Db\\Adapter\\Adapter');
         $saveHandler = new SaveHandler();
         $saveHandler->setDb($db);
         $manager = new SessionManager();
         $manager->setSaveHandler($saveHandler);
         return $manager;
     }));
 }
Esempio n. 3
0
 public function onBootstrap(MvcEvent $e)
 {
     /* @var $sm \Zend\ServiceManager\ServiceManager */
     $sm = $e->getApplication()->getServiceManager();
     $config = $sm->get('Config');
     // bootstrap session
     $tableGateway = new TableGateway($config['app']['session.tableName'], $sm->get('dbAdapter'));
     $saveHandler = new DbTableGateway($tableGateway, new DbTableGatewayOptions());
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config['session']);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->setSaveHandler($saveHandler);
     $sessionManager->start();
     Container::setDefaultManager($sessionManager);
     // translate
     $sm->get('translator');
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     // bootstrap locale
     //     	$headers = $app->getRequest()->getHeaders();
     //     	Locale::setDefault($config['locale']['default']);
     //     	if($headers->has('Accept-Language')) {
     //     		$locales = $headers->get('Accept-Language')->getPrioritized();
     //     		// Loop through all locales, highest priority first
     //     		foreach($locales as $locale) {
     //     			if(!!($match = Locale::lookup($config['locale']['supported'], $locale->typeString))) {
     //     				// The locale is one of our supported list
     //     				Locale::setDefault($match);
     //     				break;
     //     			}
     //     		}
     //     		if(!$match) {
     //     			// Nothing from the supported list is a match
     //     			Locale::setDefault($config['locale']['default']);
     //     		}
     //     	}
     // switch layout
     $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\\Mvc\\Controller\\AbstractActionController', 'dispatch', function ($e) {
         $controller = $e->getTarget();
         $controllerClass = get_class($controller);
         $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
         $config = $e->getApplication()->getServiceManager()->get('config');
         $routeMatch = $e->getRouteMatch();
         $actionName = strtolower($routeMatch->getParam('action', 'not-found'));
         // get the action name
         if (isset($config['module_layouts'][$moduleNamespace][$actionName])) {
             $controller->layout($config['module_layouts'][$moduleNamespace][$actionName]);
         } elseif (isset($config['module_layouts'][$moduleNamespace]['default'])) {
             $controller->layout($config['module_layouts'][$moduleNamespace]['default']);
         }
     }, 100);
 }
Esempio n. 4
0
 public function initSession($config, \Zend\ServiceManager\ServiceManager $sm)
 {
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($config);
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->getValidatorChain()->attach('session.validate', array(new HttpUserAgent(), 'isValid'));
     $sessionManager->getValidatorChain()->attach('session.validate', array(new RemoteAddr(), 'isValid'));
     $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
     $tableGateway = new TableGateway(new TableIdentifier('sessions', 'users'), $dbAdapter);
     $saveHandler = new DbTableGateway($tableGateway, new DbTableGatewayOptions());
     $sessionManager->setSaveHandler($saveHandler);
     $sessionManager->start();
     Container::setDefaultManager($sessionManager);
 }
 public function __invoke()
 {
     $sessionConfig = new SessionConfig();
     $sessionConfig->setOptions($this->config['options']);
     $sessionManager = new SessionManager($sessionConfig);
     if (class_exists(\Redis::class)) {
         $saveHandler = new Redis($this->config['redis']['host'], $this->config['redis']['port'], $this->config['redis']['password']);
         $sessionManager->setSaveHandler($saveHandler);
         $sessionManager->start();
     } else {
         trigger_error('Redis extension is not found. ' . \Staticus\Auth\AuthSessionMiddleware::class . ' will not work.', E_USER_NOTICE);
     }
     return $sessionManager;
 }
Esempio n. 6
0
 public function onBootstrap(MvcEvent $e)
 {
     $eventManager = $e->getApplication()->getEventManager();
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->attach($eventManager);
     $settings = $e->getApplication()->getServiceManager()->get("Config");
     if (isset($settings['zDbSession']) && $settings['zDbSession']['enabled']) {
         $sessionConfig = new \Zend\Session\Config\SessionConfig();
         $sessionConfig->setOptions($settings['zDbSession']['sessionConfig']);
         $saveHandler = new DoctrineGateway($e->getApplication()->getServiceManager());
         $sessionManager = new SessionManager();
         $sessionManager->setConfig($sessionConfig);
         $sessionManager->setSaveHandler($saveHandler);
         Container::setDefaultManager($sessionManager);
         $sessionManager->start();
     }
 }
Esempio n. 7
0
 public function setSessionStorage()
 {
     $gwOpts = new DbTableGatewayOptions();
     $gwOpts->setDataColumn('data');
     $gwOpts->setIdColumn('id');
     $gwOpts->setLifetimeColumn('lifetime');
     $gwOpts->setModifiedColumn('modified');
     $gwOpts->setNameColumn('name');
     if (isset($this->serviceConfig['base64Encode']) && $this->serviceConfig['base64Encode']) {
         $saveHandler = new EncodedDbTableGateway($this->tblGW, $gwOpts);
     } else {
         $saveHandler = new DbTableGateway($this->tblGW, $gwOpts);
     }
     $sessionManager = new SessionManager();
     if ($this->sessionConfig) {
         $sessionConfig = new \Zend\Session\Config\SessionConfig();
         $sessionConfig->setOptions($this->sessionConfig);
         $sessionManager->setConfig($sessionConfig);
     }
     $sessionManager->setSaveHandler($saveHandler);
     Container::setDefaultManager($sessionManager);
     $sessionManager->start();
 }
Esempio n. 8
0
 /**
  * Create a session manager using the cache manager as storage
  * @return Zend\Session\Manager
  */
 public function _initSessionManager()
 {
     $container = $this;
     $this['sessionManager'] = $this->share(function () use($container) {
         $sessionConfigs = $container['configs']['session'];
         $saveHandler = new Cache($container['cacheManager']);
         $config = new SessionConfig();
         $config->setOptions($sessionConfigs);
         $manager = new SessionManager($config);
         $manager->setSaveHandler($saveHandler);
         Container::setDefaultManager($manager);
         return $manager;
     });
 }
Esempio n. 9
0
 /**
  * Create service
  *
  * @param ServiceLocatorInterface $sm Service manager
  *
  * @return mixed
  */
 public function createService(ServiceLocatorInterface $sm)
 {
     // Build configuration:
     $sessionConfig = new \Zend\Session\Config\SessionConfig();
     $sessionConfig->setOptions($this->getOptions($sm));
     // Build session manager and attach handler:
     $sessionManager = new SessionManager($sessionConfig);
     $sessionManager->setSaveHandler($this->getHandler($sm));
     // Start up the session:
     $sessionManager->start();
     // Check if we need to immediately stop it based on the settings object
     // (which may have been informed by a controller that sessions should not
     // be written as part of the current process):
     $settings = $sm->get('VuFind\\Session\\Settings');
     if ($settings->setSessionManager($sessionManager)->isWriteDisabled()) {
         $sessionManager->getSaveHandler()->disableWrites();
     } else {
         // If the session is not disabled, we should set up the normal
         // shutdown function:
         $this->registerShutdownFunction($sessionManager);
     }
     return $sessionManager;
 }
Esempio n. 10
0
 public function getServiceConfig()
 {
     return array('factories' => array('magic-methods' => function ($sm) {
         return new MagicMethods();
     }, 'neo4j' => function ($sm) {
         return new Client();
     }, 'mongo' => function ($sm) {
         $config = $sm->get('config');
         $config = $config['mongo'];
         $factory = new MongoConnectionFactory($config['server'], $config['server_options']);
         $connection = $factory->createService($sm);
         return $connection->selectDB($config['db']);
     }, 'logged_user_container' => function ($sm) {
         $config = $sm->get('config');
         if (isset($config['use_redis']) && $config['use_redis']) {
             $cache = StorageFactory::factory(array('adapter' => array('name' => 'redis', 'options' => array('server' => $config['redis'], 'ttl' => 7200))));
             $saveHandler = new Cache($cache);
             $manager = new SessionManager();
             $manager->setSaveHandler($saveHandler);
             Container::setDefaultManager($manager);
         }
         return new Container('logged_user');
     }));
 }
 public function __invoke(ServiceLocatorInterface $container)
 {
     $manager = new SessionManager();
     $manager->setSaveHandler($container->get('TweeServerLessSession\\Session\\SaveHandler\\ServerLess'));
     return $manager;
 }