本文整理匯總了PHP中Zend\Session\SessionManager::setSaveHandler方法的典型用法代碼示例。如果您正苦於以下問題:PHP SessionManager::setSaveHandler方法的具體用法?PHP SessionManager::setSaveHandler怎麽用?PHP SessionManager::setSaveHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend\Session\SessionManager
的用法示例。
在下文中一共展示了SessionManager::setSaveHandler方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: configure
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);
}
示例2: getServiceConfig
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;
}));
}
示例3: onBootstrap
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);
}
示例4: initSession
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);
}
示例5: __invoke
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;
}
示例6: onBootstrap
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();
}
}
示例7: setSessionStorage
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();
}
示例8: _initSessionManager
/**
* 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;
});
}
示例9: createService
/**
* 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;
}
示例10: getServiceConfig
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');
}));
}
示例11: __invoke
public function __invoke(ServiceLocatorInterface $container)
{
$manager = new SessionManager();
$manager->setSaveHandler($container->get('TweeServerLessSession\\Session\\SaveHandler\\ServerLess'));
return $manager;
}