Symfony Doctrine 实体概述

断货

是否可以获得项目中所有映射实体的报告?

我想要一个控制台命令或一个外部包,它可以向我显示所有映射实体的详细列表,以及有关字段、类型、约束等的每个细节。

像这样的东西:

产品

|-------|-------------|--------|----------|-------------|
| Field | Type        | Column | Nullable | Constraints |
|-------|-------------|--------|----------|-------------|
| name  | string(255) | name   | no       | NotBlank    |
|-------|-------------|--------|----------|-------------|
| price | float       | price  | yes      | GreaterThan |
|-------|-------------|--------|----------|-------------|

快速了解具有许多实体的项目可能非常有用。

谢谢!

曼佐洛

它可以帮助吗?

<?php

    namespace App\Command;

    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    use Doctrine\Common\Persistence\ObjectManager;
    use Symfony\Component\Console\Helper\Table;

    class EntitylistCommand extends Command
    {

        protected static $defaultName = 'EntitylistCommand';

        protected function configure()
        {
            $this
                    ->setDescription('EntitylistCommand')
                    ->setHelp('EntitylistCommand');
        }
        public function __construct(ObjectManager $em)
        {
            $this->em = $em;

            // you *must* call the parent constructor
            parent::__construct();
        }
        protected function execute(InputInterface $input, OutputInterface $output)
        {

            /* @var $em \Doctrine\ORM\EntityManager */
            $em = $this->em;
            $tables = $em->getMetadataFactory()->getAllMetadata();
            foreach ($tables as $table) {

                $tablename = $table->getName();
                echo $tablename . PHP_EOL;

                $metadata = $em->getClassMetadata($tablename);
                $fields = $metadata->getFieldNames();
                $rows = array();
                foreach ($fields as $field) {

                    $fieldinfo = $metadata->fieldMappings[$metadata->getFieldName($field)];
                    $fieldname = $fieldinfo["fieldName"];
                    $fieldcolumnname = $fieldinfo["columnName"];
                    $fieldnullable = (isset($fieldinfo["nullable"]) ? ($fieldinfo["nullable"] ? "yes" : "no") : "no");
                    $fieldlength = (isset($fieldinfo["length"]) ? " (" . $fieldinfo["length"] . ")" : "");
                    $fieldtype = (isset($fieldinfo["type"]) ? $fieldinfo["type"] : "");

                    $rows[] = array($fieldname, $fieldtype . $fieldlength, $fieldcolumnname, $fieldnullable);
                }

                $table = new Table($output);
                $table
                        ->setHeaders(['Field', 'Type', 'Column', 'Nullable', 'Constraints'])
                        ->setRows($rows)
                ;
                $table->render();
            }
        }
    }
FOS\UserBundle\Model\User
+---------------------+--------------+-----------------------+----------+-------------+
| Field               | Type         | Column                | Nullable | Constraints |
+---------------------+--------------+-----------------------+----------+-------------+
| username            | string (180) | username              | no       |             |
| usernameCanonical   | string (180) | username_canonical    | no       |             |
| email               | string (180) | email                 | no       |             |
| emailCanonical      | string (180) | email_canonical       | no       |             |
| enabled             | boolean      | enabled               | no       |             |
| salt                | string       | salt                  | yes      |             |
| password            | string       | password              | no       |             |
| lastLogin           | datetime     | last_login            | yes      |             |
| confirmationToken   | string (180) | confirmation_token    | yes      |             |
| passwordRequestedAt | datetime     | password_requested_at | yes      |             |
| roles               | array        | roles                 | no       |             |
+---------------------+--------------+-----------------------+----------+-------------+

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Symfony / Doctrine2和关联实体

Symfony找不到最近保留的实体-Doctrine / Symfony

Doctrine Symfony2 与现有实体保持关联实体

symfony2 doctrine2不刷新新实体

Symfony - Doctrine:设计用于接收多对多实体的 REST api

在Symfony2 + Doctrine上以XML映射实体

Symfony2和Doctrine实体未定义方法

symfony2 doctrine2与实体的批处理错误

如何在Symfony / Doctrine中持久保存克隆的实体对象

从 Doctrine 实体 (Symfony3) 中获取所有值

Symfony-与父实体的Doctrine单表继承ManyToOne关联

Symfony,Doctrine:如何禁用实体侦听器?

doctrine2 symfony2关系实体

Symfony / Doctrine:从数据库外部获取实体字段

Symfony2,Doctrine2,实体映射

Doctrine2 + Symfony2:如何在Symfony2中使用命名空间的Doctrine实体?

Symfony / Doctrine:在symfony提交表单之前,将关系ID解析为实体

Symfony2 Doctrine2多对多将所有实体及其关系实体

Symfony Doctrine Listener - 在 preRemove 事件中删除实体之前更新实体

Doctrine/Symfony - 继承 - 关系

Symfony - Redis 和 Doctrine

Symfony 2.8 Doctrine Fixtures

Symfony、Doctrine 和 createNativeQuery

使用嵌入的表单集合保存相关的Doctrine实体时出现Symfony SQL错误

Symfony / Doctrine:实体“模式”注释不依赖于环境吗?

Symfony 5 / Doctrine:按创建日期时间对实体集合进行排序

如何不使用Doctrine刷新Symfony2中的持久实体?

如何更新 Doctrine (Symfony 4) 中未自动生成 $id 的实体?

在具有Gedmo扩展的层次结构中获取Symfony / Doctrine实体的级别