我有一个自定义的AuthenticationService实现,我想在ZfcUser模块中使用它,但我可以将这个类设置到模块中。这个实现似乎是固定的。
供应商\zf-commons\zfc-user\Module.php
'zfcuser_auth_service' => function ($sm) {
return new \Zend\Authentication\AuthenticationService(
$sm->get('ZfcUser\Authentication\Storage\Db'),
$sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
);
}最初的需求是为我的CustomAuthenticationService中实现的每个用户保持一个唯一的活动会话。有什么办法来解决这个问题吗?
发布于 2015-07-28 22:22:39
您的用例并不明确;通常情况下,身份验证适配器是您通常要定制的类,而不是实际的身份验证服务。
但是,您可以使用自己的服务覆盖默认服务,前提是您使用相同的名称注册服务,并且模块在ZfcUser模块之后加载。
假设您的自定义身份验证服务位于您自己的Auth名称空间/模块中,其类为Auth\Service\CustomAuthenticationService。
在Auth\Module.php中注册服务(或根据工厂的类型,即该模块的module.config.php )。
class Module
{
public function getServiceConfig()
{
return [
'aliases' => [
'MyAuthenticationService' => 'zfcuser_auth_service',
],
'factories' => [
'zfcuser_auth_service' => function($sm) {
return new \Auth\Service\CustomAuthenticationService(
$sm->get('ZfcUser\Authentication\Storage\Db'),
$sm->get('ZfcUser\Authentication\Adapter\AdapterChain')
);
},
],
];
}
}最后,确保在application.config.php中的ZfcUser之后加载模块。
return [
'modules' => [
//...
'ZfcUser',
'Auth',
// ...
],
];发布于 2015-07-28 23:09:13
当执行登录操作时,就会触发身份验证适配器。要处理每个请求,您可以覆盖允许在每个请求中验证标识符的存储适配器。在您的配置文件中,为您的自定义存储类添加一个'ZfcUser\Authentication\ storage \Db‘属性。
'service_manager' => array(
'invokables' => array(
'ZfcUser\Authentication\Storage\Db' => 'MyCustom\Authentication\Storage'),
...https://stackoverflow.com/questions/31664205
复制相似问题