我问自己是否有可能基于JSON格式生成Doctrine2实体。
类似的东西:
"address": {
"postal_code": "91512"
},
可以变成
/**
* @ORMEntity
* @ORMTable(name="Adress")
*/
class Adress{
/**
* @var string // ideal should be integer
*/
protected $postalCode;
}
问候。
我不知道我是否回答您的问题。您是否尝试首先将JSON转换为YAML(https://www.json2yaml.com/(?当您拥有YML时,可以使用Console Command
php bin/console generate:doctrine:entities yourBundle
文档在这里:https://symfony.com/doc/current/doctrine.html#generating-generating-getters-and-setters
例如,使用此JSON:
{
"AppBundle\Entity\Product": {
"type": "entity",
"table": "product",
"id": {
"id": {
"type": "integer",
"generator": {
"strategy": "AUTO"
}
}
},
"fields": {
"name": {
"type": "string",
"length": 100
},
"price": {
"type": "decimal",
"scale": 2
},
"description": {
"type": "text"
}
}
}
}
您可以推论此YAML:
# src/AppBundle/Resources/config/doctrine/Product.orm.yml
AppBundleEntityProduct:
type: entity
table: product
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 100
price:
type: decimal
scale: 2
description:
type: text
之后,您可以尝试运行此命令:
php bin/console doctrine:generate:entities AppBundle/Entity/Product