api-platform / api-platform/schema-generator

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

Ouverte
#73 1 commentaire 3 réactions 0 personnes assignées Voir sur GitHub
enhancement
Langage dominant
PHP
Étoiles
474
Forks
107
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.