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
Add a cookbook about dealing with multiple channels in console commands #14654
Conversation
4dd96eb
to
0003ea0
Compare
0003ea0
to
eccb7dd
Compare
Thank you, Jakub! 🎉 |
Now, we can use our custom channel context in our console command. For proof of our concept we will create a DummyCommand, | ||
which will take a channel code as an option and will dispatch a dummy event. This event is handled by an event subscriber using | ||
the channel context to get the channel and print its name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, we can use our custom channel context in our console command. For proof of our concept we will create a DummyCommand, | |
which will take a channel code as an option and will dispatch a dummy event. This event is handled by an event subscriber using | |
the channel context to get the channel and print its name. | |
For our example, we will create a DummyCommand which will take a channel code as an option | |
and dispatch a dummy event. This event is handled by a subscriber using | |
the channel context to print the channel's name. |
To accomplish this task, we have to create a custom channel context available only from the CLI context. But this concrete channel context cannot only return a channel, | ||
but also has to allow to pass a channel code as an argument (which we will get from the console command). This way, we can use the channel context in our services. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To accomplish this task, we have to create a custom channel context available only from the CLI context. But this concrete channel context cannot only return a channel, | |
but also has to allow to pass a channel code as an argument (which we will get from the console command). This way, we can use the channel context in our services. | |
We have to create a custom channel context available only from the CLI context. This channel context should allow setting a channel code (which we will do inside the console command). This way, we can use the channel context in our services. |
1. Custom Channel Context | ||
------------------------- | ||
|
||
First, we need to create a custom channel context. Let's remind our requirements: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, we need to create a custom channel context. Let's remind our requirements: | |
First, we need to create a channel context. Let's remind the requirements: |
Your channel name is: Magic Web Channel | ||
/app $ bin/console app:dummy -c FASHION_WEB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your channel name is: Magic Web Channel | |
/app $ bin/console app:dummy -c FASHION_WEB | |
Your channel name is: Magic Web Channel | |
/app $ bin/console app:dummy -c FASHION_WEB |
A bit more clarity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is an exact output from console :D.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave it as suggested, but you could also split it into 2 blocks, either way, it's easier to read.
// it isn't important what happens inside the event subscriber. | ||
// It just gets channel from the channel context service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// it isn't important what happens inside the event subscriber. | |
// It just gets channel from the channel context service | |
// The subscriber just gets a channel from the channel context |
If you need a context, read Łukasz's comment in #14549.
Preview: