Exam AD0-E716 Topic 5 Question 56 Discussion
Actual exam question for Adobe's AD0-E716 exam
Question #: 56
Topic #: 5
Question #: 56
Topic #: 5
The di. xml file of a module attaches two plugins for the class Action.
The PluginA has the methods: beforeDispatch, aroundDispatch, afterDispatch. The PluginB has the methods:
beforeDispatch, afterDispatch.

The around plugin code is:

What would be the plugin execution order?
The PluginA has the methods: beforeDispatch, aroundDispatch, afterDispatch. The PluginB has the methods:
beforeDispatch, afterDispatch.

The around plugin code is:

What would be the plugin execution order?
Suggested Answer: A Vote an answer
* Magento Plugin Types and Execution Order:
* Before Plugins: Execute before the actual method is called. They execute in ascending sortOrder.
* Around Plugins: Wrap around the method call. The around method is executed, passing control to the $next callback that calls the actual method.
* After Plugins: Execute after the method completes. They execute in descending sortOrder.
* Analysis of Plugins Configuration:
* PluginA (sortOrder="10") has beforeDispatch, aroundDispatch, and afterDispatch methods.
* PluginB (sortOrder="20") has beforeDispatch and afterDispatch methods.
* Execution Order Breakdown for Option A:
* Before Plugins:
* PluginA::beforeDispatch() executes first (lower sortOrder).
* PluginB::beforeDispatch() executes second.
* Around Plugin:
* PluginA::aroundDispatch() wraps around the dispatch method. It will only proceed to the actual dispatch call after completing any custom code and calling the $next function.
* Action Dispatch:
* Action::dispatch() is executed as part of PluginA::aroundDispatch() via $next().
* After Plugins:
* PluginB::afterDispatch() executes after the dispatch method, due to its higher sortOrder.
* PluginA::afterDispatch() executes last.
Execution Flow for Option A:
* PluginA::beforeDispatch()
* PluginB::beforeDispatch()
* PluginA::aroundDispatch() wraps the Action::dispatch()
* Action::dispatch() occurs within the aroundDispatch of PluginA
* PluginB::afterDispatch()
* PluginA::afterDispatch()
This matches the order specified in Option A.
References:
* Magento Plugins (Interceptors) Overview - Adobe Commerce Developer Guide detailing the role and order of before, around, and after plugins.
* Managing Plugin Execution Order - Explanation of how sortOrder affects execution order of plugins.
* Magento Dependency Injection Configuration - Detailed information on configuring plugins within di.
xml.
By following the sortOrder and plugin type rules, Option A correctly represents the plugin execution order for the given setup.
* Before Plugins: Execute before the actual method is called. They execute in ascending sortOrder.
* Around Plugins: Wrap around the method call. The around method is executed, passing control to the $next callback that calls the actual method.
* After Plugins: Execute after the method completes. They execute in descending sortOrder.
* Analysis of Plugins Configuration:
* PluginA (sortOrder="10") has beforeDispatch, aroundDispatch, and afterDispatch methods.
* PluginB (sortOrder="20") has beforeDispatch and afterDispatch methods.
* Execution Order Breakdown for Option A:
* Before Plugins:
* PluginA::beforeDispatch() executes first (lower sortOrder).
* PluginB::beforeDispatch() executes second.
* Around Plugin:
* PluginA::aroundDispatch() wraps around the dispatch method. It will only proceed to the actual dispatch call after completing any custom code and calling the $next function.
* Action Dispatch:
* Action::dispatch() is executed as part of PluginA::aroundDispatch() via $next().
* After Plugins:
* PluginB::afterDispatch() executes after the dispatch method, due to its higher sortOrder.
* PluginA::afterDispatch() executes last.
Execution Flow for Option A:
* PluginA::beforeDispatch()
* PluginB::beforeDispatch()
* PluginA::aroundDispatch() wraps the Action::dispatch()
* Action::dispatch() occurs within the aroundDispatch of PluginA
* PluginB::afterDispatch()
* PluginA::afterDispatch()
This matches the order specified in Option A.
References:
* Magento Plugins (Interceptors) Overview - Adobe Commerce Developer Guide detailing the role and order of before, around, and after plugins.
* Managing Plugin Execution Order - Explanation of how sortOrder affects execution order of plugins.
* Magento Dependency Injection Configuration - Detailed information on configuring plugins within di.
xml.
By following the sortOrder and plugin type rules, Option A correctly represents the plugin execution order for the given setup.
by Phoebe at Feb 11, 2025, 05:07 PM
0
0
0
10
Comments
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Report Comment
Commenting
You can sign-up / login (it's free).