Skip to content

MC-40313: Eliminate plugins for ActionInterface in Framework #31970

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

Merged
merged 2 commits into from
Feb 18, 2021

Conversation

engcom-Golf
Copy link
Contributor

@engcom-Golf engcom-Golf commented Feb 4, 2021

Description (*)

Plugins should be used to customize behavior of one module from another module. In this case, plugins that belong to Framework customize class behavior of the same Framework.
This PR moves logic of framework plugins directly to the place where it's expected to execute

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Eliminate plugins for ActionInterface in Framework #28050

Manual testing scenarios (*)

smoke test

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Feb 4, 2021

Hi @engcom-Golf. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@m2-community-project m2-community-project bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Feb 4, 2021
@engcom-Golf
Copy link
Contributor Author

@magento run all tests

@mrtuvn
Copy link
Contributor

mrtuvn commented Feb 5, 2021

@magento run WebAPI Tests, Integration Tests

@engcom-Golf
Copy link
Contributor Author

@magento run all tests

* - Correct way for handling requests with `ActionInterface::execute`
*
* @param ActionInterface $actionInstance
* @param HttpRequest $request
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you use RequestInterface instead of HttpRequest
Actually variable that you are passing to this method has type RequestInterface

* Dispatch the controller_action_predispatch events.
*
* @param ActionInterface $actionInstance
* @param HttpRequest $request
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you use RequestInterface instead of HttpRequest
Actually variable that you are passing to this method has type RequestInterface

* @param ActionInterface $actionInstance
* @param HttpRequest $request
*/
private function dispatchPreDispatchEvents(ActionInterface $actionInstance, HttpRequest $request)
Copy link
Contributor

Choose a reason for hiding this comment

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

add return type hinting and annotation

* Dispatch the controller_action_postdispatch events.
*
* @param ActionInterface $actionInstance
* @param HttpRequest $request
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you use RequestInterface instead of HttpRequest
Actually variable that you are passing to this method has type RequestInterface

* @param ActionInterface $actionInstance
* @param HttpRequest $request
*/
private function dispatchPostDispatchEvents(ActionInterface $actionInstance, HttpRequest $request)
Copy link
Contributor

Choose a reason for hiding this comment

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

add return type hinting and annotation

*/
private function isSetActionNoPostDispatchFlag(): bool
{
return $this->actionFlag->get('', ActionInterface::FLAG_NO_DISPATCH) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

|| should be on the next line

$request,
$actionInstance
);
$this->requestValidator->validate($request, $actionInstance);
Copy link
Contributor

Choose a reason for hiding this comment

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

$request parameter should be of type RequestInterface sonce it passed from dispatch() method. Please change parameter type, hinting and annotation

Copy link
Contributor

@mrtuvn mrtuvn Feb 9, 2021

Choose a reason for hiding this comment

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

I have question here ! Is this design fault ?

$area->load(Area::PART_DESIGN);

Previously in code try load design and translate part in catch
In my opinion we should load this part before try catch! Also maybe no need designloader load plugin defined in here to reduce work-load consumption called everytime
https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Theme/etc/di.xml#L109
What you guys think?
CC: @kandy @paliarush @engcom-Golf @lbajsarowicz

Copy link
Contributor

Choose a reason for hiding this comment

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

Screenshot from 2021-02-09 11-06-20
Here is snippets demo

Copy link
Contributor

@Vinai Vinai Feb 9, 2021

Choose a reason for hiding this comment

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

@zakdma

$request parameter should be of type RequestInterface sonce it passed from dispatch() method. Please change parameter type, hinting and annotation

Since the method getFullActionName is called on the request, the dependency is actually on the HttpRequest, not the RequestInterface.
Depending on RequestInterface means an interface contract violation.
The options are to either add the method to the RequestInterface (backward incompatible change), or to depend on the HttpRequest (which is simply making the implicit explicit).

@engcom-Golf
Copy link
Contributor Author

@magento run all tests

@mrtuvn
Copy link
Contributor

mrtuvn commented Feb 5, 2021

Should we need update description clarify we make this change

@engcom-Golf engcom-Golf requested a review from zakdma February 5, 2021 12:17
@mrtuvn
Copy link
Contributor

mrtuvn commented Feb 6, 2021

@magento run Functional Tests EE

@zakdma
Copy link
Contributor

zakdma commented Feb 10, 2021

@sidolov @gabrieldagama
could yo please review this PR and express you opinion about discussion in comments?

@gabrieldagama
Copy link
Contributor

gabrieldagama commented Feb 10, 2021

The problem here is the public method from FrontControllerInterface depends on RequestInterface and the private method of FrontController is depending on HttpRequest instead. I agree with @Vinai that just replacing it with RequestInterface would violate the interface because of the usage of getFullActionName function.

The code as it is today is already violating the interface and we should fix it, as discussed with @zakdma, it may be better to re-evaluate the RequestInterface, see if there are any gaps on the interface, and fix this problem. Because the solution will be backward-incompatible we should aim such changes to 2.5 release line instead.

Since would be doing such work, it probably worth looking at other implementations from FrontControllerInterface, it seems that they are also violating the contract, like \Magento\Webapi\Controller\Rest.

@mrtuvn
Copy link
Contributor

mrtuvn commented Feb 10, 2021

I have see some implements with same function name getFullActionName
Magento\Framework\App\RequestInterface and Magento\Framework\App\Request\Http
Both object serve difference purpose may make some confusing! Should we need update clarify via documents when/how/why use for each one?

Example 1 here usage of http request
https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/View/Layout/Builder.php#L81
Proposal: change property $this->request to $this->httpRequest?

Example 2 usage of Magento\Framework\App\RequestInterface
https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/View/Result/Page.php#L276

@mrtuvn mrtuvn mentioned this pull request Feb 13, 2021
4 tasks
@mrtuvn
Copy link
Contributor

mrtuvn commented Feb 13, 2021

@zakdma
Copy link
Contributor

zakdma commented Feb 17, 2021

@magento-engcom-team
Copy link
Contributor

@zakdma, an error occurred during the Pull Request import.

1 similar comment
@magento-engcom-team
Copy link
Contributor

@zakdma, an error occurred during the Pull Request import.

@zakdma
Copy link
Contributor

zakdma commented Feb 17, 2021

@magento-engcom-team
Copy link
Contributor

@zakdma, an error occurred during the Pull Request import.

1 similar comment
@magento-engcom-team
Copy link
Contributor

@zakdma, an error occurred during the Pull Request import.

@zakdma
Copy link
Contributor

zakdma commented Feb 17, 2021

@magento-engcom-team
Copy link
Contributor

@zakdma the branch with code successfully imported intomagento-tsg/magento2ce repository. Branch name: imported-magento-magento2-31970.

@magento-engcom-team magento-engcom-team merged commit 60435c2 into magento:2.4-develop Feb 18, 2021
@m2-assistant
Copy link

m2-assistant bot commented Feb 18, 2021

Hi @engcom-Golf, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: App Component: Store Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: review Release Line: 2.4 Type: Feature/Improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eliminate plugins for ActionInterface in Framework
7 participants