-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
101 lines (84 loc) · 3.88 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
* Dejan Cabrilo <[email protected]>
*
* @link https://github.com/cabrilo/BitDbSession for the canonical source repository
* @copyright Dejan Cabrilo
* @license https://raw.github.com/cabrilo/BitDbSession/master/LICENSE New BSD License
*/
namespace BitDbSession;
use Zend\Db\TableGateway\TableGateway;
use Zend\Mvc\MvcEvent;
use Zend\Session\Container;
use Zend\Session\SaveHandler\DbTableGateway;
use Zend\Session\SaveHandler\DbTableGatewayOptions;
use Zend\Session\SessionManager;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$a = 2;
$session = $e->getApplication()
->getServiceManager()
->get('Zend\Session\SessionManager');
$cfg = $e->getApplication()->getServiceManager()->get('Config');
$cfgSession = $cfg['session'];
$tableGateway = new TableGateway($cfgSession['table_name'], $e->getApplication()->getServiceManager()->get('Zend\Db\Adapter\Adapter'));
$saveHandler = new DbTableGateway($tableGateway, new DbTableGatewayOptions());
$session->setSaveHandler($saveHandler);
$session->start();
$container = new Container('initialized');
if (!isset($container->init)) {
$session->regenerateId(true);
$container->init = 1;
}
}
/**
* This was taken, pretty much verbatim, from http://framework.zend.com/manual/2.3/en/modules/zend.session.manager.html
*
* @return array
*/
public function getConfig()
{
return array(
'service_manager' => array(
'factories' => array(
'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'])) {
$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();
}
Container::setDefaultManager($sessionManager);
return $sessionManager;
},
)
)
);
}
}