public function setSessionStorage() { $options = new DbTableGatewayOptions(); $options->setDataColumn('session_data')->setIdColumn('session_id')->setLifetimeColumn('life_time')->setModifiedColumn('update_time')->setNameColumn('session_name'); $handler = new DbTableGateway($this->tblgw, $options); $this->sessionManager = new SessionManager(); $this->sessionManager->setSaveHandler($handler); if ($this->sessionConfig) { $options = gv('options', $this->sessionConfig); $sessionConfig = new \Zend\Session\Config\SessionConfig(); $sessionConfig->setOptions($options); $this->sessionManager->setConfig($sessionConfig); } $this->sessionManager->setSaveHandler($handler); Container::setDefaultManager($this->sessionManager); $this->sessionManager->start(); $this->container = new Container('init'); if (!$this->container->init) { $request = $this->request; $this->container->init = 1; $this->container->remoteAddr = $request->getServer()->get('REMOTE_ADDR'); $this->container->httpUserAgent = $request->getServer()->get('HTTP_USER_AGENT'); $this->container->create = time(); } // update session id if (SESSION_ID_EXPIRE < time() - $this->container->create) { $this->sessionManager->regenerateId(true); $this->container->create = time(); } return $this->sessionManager; }
public function getServiceConfig() { return array('abstract_factories' => array('Zend\\Cache\\Service\\StorageCacheAbstractServiceFactory', 'Zend\\Log\\LoggerAbstractServiceFactory'), 'factories' => array('translator' => 'Zend\\Mvc\\Service\\TranslatorServiceFactory', 'Application\\SessionManager' => function ($sm) { $config = $sm->get('Config'); if (isset($config['session'])) { $session = $config['session']; $sessionConfig = null; if (isset($session)) { $sessionConfig = new \Zend\Session\Config\SessionConfig(); $sessionConfig->setOptions($session); } $storagePath = ''; if (isset($config['app_base_dir'])) { $storagePath = $config['app_base_dir'] . DIRECTORY_SEPARATOR; } $storagePath .= '/data/sessions/cache'; $fileCacheStorage = new \Zend\Cache\Storage\Adapter\FileSystem(['cache_dir' => $storagePath]); $sessionSaveHandler = new \Zend\Session\SaveHandler\Cache($fileCacheStorage); $sessionManager = new \Zend\Session\SessionManager($sessionConfig, null, $sessionSaveHandler); if (isset($session['validators'])) { $chain = $sessionManager->getValidatorChain(); foreach ($session['validators'] as $validator) { $validator = new $validator(); $chain->attach('session.validate', array($validator, 'isValid')); } } } else { $sessionManager = new \Zend\Session\SessionManager(); } \Zend\Session\Container::setDefaultManager($sessionManager); return $sessionManager; })); }
/** * @see \Zend\ServiceManager\FactoryInterface::createService() * @param \Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator * @return \Zend\Session\SessionManager */ public function createService(\Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator) { $oSessionConfig = new \Zend\Session\Config\SessionConfig(); $aConfiguration = $oServiceLocator->get('config'); if (isset($aConfiguration['authentication']['remember_me_ttl'])) { $oSessionConfig->setRememberMeSeconds($aConfiguration['authentication']['remember_me_ttl']); } return new \Zend\Session\SessionManager($oSessionConfig); }
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(); } }
/** * Construct the Session Manager. * * @param ServiceManager $sm Service manager. * * @return \Zend\Session\SessionManager */ public static function getSessionManager(ServiceManager $sm) { $cookieManager = $sm->get('Resources\\CookieManager'); $sessionConfig = new \Zend\Session\Config\SessionConfig(); $options = ['cookie_path' => $cookieManager->getPath(), 'cookie_secure' => $cookieManager->isSecure()]; $domain = $cookieManager->getDomain(); if (!empty($domain)) { $options['cookie_domain'] = $domain; } $sessionConfig->setOptions($options); return new \Zend\Session\SessionManager($sessionConfig); }
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(); }
use Application\Service\SettingsService; use Application\Service\StatisticsService; use Application\Service\SupplierService; use Application\Service\TemplateService; use Application\Service\WarehouseDocumentService; use Application\Service\WarehouseService; use Application\View\Helper\Messages; use DoctrineModule\Persistence\ObjectManagerAwareInterface; use Zend\Mvc\Controller\ControllerManager; use Zend\ServiceManager\ServiceManager; use Zend\Validator\Translator\TranslatorAwareInterface; return array('router' => array('routes' => array('home' => array('type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => array('route' => '/', 'defaults' => array('controller' => 'Application\\Controller\\Index', 'action' => 'index'))), 'language' => array('type' => 'Segment', 'options' => array('route' => '/language/:language', 'defaults' => array('__NAMESPACE__' => 'Application\\Controller', 'controller' => 'Index', 'action' => 'language'))), 'application' => array('type' => 'Segment', 'options' => array('route' => '/application[/:controller[/:action]]', 'constraints' => array('controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*'), 'defaults' => array('__NAMESPACE__' => 'Application\\Controller', 'controller' => 'Index', 'action' => 'index')), 'may_terminate' => true, 'child_routes' => array('default' => array('type' => 'wildcard'))))), 'service_manager' => array('abstract_factories' => array('Zend\\Cache\\Service\\StorageCacheAbstractServiceFactory', 'Zend\\Log\\LoggerAbstractServiceFactory'), 'aliases' => array('translator' => 'MvcTranslator'), 'invokables' => array(), 'factories' => array('sessionManager' => function (ServiceManager $sm) { $sessionManager = new \Zend\Session\SessionManager(); $configuration = $sm->get('Config'); if (isset($configuration['sessionConfiguration'])) { $sessionConfig = new \Zend\Session\Config\SessionConfig(); if (isset($configuration['sessionConfiguration']['rememberMeSeconds'])) { $sessionConfig->setRememberMeSeconds($configuration['sessionConfiguration']['rememberMeSeconds']); } if (isset($configuration['sessionConfiguration']['savePath'])) { $target = $configuration['sessionConfiguration']['savePath']; if ($target === true) { $target = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . '/../data/session'; } if (!file_exists($target)) { mkdir($target); } $sessionConfig->setSavePath($target); } if (isset($configuration['sessionConfiguration']['options'])) { $sessionConfig->setOptions($configuration['sessionConfiguration']['options']);
/** * 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; }