forked from samsonasik/SanAuthWithDbSaveHandler
/
Module.php
52 lines (45 loc) · 1.48 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
<?php
//filename : SanAuthWithDbSaveHandler/Module.php
namespace SanAuthWithDbSaveHandler;
use Zend\Mvc\MvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$em = $e->getApplication()->getEventManager();
$em->attach('route', array($this, 'checkAuthenticated'));
}
public function isOpenRequest(MvcEvent $e)
{
if ($e->getRouteMatch()->getParam('controller') == 'SanAuthWithDbSaveHandler\Controller\AuthController') {
return true;
}
return false;
}
public function checkAuthenticated(MvcEvent $e)
{
if (!$this->isOpenRequest($e)) {
$sm = $e->getApplication()->getServiceManager();
if (! $sm->get('AuthService')->getStorage()->getSessionManager()
->getSaveHandler()->read($sm->get('AuthService')->getStorage()->getSessionId())) {
$e->getRouteMatch()
->setParam('controller', 'SanAuthWithDbSaveHandler\Controller\Auth')
->setParam('action', 'index');
}
}
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
),
),
);
}
}