本文整理汇总了PHP中Zend\Session\Container::setDefaultManager方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::setDefaultManager方法的具体用法?PHP Container::setDefaultManager怎么用?PHP Container::setDefaultManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Session\Container
的用法示例。
在下文中一共展示了Container::setDefaultManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setSessionStorage
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;
}
示例2: onBootstrap
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
// Listeners to ensure that we always send back JSON.
// If we set a 404 in the ViewModel, then the RouteNotFoundStrategy will add it's own
// fields to the ViewModel, so detect a 404 first and respond to it
$eventManager->getSharedManager()->attach('Zend\\Stdlib\\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($this, 'detect404'), -89);
// Ensure we always render JSON
$eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'ensureJsonModel'), 999);
// Turn errors into JSON
// $eventManager->attach(MvcEvent::EVENT_RENDER, array($this, 'renderError'));
//*********Session
$sm = $e->getApplication()->getServiceManager();
$config = $sm->get('session_config');
$storage = null;
if ($sm->has('session_storage', false)) {
$storage = $sm->get('session_storage');
}
$saveHandler = null;
if ($sm->has('session_save_handler', false)) {
$saveHandler = $sm->get('session_save_handler');
}
$sessionManager = new SessionManager($config, $storage, $saveHandler);
Container::setDefaultManager($sessionManager);
//$sessionManager->start();
}
示例3: onBootstrap
public function onBootstrap(EventInterface $e)
{
/** @var \Zend\Mvc\Application $app */
$app = $e->getTarget();
$config = $app->getConfig();
$sessionConfig = new SessionConfig();
if (isset($config['session']['options'])) {
$options = $config['session']['options'];
if (isset($options['cookie_domain']) && strpos($_SERVER['SERVER_NAME'], $options['cookie_domain']) === false) {
$options['cookie_domain'] = $_SERVER['SERVER_NAME'];
}
$sessionConfig->setOptions($options);
}
$serviceManager = $app->getServiceManager();
$storage = null;
$saveHandler = null;
if ($serviceManager->has('Session\\Service\\Storage', false)) {
/** @var \Zend\Session\Storage\StorageInterface $storage */
$storage = $serviceManager->get('Session\\Service\\Storage');
}
if ($serviceManager->has('Session\\Service\\SaveHandler', false)) {
/** @var \Zend\Session\SaveHandler\SaveHandlerInterface $saveHandler */
$saveHandler = $serviceManager->get('Session\\Service\\SaveHandler');
}
Container::setDefaultManager(new SessionManager($sessionConfig, $storage, $saveHandler));
}
示例4: testCanSetDefaultManagerToNull
public function testCanSetDefaultManagerToNull()
{
$manager = new TestAsset\TestManager();
Container::setDefaultManager($manager);
Container::setDefaultManager(null);
$this->assertNotSame($manager, Container::getDefaultManager());
}
示例5: createService
/**
* @param ServiceLocatorInterface $sm
* @return SessionManager
*/
public function createService(ServiceLocatorInterface $sm)
{
$config = $sm->get('config');
if (isset($config['session'])) {
$session = $config['session'];
$sessionConfig = null;
if (isset($session['config'])) {
$class = isset($session['config']['class']) ? $session['config']['class'] : 'Zend\\Session\\Config\\SessionConfig';
$options = isset($session['config']['options']) ? $session['config']['options'] : array();
$sessionConfig = new $class();
$sessionConfig->setOptions($options);
}
$sessionStorage = null;
if (isset($session['storage'])) {
$class = $session['storage'];
$sessionStorage = new $class();
}
$sessionSaveHandler = null;
if (isset($session['save_handler'])) {
$sessionSaveHandler = $sm->get($session['save_handler']);
}
$sessionManager = new SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler);
} else {
$sessionManager = new SessionManager();
}
Container::setDefaultManager($sessionManager);
return $sessionManager;
}
示例6: getServiceConfig
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;
}));
}
示例7: __invoke
public function __invoke(ContainerInterface $container)
{
$manager = new SessionManager();
Container::setDefaultManager($manager);
$realSessionContainer = new Container('zend_expressive');
return new SessionContainer($realSessionContainer);
}
示例8: createService
public function createService(\Zend\ServiceManager\ServiceLocatorInterface $sm)
{
$config = $sm->get('config');
if (isset($config['session'])) {
$session = $config['session'];
$sessionConfig = null;
if (isset($session['config'])) {
$class = isset($session['config']['class']) ? $session['config']['class'] : 'Zend\\Session\\Config\\SessionConfig';
$options = isset($session['config']['options']) ? $session['config']['options'] : array();
$sessionConfig = new $class();
$sessionConfig->setOptions($options);
}
$sessionStorage = null;
if (isset($session['storage'])) {
$class = $session['storage'];
$sessionStorage = new $class();
}
$sessionSaveHandler = null;
if (isset($session['save_handler'])) {
// class should be fetched from service manager since it will require constructor arguments
$sessionSaveHandler = $sm->get($session['save_handler']);
}
$sessionManager = new self($sessionConfig, $sessionStorage, $sessionSaveHandler);
} else {
$sessionManager = new self();
}
\Zend\Session\Container::setDefaultManager($sessionManager);
return $sessionManager;
}
示例9: initSession
public function initSession($config)
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
示例10: sessionStart
public function sessionStart(MvcEvent $event)
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions(array());
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
示例11: bootstrapSession
public function bootstrapSession($e)
{
$sessionManager = $e->getApplication()->getServiceManager()->get('Zend\\Session\\SessionManager');
// TODO start session if session cookie exists?
//$session->start();
// ensure this session manager is used by default
Container::setDefaultManager($sessionManager);
}
示例12: tearDown
public function tearDown()
{
$ref = new \ReflectionClass('Zend\\Validator\\Csrf');
$hashCache = $ref->getProperty('hashCache');
$hashCache->setAccessible(true);
$hashCache->setValue(new Csrf(), array());
SessionContainer::setDefaultManager(null);
}
示例13: __invoke
public function __invoke(ContainerInterface $container)
{
/** @var SessionManager $manager */
$manager = $container->get(SessionManager::class);
SessionContainer::setDefaultManager($manager);
$manager->start();
return new SessionMiddleware();
}
示例14: init
/**
* @return void
*/
private function init()
{
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($this->config);
$sessionManager = new SessionManager($sessionConfig);
$sessionManager->start();
Container::setDefaultManager($sessionManager);
}
示例15: getServiceConfig
public function getServiceConfig()
{
return array('factories' => array('JYLibrary\\Model\\SessionTable' => function ($sm) {
$dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
$table = new SessionTable($dbAdapter);
return $table;
}, 'Zend\\Session\\SessionManager' => function ($sm) {
$config = $sm->get('config');
if (isset($config['session'])) {
$session = $config['session'];
$sessionConfig = null;
if (isset($session['config'])) {
$class = isset($session['config']['class']) ? $session['config']['class'] : 'Zend\\Session\\Config\\SessionConfig';
$options = isset($session['config']['options']) ? $session['config']['options'] : array();
$sessionConfig = new $class();
$sessionConfig->setOptions($options);
}
$sessionStorage = null;
if (isset($session['storage'])) {
$class = $session['storage'];
$sessionStorage = new $class();
}
$sessionSaveHandler = null;
if (isset($session['save_handler'])) {
// class should be fetched from service manager since it will require constructor arguments
$sessionSaveHandler = $sm->get($session['save_handler']);
}
$sessionManager = new SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler);
if (isset($session['validator'])) {
$chain = $sessionManager->getValidatorChain();
foreach ($session['validator'] as $validator) {
$validator = new $validator();
$chain->attach('session.validate', array($validator, 'isValid'));
}
}
} else {
$sessionManager = new SessionManager();
/*
$adapter = new \Zend\Db\Adapter\Adapter(array(
'driver' => 'Mysqli',
'database' => 'jymobile',
'username' => 'root',
'password' => '',
'hostname'=>'localhost'
));
$tableGateway = new TableGateway('session', $adapter);
$saveHandler = new DbTableGateway($tableGateway, new DbTableGatewayOptions());
$manager = new SessionManager();
$manager->setSaveHandler($saveHandler);
//echo '×Ô¶¨ÒåsessionManager';
*/
}
Container::setDefaultManager($sessionManager);
return $sessionManager;
}));
}