-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
103 lines (86 loc) · 3.59 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
101
102
103
<?php
namespace Auth;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
use Zend\Session\Config\SessionConfig;
use Zend\Session\SessionManager;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Storage\Session as SessionStorage;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$eventManager->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', array($this, 'setLayout'), 100);
}
public function setLayout(MvcEvent $e)
{
$controller = $e->getTarget();
$config = $e->getApplication()->getServiceManager()->get('config');
$controllerClass = get_class($controller);
$moduleNamespace = strtolower(substr($controllerClass, 0, strpos($controllerClass, '\\')));
if (isset($config['view_manager']['template_map']['layout/'.$moduleNamespace])) {
$controller->layout('layout/'.$moduleNamespace);
}
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getServiceConfig()
{
return array(
'factories' => array(
'Auth\Adapter\Authentication' => function($sm) {
$config = $sm->get('Auth\Config');
$config = $config['Authentication\Adapter'];
if (isset($config['type']) && $config['type'] == 'mongo') {
return new \Auth\Adapter\MongoAuthenticate($sm->get('doctrine.documentmanager.odm_default'));
} elseif (isset($config['type']) && $config['type'] == 'dbtable') {
}
return null;
},
'Auth\Adapter\Session\StorageManager' => function ($sm) {
$config = $sm->get('Auth\Config');
$config = $config['Session\Storage'];
$sessionConfig = new SessionConfig();
$sessionConfig->setOptions($config[$config['type']]);
var_dump($sessionConfig);exit;
//$sessionManager = new SessionManager($sessionConfig);
var_dump($sessionManager);exit;
},
'Auth\Identity' => function ($sm) {
$auth = new AuthenticationService;
$auth->setStorage(new SessionStorage("Auth", null, $sm->get('Auth\Adapter\Session\StorageManager')));
return $auth->getIdentity();
},
'Auth\Config' => function ($sm) {
$config = $sm->get('config');
return $config['Auth\Config'];
},
),
);
}
public function getViewHelperConfig()
{
return array(
'factories' => array(
'identityHelper' => function($sm) {
return new \Auth\View\Helper\IdentityHelper($sm->getServiceLocator()->get('Auth\Adapter\Session\StorageManager'));
}
),
);
}
}