1

我正在阅读UserMapper来自的代码,ZfcUser Zend Framework Module 因为我认为在我构建我的并且对某些东西感到好奇之前,我可以了解使用 zends auth 系统的一般概念。

在其中(单击此处),在第 19 行,我们有以下代码:

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

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

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

4

1 回答 1

1

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

更多,ZfcUser可以和BjyAuthorize、roleuserbridge其他模块一起使用,提供更多的功能(acl和用户角色管理...),这些第三方模块可以使用ZfcUser.

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

$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,它不是这个模块未来开发的占位符,它是你的一个钩子,如果你需要在用户存储库中找到用户时做某事......

于 2016-09-14T17:14:28.610 回答