Php 将AuthenticationService自定义到ZfcUser

Php 将AuthenticationService自定义到ZfcUser,php,zend-framework,zend-framework2,zfcuser,Php,Zend Framework,Zend Framework2,Zfcuser,我有一个AuthenticationService的自定义实现,我希望在ZfcUser模块中使用它,但我能够将此类设置到模块中。实现似乎是固定的 供应商\zf commons\zfc user\Module.php 'zfcuser_auth_service' => function ($sm) { return new \Zend\Authentication\AuthenticationService( $sm->get('ZfcUser\Authent

我有一个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')
      );
 }

最初的要求是在my CustomAuthenticationService中为每个用户保留一个唯一的活动会话。有什么办法可以解决这个问题吗?

您的用例不清楚;通常,身份验证适配器是您通常自定义的类,而不是实际的身份验证服务

但是,如果您使用相同的名称注册服务,并且模块加载在
ZfcUser
模块之后,您可以使用自己的服务覆盖默认服务

假设您的自定义身份验证服务位于您自己的
Auth
命名空间/模块中,类为
Auth\service\CustomAuthenticationService

Auth\Module.php
中注册服务(或者根据该模块的
Module.config.php
工厂类型)

最后,确保在
application.config.php
中的
ZfcUser
之后加载模块

return [
    'modules' => [
        //...
        'ZfcUser',
        'Auth',
        // ...
    ],
];

当执行登录操作时,将触发auth适配器。要处理每个请求,您可以覆盖允许验证每个请求中的标识的存储适配器。在配置文件中,向自定义存储类添加“ZfcUser\Authentication\Storage\Db”属性点

'service_manager' => array(
    'invokables' => array(
    'ZfcUser\Authentication\Storage\Db' => 'MyCustom\Authentication\Storage'),
...

你想完成什么?我想确保用户只有一个活动会话。你需要自定义服务吗?请您详细解释一下什么不起作用…我正在使用ZfcUser控制我的身份验证,每次请求此AuthenticationService都会验证我是否具有身份,然后我会在自定义AuthenticationService中重写此行为,现在我看不到如何在不更改供应商代码的情况下将自定义身份验证服务注入ZfcUser。嘿,你是如何做到这一点的?你找到有效的解决办法了吗?我也有同样的问题here@user2819732我拒绝了你对我答案的编辑。请添加您的工作解决方案作为您自己的答案,然后将其视为正确答案。否则,其他寻求类似解决方案的人可能会感到困惑。
'service_manager' => array(
    'invokables' => array(
    'ZfcUser\Authentication\Storage\Db' => 'MyCustom\Authentication\Storage'),
...