forked from ZF-Commons/ZfcUser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
190 lines (171 loc) · 7.89 KB
/
Module.php
File metadata and controls
190 lines (171 loc) · 7.89 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
namespace ZfcUser;
use Zend\Console\Adapter\AdapterInterface as Console;
use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface;
use Zend\ModuleManager\ModuleManager;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
class Module implements
AutoloaderProviderInterface,
ConfigProviderInterface,
ServiceProviderInterface,
ConsoleUsageProviderInterface
{
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',
),
'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());
return $mapper;
},
),
);
}
/**
* Define Console Help text
*
*/
public function getConsoleUsage(Console $console)
{
return array(
'user list [--state=] [--fields=]' => 'List all users in the database.',
'user view <id>' => 'View specified user details.',
'user register <email> [--password=] [--username=] [--displayname=] [--state=]'
=> 'Registers a new user into database.',
array('--state=', 'User state value (Integer).'),
array('--fields=', 'Comma-separated list of fields to display.'),
array('<id>', 'User identification, accepts: id number, email, or username.'),
);
}
}