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