【发布时间】:2013-08-01 22:27:19
【问题描述】:
我正在尝试扩展一个类,而我只需要 UserProvider。
我认为传入 '@security.context' 服务并执行下面的代码可以做到,但它不起作用(它只是说 $security_context 不是对象);
// $security_context holds the passed in $security_context service
$security_context->getToken()->getUser(); // doesn't work
如果这有所作为,我正在使用 FOSUserBundle。
当我将它传递给 __construct 时,可能尚未创建用户,但我不确定发生了什么。
那么我如何获得这个用户提供者呢?是否有 security.user_provider 服务?
该脚本允许一组用户提供者,但我只需要并且拥有一个。
--
完整配置:
services.yml:
security.authentication.rememberme.services.simplehash: #override/extend this class
class: Acme\MyBundle\ExtendRememberMe
parent: security.authentication.rememberme.services.abstract
abstract: true
arguments:
- "@security.context"
- "@doctrine.orm.entity_manager"
Acme\MyBundle\ExtendRememberMe.php
public function __construct( $security_context, $doctrine_entity_manager ) {
$userProviders = array( $security_context->getToken()->getUser() );
//etc. (but error due to above line)
{
【问题讨论】:
-
你能说明你在哪里定义你的服务和你的服务构造函数吗?
-
已更新。感谢您的帮助。