3

我们可以覆盖模型访问器属性名称或忽略它吗?

这是我的User::getUsername函数,它是电子邮件属性的吸气剂(我需要这样命名的函数来实现接口):

class User extends AbstractDocument implements AdvancedUserInterface, EquatableInterface
{
    /**
     * @var string
     * @Assert\NotBlank()
     * @Assert\Email()
     * @SWG\Property(
     *     description="The email of the user",
     *     example="example@company.com"
     * )
     */
    private $email;

    //...

    /**
     * Returns the username used to authenticate the user.
     * @return string The user email
     * @SWG\Property(property="email")
     */
    public function getUsername()
    {
        return $this->email;
    }
}

并且生成的文档仍然显示:

{
  "User": {
    "properties":{
      "email":{  
        "description":"The email of the user",
        "example":"example@company.com",
        "type":"string"
      },
      "username":{  
        "type":"string"
      }
    }
  }
}

你能帮我吗?

4

0 回答 0