如何在 PHP 属性中创建实例数组
How to create an instance array in PHP Attributes
使用 Doctrine 注释可以构建以下映射:
/**
* @ORM\Table(indexes={
* @ORM\Index(name="first_index", columns={"username","password","email"}),
* @ORM\Index(name="second_index", columns={"email"}),
* @ORM\Index(name="third_index", columns={"email", "username","language"})
* })
*/
class SomeClass
{
将其重构为 PHP 属性时,我正在尝试
#[ORM\Table(
indexes: [
['name' => 'first_index', 'columns' => ['username', 'password', 'email']],
['name' => 'second_index', 'columns' => ['email']],
['name' => 'third_index', 'columns' => ['email', 'username','language']]
]
)]
class SomeClass
{
但是我的 IDE 抱怨这是一个 string[]
,而不是它需要的预期 ORM\Index[]
。
(而且,Doctrine 会抛出带有消息 Class "SomeClass" is not a valid entity or mapped super class.
的 MappingException。)
所以实际上我的问题是:如何在 ORM\Table
属性中获取 ORM\Index
个实例的数组?
我尝试过的其他选项:
#[ORM\Table(
indexes: [
#[ORM\Index(name: 'first_index', columns: ['username', 'password', 'email'])],
]
)]
class SomeClass
{
但这会破坏属性注释。
不幸的是,非常基本的 Doctrine attributes documentation 没有演示相关示例。
#[Index]
应该是一个单独的语句,而不是 #[Table]
:
的一部分
#[ORM\Table]
#[ORM\Index(name: 'first_index', columns: ['username', 'password', 'email'])]
#[ORM\Index(name: 'second_index', columns: ['email'])]
#[ORM\Index(name: 'third_index', columns: ['email', 'username','language'])]
class SomeClass
{
有关示例,请参阅文档的 this part。
使用 Doctrine 注释可以构建以下映射:
/**
* @ORM\Table(indexes={
* @ORM\Index(name="first_index", columns={"username","password","email"}),
* @ORM\Index(name="second_index", columns={"email"}),
* @ORM\Index(name="third_index", columns={"email", "username","language"})
* })
*/
class SomeClass
{
将其重构为 PHP 属性时,我正在尝试
#[ORM\Table(
indexes: [
['name' => 'first_index', 'columns' => ['username', 'password', 'email']],
['name' => 'second_index', 'columns' => ['email']],
['name' => 'third_index', 'columns' => ['email', 'username','language']]
]
)]
class SomeClass
{
但是我的 IDE 抱怨这是一个 string[]
,而不是它需要的预期 ORM\Index[]
。
(而且,Doctrine 会抛出带有消息 Class "SomeClass" is not a valid entity or mapped super class.
的 MappingException。)
所以实际上我的问题是:如何在 ORM\Table
属性中获取 ORM\Index
个实例的数组?
我尝试过的其他选项:
#[ORM\Table(
indexes: [
#[ORM\Index(name: 'first_index', columns: ['username', 'password', 'email'])],
]
)]
class SomeClass
{
但这会破坏属性注释。 不幸的是,非常基本的 Doctrine attributes documentation 没有演示相关示例。
#[Index]
应该是一个单独的语句,而不是 #[Table]
:
#[ORM\Table]
#[ORM\Index(name: 'first_index', columns: ['username', 'password', 'email'])]
#[ORM\Index(name: 'second_index', columns: ['email'])]
#[ORM\Index(name: 'third_index', columns: ['email', 'username','language'])]
class SomeClass
{
有关示例,请参阅文档的 this part。