api-platform / api-platform/schema-generator

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

オープン
#73 コメント 1 件 リアクション 3 件 担当者 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 を短くまとめたダイジェスト。