如何将 DoctrineMigrationsBundle 与 yaml 文件一起使用?

How to use DoctrineMigrationsBundle with yaml file?

当我像上面的例子一样使用 Doctrine Annotation 文件时,命令 php bin/console doctrine:migrations:diff 工作得很好。

#src/Entity/User.php

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity(repositoryClass="Repository\UserRepository")
 * @ORM\Table(
 *     schema="data",
 *     name="ts_user",
 *     options={"comment":"Utilisateurs de l'application"},
 *     uniqueConstraints={@ORM\UniqueConstraint(name="uk_usr_email", columns={"usr_email"})}
 * )
 */
class User
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer", name="usr_id")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="text", nullable=true, name="usr_name")
     */
    private $name;

    /**
     * @ORM\Column(type="text", nullable=false, name="usr_email")
     */
    private $email;

    /**
     * @ORM\Column(type="text", nullable=true, name="usr_password")
     */
    private $password;
}

出于某些原因(特征、接口),我必须使用 doctrine yaml 文件来声明我的实体。一旦我用 yaml 文件替换注释,迁移命令就会抛出此错误:

In OrmSchemaProvider.php line 41:

No mapping information to process

这是我的 yaml 文件:

#src/Resources/config/doctrine/User.orm.yml
App\Entity\User:
  type: entity
  schema: data
  table: ts_user
  repositoryClass: Repository\UserRepository
  id:
    id:
      type: integer
      column: usr_id
      generator:
        strategy: AUTO
  fields:
    name:
      type: text
      nullable: true
      column: usr_name
    email:
      type: text
      nullable: false
      column: usr_email
    password:
      type: text
      nullable: true
      column: usr_password
  uniqueConstraints:
    uk_usr_email:
      columns: [usr_email]
  options:
    comment: Utilisateurs de l'application

由于这个错误,我认为它没有找到我的 yaml 文件。它在错误的目录中吗?把这个文件放在哪里?我在源代码中没有看到任何声明我的 yaml 文件的目录。我已经在这个目录中尝试过但没有成功:

我做错了什么?

环境:PHP 7.2.3,Symfony 4.1.1(内核:src,环境:dev,调试:true)

如果自动映射与 Doctrine 一起使用,您将必须检查您的 orm 配置并将其设置为使用 yml

加载这些实体

类似于:

doctrine:
    # ...
    orm:
        # ...
        auto_mapping: true
        mappings:
            # ...
            AppBundle:
                type: yml
                dir: SomeResources/config/doctrine

有关更多信息,您可以查看 Symfony 教程中 Doctrine 配置的自定义映射部分

https://symfony.com/doc/3.4/reference/configuration/doctrine.html