我有一个扩展BaseUser的自定义User类。
我被告知,为了利用用户锁定功能,我的用户类需要实现AdvancedUserInterface,但似乎我不能在User类上同时执行EXTENDS和IMPLEMENTS?
<?php
// src/BizTV/UserBundle/Entity/User.php
namespace BizTV\UserBundle\Entity;
use BizTV\UserBundle\Validator\Constraints as BizTVAssert;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use BizTV\BackendBundle\Entity\company as company;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser implements AdvancedUserInterface
{
使用这种方法我没有收到任何错误消息,但我也没有使用这些函数来检查用户锁定,所以似乎没有任何反应。
如果我这样切换它们,
class User implements AdvancedUserInterface extends BaseUser
我收到以下错误消息:
Parse error: syntax error, unexpected T_EXTENDS, expecting '{' in /var/www/cloudsign/src/BizTV/UserBundle/Entity/User.php on line 18
答案 0 :(得分:0)
好的,我解决了这个问题:
向用户实体添加我自己的函数以获取Lock状态(我没有定义的变量,它已经在我正在扩展的用户类中
//Below should be part of base user class but doesn't work so I implement it manually.
/**
* Get lock status
*
* @return boolean
*/
public function getLocked()
{
return $this->locked;
}
在UserChecker中,我把它放在了:
public function checkPreAuth(UserInterface $user)
{
//Test for companylock...
if ( !$user->getCompany()->getActive() ) {
throw new LockedException('The company of this user is locked.', $user);
}
if ( $user->getLocked() ) {
throw new LockedException('The admin of this company has locked this user.', $user);
}
...
/**
* {@inheritdoc}
*/
public function checkPostAuth(UserInterface $user)
{
//Test for companylock...
if ( !$user->getCompany()->getActive() ) {
throw new LockedException('The company of this user is locked.', $user);
}
if ( $user->getLocked() ) {
throw new LockedException('The admin of this company has locked this user.', $user);
}