Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
The event model helps to build a loosely coupled system. An example from life. I am currently working on a SAAS platform. The company buys an account and chooses which modules to pay for. There are modules for accounting, checks, for personnel officers, etc. Modules must interact with each other, but any module may not exist.
For example, when creating an employee in the "personnel reserve" module, it must be automatically added to the "accounting" module. I cannot directly pull a method from another module. it is not known in advance whether it will be bought or not.
Instead, I throw an event of type user.created, and in the accounting module, in the handler of this event, I add the user to the necessary lists. It turns out that if there is no module, then the event will simply be thrown to idle, and if there is, then the handler will be launched.
It's actually very convenient. But there is also a negative side: due to weak coupling, it becomes more difficult to navigate through the code. To find out where there are handlers, you have to use the search by event name. But this is a small price to pay for the flexibility that events provide.
This and many other topics on yii2 on the fingers, and in Russian))
https://www.youtube.com/user/ElisDN/videos
For example, there is a "user created" event.
The handlers "send an SMS somewhere", "send an event to some mix-panel", "prepare some emails for the user" are hung on it.
In order not to shit-code everything in one place, everything is divided into logical services.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question