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

Integration with symfony #11

Closed
muspelheim opened this issue Oct 10, 2016 · 3 comments
Closed

Integration with symfony #11

muspelheim opened this issue Oct 10, 2016 · 3 comments

Comments

@muspelheim
Copy link

muspelheim commented Oct 10, 2016

Hello, I trying integrate this bundle with symfony, but it's not work for me.

/**
     * @ORM\Embedded(class="DDD\Embeddable\EmailAddress")
     */
    private $email;

This I add to my entity, after run command bin/console doctrine:generate:entities I get this result:

/**
     * Set email
     * @return Test
     */
    public function setEmail(EmailAddress $email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return EmailAddress
     */
    public function getEmail()
    {
        return $this->email;
    }

In this case we can't create simple object as:

$test = new Test();
$test->setEmail('test@ddd.dd');

Because method setEmail must be an instance of EmailAddress, string given and it's useless for development. In this case we can manually create method

public function setEmail($email)
    {
        $this->email = new EmailAddress($email);
        return $this;
    }

but this solution is very difficult to extend, may be you have solution for this case?

$prod->setColor(new Color('#FF00FF'));

this case is difficult for development.

@hkulekci
Copy link
Member

hkulekci commented Oct 11, 2016

In my opinion, you can use a trait for situations such this. After pairing the embeddable to owning entity, you can utilize a trait for setter and getters of value object. Right now, this repository have not any trait implementation, please don't hesitate to give opinion if there is any other solution or way to deal with. @muspelheim

@edigu
Copy link
Contributor

edigu commented Oct 11, 2016

@muspelheim thanks for your interest. Seems like your case is related with object hydration and imho there is nothing to do within this library except allowing empty values in constructors. After your comment I realized this detail and I will try to create another PR to convert all ctors args to optional.

Another detail is, reason behind existence of the bin/console doctrine:generate:entities command is helping developers to easily generate entities from an existing schema. The output of the command should not interpret as a "final" entity. We can (and must) always write additional methods to our entities when required and after that point doctrine:generate:entities lose it's meaning.

As you know there is no method overloading in PHP, but if you don't want to create a custom hydrator for your User, having a setter like below completely valid:

public function setEmail($email)
{
    $this->email = ($email instanceof EmailAddress) ? $email : new EmailAddress($email);
    return $this;
}

Yes, it looks ugly and I also prefer to have type hinting here but don't know is there is a better approach exists or not.

edigu added a commit to edigu/ddd-embeddables that referenced this issue Oct 14, 2016
edigu added a commit that referenced this issue Oct 14, 2016
* Improve Goepoint, add more and proper tests
* Allow empty state for all value objects #11 #12
* Fixing some grammar @yasinaydin 
* update for contributing message (#13) @hkulekci
@edigu
Copy link
Contributor

edigu commented Oct 14, 2016

All embeddables now supports empty state. Closing this. Hydration of domain entities should be handled in other application layers.

@edigu edigu closed this as completed Oct 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants