forked from ZF-Commons/ZfcUser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
171 lines (155 loc) · 7.21 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
namespace ZfcUser;
use Zend\ModuleManager\ModuleManager;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods;
class Module implements
AutoloaderProviderInterface,
ConfigProviderInterface,
ServiceProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig($env = null)
{
return include __DIR__ . '/config/module.config.php';
}
public function getControllerPluginConfig()
{
return array(
'factories' => array(
'zfcUserAuthentication' => function ($sm) {
$serviceLocator = $sm->getServiceLocator();
$authService = $serviceLocator->get('zfcuser_auth_service');
$authAdapter = $serviceLocator->get('ZfcUser\Authentication\Adapter\AdapterChain');
$controllerPlugin = new Controller\Plugin\ZfcUserAuthentication;
$controllerPlugin->setAuthService($authService);
$controllerPlugin->setAuthAdapter($authAdapter);
return $controllerPlugin;
},
),
);
}
public function getViewHelperConfig()
{
return array(
'factories' => array(
'zfcUserDisplayName' => function ($sm) {
$locator = $sm->getServiceLocator();
$viewHelper = new View\Helper\ZfcUserDisplayName;
$viewHelper->setAuthService($locator->get('zfcuser_auth_service'));
return $viewHelper;
},
'zfcUserIdentity' => function ($sm) {
$locator = $sm->getServiceLocator();
$viewHelper = new View\Helper\ZfcUserIdentity;
$viewHelper->setAuthService($locator->get('zfcuser_auth_service'));
return $viewHelper;
},
'zfcUserLoginWidget' => function ($sm) {
$locator = $sm->getServiceLocator();
$viewHelper = new View\Helper\ZfcUserLoginWidget;
$viewHelper->setViewTemplate($locator->get('zfcuser_module_options')->getUserLoginWidgetViewTemplate());
$viewHelper->setLoginForm($locator->get('zfcuser_login_form'));
return $viewHelper;
},
),
);
}
public function getServiceConfig()
{
return array(
'invokables' => array(
'ZfcUser\Authentication\Adapter\Db' => 'ZfcUser\Authentication\Adapter\Db',
'ZfcUser\Authentication\Storage\Db' => 'ZfcUser\Authentication\Storage\Db',
'ZfcUser\Form\Login' => 'ZfcUser\Form\Login',
'zfcuser_user_service' => 'ZfcUser\Service\User',
'zfcuser_register_form_hydrator' => 'Zend\Stdlib\Hydrator\ClassMethods',
),
'factories' => array(
'zfcuser_module_options' => function ($sm) {
$config = $sm->get('Config');
return new Options\ModuleOptions(isset($config['zfcuser']) ? $config['zfcuser'] : array());
},
// We alias this one because it's ZfcUser's instance of
// Zend\Authentication\AuthenticationService. We don't want to
// hog the FQCN service alias for a Zend\* class.
'zfcuser_auth_service' => function ($sm) {
return new \Zend\Authentication\AuthenticationService(
$sm->get('ZfcUser\Authentication\Storage\Db'),
$sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
);
},
'ZfcUser\Authentication\Adapter\AdapterChain' => 'ZfcUser\Authentication\Adapter\AdapterChainServiceFactory',
'zfcuser_login_form' => function($sm) {
$options = $sm->get('zfcuser_module_options');
$form = new Form\Login(null, $options);
$form->setInputFilter(new Form\LoginFilter($options));
return $form;
},
'zfcuser_register_form' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
$form = new Form\Register(null, $options);
//$form->setCaptchaElement($sm->get('zfcuser_captcha_element'));
$form->setInputFilter(new Form\RegisterFilter(
new Validator\NoRecordExists(array(
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'email'
)),
new Validator\NoRecordExists(array(
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'username'
)),
$options
));
return $form;
},
'zfcuser_change_password_form' => function($sm) {
$options = $sm->get('zfcuser_module_options');
$form = new Form\ChangePassword(null, $sm->get('zfcuser_module_options'));
$form->setInputFilter(new Form\ChangePasswordFilter($options));
return $form;
},
'zfcuser_change_email_form' => function($sm) {
$options = $sm->get('zfcuser_module_options');
$form = new Form\ChangeEmail(null, $sm->get('zfcuser_module_options'));
$form->setInputFilter(new Form\ChangeEmailFilter(
$options,
new Validator\NoRecordExists(array(
'mapper' => $sm->get('zfcuser_user_mapper'),
'key' => 'email'
))
));
return $form;
},
'zfcuser_user_hydrator' => function ($sm) {
$hydrator = new \Zend\Stdlib\Hydrator\ClassMethods();
return $hydrator;
},
'zfcuser_user_mapper' => function ($sm) {
$options = $sm->get('zfcuser_module_options');
$mapper = new Mapper\User();
$mapper->setDbAdapter($sm->get('zfcuser_zend_db_adapter'));
$entityClass = $options->getUserEntityClass();
$mapper->setEntityPrototype(new $entityClass);
$mapper->setHydrator(new Mapper\UserHydrator());
$mapper->setTableName($options->getTableName());
return $mapper;
},
),
);
}
}