无法通过查看 ZfcUser User Mapper 代码找到事件

Cannot find event from looking at ZfcUser User Mapper code

我正在阅读 ZfcUser Zend Framework Module 中的 UserMapper 代码,因为我认为在构建我的系统之前我可以获得使用 zends 身份验证系统的一般概念并且对某些事情感到好奇。

其中(click here),第19行,我们有如下代码:

$this->getEventManager()->trigger('find', $this, array('entity' => $entity));

我真的很想知道在哪里可以找到正在触发的 "find" 事件,或者它是否是未来可能的查找事件的占位符

我查看了模块文件和其他几个文件,但找不到它

Zfcuser 是一个非常完整的模块,具有许多在普通基本身份验证中您不需要的功能。这些功能包括几个 ZfcUser 触发但不需要它的事件,它只是为了防止用户需要对此事件执行特定操作。

更多,ZfcUser可以像BjyAuthorize and roleuserbridge一样与其他模块一起使用,以提供更多功能(acl和用户角色管理...),并且这些第三方模块可以使用触发的事件通过 ZfcUser.

例如,您想记录每个用户身份验证,您可以在 onBootstrap() 方法中以这种方式使用 authenticate 事件:(示例来自 here):

$sm = $e->getApplication()->getServiceManager();
$zfcAuthEvents = $e->getApplication()->getServiceManager()->get('ZfcUser\Authentication\Adapter\AdapterChain')->getEventManager();

$zfcAuthEvents->attach( 'authenticate', function( $authEvent ) use( $sm ){
    try {
        $remote     = new \Zend\Http\PhpEnvironment\RemoteAddress;
        $remote->setUseProxy( true );

        $mapper     =  $sm->get( 'auth_log_mapper' );
        $log_entity = new \FooUser\Entity\UserAuthenticationLog;
        $log_entity->populate(
                array(
               'user_id'       => $authEvent->getIdentity(),
                'auth_time'     => new \DateTime( "now" ),
                'ip_address'    => $remote->getIpAddress()
            )
        );

        $mapper->save( $log_entity );
        return true;
    } catch( \Exception $x ) {
        // handle it
    }
});

所以 find 事件可能对 ZfcUser 没有用,它不是这个模块未来开发的占位符,它是你的一个钩子,如果你需要做一些事情当在用户存储库中找到用户时...