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

Separate the domain model and persistence layer #7

Open
mohammadhsn opened this issue Jun 17, 2021 · 0 comments
Open

Separate the domain model and persistence layer #7

mohammadhsn opened this issue Jun 17, 2021 · 0 comments

Comments

@mohammadhsn
Copy link

Hi,

I have a design-related question, As I know about DDD and some sources I read, most people indicate separations between domain and persistence (or infrastructure in general). Most people use Doctrine ORM when they consider the DDD approach in PHP, domain models (or Entities) are a part of domain, so they have no idea about persistence.

Let's imagine we have an Author domain model that publishes posts, I thought below code:

class Post
{
    public function __construct(
        protected Author $author,
        protected PostTitle $title,
        protected PostContent $content,
        protected DateTimeImmutable $publishedAt
    ) {}
}

class Author
{
    public function __construct(
        protected AuthorEmail $email,
        protected array $posts = []
    ) {}

    public function publishNewPost(Post $post)
    {
        $this->posts []= $posts;
    }
}

I fact, what I want is I could use the Post and Author classes as domain models without any persistence concern (doctrine annotations/ArrayCollection class/...). I'd like to separate Doctrine's entity from domain models and I don't know what should I do. Could you help me, please?

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

1 participant