Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Evertt opened this issue May 8, 2017 · 1 comment

Comments

@Evertt
Copy link

Evertt commented May 8, 2017

If my schema.yml says this:

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:

// 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.

@lemorragia
Copy link

I'm looking into a way to implement this with a PR.

I actually have 2 questions:
-should i think about a global setting (all classes will be generated with constructor), a local one(only the ones with a specific parameter set), or both?

-id generation: possibly different policies will be involved : sometimes the id will be auto-generated (in this case, is there a reason about "isNullable" for an auto-generated id is true?), sometimes we want to initialize a Uuid inside the constructor (but not pass it inside the parameters), sometimes we want to pass the Uuid in the parameters, etc...so i'm not sure which policy to implement...ideas? Maybe an additional "constructorParameter" configuration inside the ID configuration...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants