Mahmoudz/Porto

Relationships between sections

fresh-cut opened this issue · 6 comments

How to organize communication between sections, if we have an order section and a delivery section. They both require a relationship with the User model, which can be found, for example, in the user section.
According to the rules, such a relationship is impossible: A Section MUST be isolated and SHOULD NOT depends on any other Section.

One way to communicate between Sections is by using events.

@Mohammad-Alavi But if we using events, so how to get data from fired event ? We can call to do something but not getting data from it

You can create Dependencies folder in each container. Only this folder you should use objects from other containers.
There are 3 classes:

  1. InternalApi - this class expose some actions for other containers.
  2. InternalClient - this class can call InternalApi classes of other containers.
  3. InternalEventSubscriber - this class processes events from other containers and synchronize models data or run some actions.

Example of models synchronization:

  1. There are 2 containers: UserContainer and BlogContainer.
  2. UserContainer has User model.
  3. BlogContainer has Article model and Author model (Author is User model in specific context).
  4. UserRegisteredEvent is sent when user is regitstered.
  5. InternalEventSubscriber from BlogContainer receive event and create Author from data of UserModel.

If you need new fields in Author, for example, you need age of User.

  1. Add age field to Author.
  2. Create class for synchronization data of existed Users of UserContainer to Author of BlogContainer.

For id of entity use Uuid without auto generation.

@aleksey-anisimov Thanks for reply! Can you, please, provide small example how to make it? I do not understand how to sync models, should i make a copy of model or write command that will make copy of model or you mean something else ?

@imhitt https://github.com/aleksey-anisimov/symfony-porto

it is not finished example, but you can undestand main idea ^)