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 摘要。