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

Add a cookbook about dealing with multiple channels in console commands #14654

Merged
merged 1 commit into from Dec 22, 2022

Conversation

jakubtobiasz
Copy link
Member

@jakubtobiasz jakubtobiasz commented Dec 16, 2022

Q A
Branch? 1.13
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Related tickets related to #9987 and #14549
License MIT

If you need a context, read Łukasz's comment in #14549.

Preview:
CleanShot 2022-12-16 at 17 42 13@2x

@jakubtobiasz jakubtobiasz added the Documentation Documentation related issues and PRs - requests, fixes, proposals. label Dec 16, 2022
@jakubtobiasz jakubtobiasz requested a review from a team as a code owner December 16, 2022 16:28
@jakubtobiasz jakubtobiasz force-pushed the docs/channel-context-in-cli branch 2 times, most recently from 4dd96eb to 0003ea0 Compare December 16, 2022 16:38
@coldic3 coldic3 merged commit 991c7ee into Sylius:1.13 Dec 22, 2022
@coldic3
Copy link
Contributor

coldic3 commented Dec 22, 2022

Thank you, Jakub! 🎉

Comment on lines +105 to +107
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +10 to +11
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:

Comment on lines +167 to +168
Your channel name is: Magic Web Channel
/app $ bin/console app:dummy -c FASHION_WEB
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Member Author

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.

Copy link
Contributor

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.

Comment on lines +152 to +153
// it isn't important what happens inside the event subscriber.
// It just gets channel from the channel context service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

@jakubtobiasz jakubtobiasz deleted the docs/channel-context-in-cli branch December 22, 2022 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Documentation related issues and PRs - requests, fixes, proposals.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants