api-platform / api-platform/schema-generator

[enhancement] generate entity constructors with all non-nullable properties

未关闭
#73 1 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
PHP
星标
474
派生
107
PR 合并指标
30 天内没有已合并 PR

描述

If my `schema.yml` says this:

```yaml
Product:
parent: false
properties:
name: { nullable: false }
```

Then I would love it if my generated `Product.php` then contains a constructor function which requires the `$name` property. Like this:

```php
// src/AppBundle/Entity/Product.php

class Product
{
// ...

public function __construct(string $name)
{
$this->setName($name);
// using the setter that already exists
// so we can utilize any validation that that method might have
}

// ...
}
```

That way you can guarantee when I or another developer wants to initialize a new `Product`, that it will be a valid entity right after initialization.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。