-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Question] Have traits been considered for the Interceptor classes? #975
Comments
Generated code doesn't lead to maintainance problems because its logic is in single place. Traits would not bring any value but would just add one more file to interceptor code. |
Does this answer your question? Can we close the issue? |
@antonkril I think you might have misunderstood my question. My comment in regards to maintainability, readability and so forth is about the generating code not the generated code. I haven't yet been able to run the performance tests however this is what I am referring to: For example this code here The code can also be subjected to code analysis plus the trait can be discovered from the generated code. |
The trait approach is more developer friendly as you can directly hack in the trait and try things out. 👍 for @fooman |
If I understand it correctly, its about the shared code the generator adds to many classes, which is always the same. |
@Flyingmana the Interceptor classes, living under var/generated, are autogenerated here https://github.com/fooman/magento2/blob/master/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php#L205 The generating code copies over the public methods from your plugin code but excludes General trait behaviour would be The precedence order is that methods from the current class override Trait methods, which in turn override methods from the base class. |
👍 for trait approach. Traits are there, they make code more readable/maintainable therefore we should use it. |
@fooman we considered template approach for code generation. With templates Interceptor code would be in separate file and generator would be simpler. But we considered this low priority task because 3PDs are not supposed to work with this code anyway. Traits are for code reuse, code can be reused by aggregation but we kept that code in interceptor class to make it easier to debug interceptor code (3PD will rarely/never encounter generator code, but will encounter Interceptor code quite often during debugging). @Flyingmana Intercetpor calls parent::__sleep() so it will be executed. |
@antonkril In reply to this comment:
3PD = third party developers? While it might not be envisaged that this code will be changed by third parties Interceptors are one of the major new features of Magento 2 and developers would/should be working all the time with this code. As this is a low priority on your end: If I finish the pull request and provided there is no major impact on performance what is the chance of this being accepted? |
3PDs (yes, third party developers) will be working with Interceptors frequently (so we try to keep them simple) but not with their generation. Refactoring of generation is not high priority but Interceptors should stay simple. So in my opinion any pull request that spreads Interceptor code should only be considered if it has performance improvement. But this question is not important (two options are not that different and I don't think there will be any performance difference) and trait version seems to have some support in community so we can consider it. |
Update: Trait implementation is considered as a possible way of simplifying debugging of intercepted code |
Guys, can we consider this question answered? |
from my point of view: yes |
- MAGETWO-66039 Remove usages of unserialize in modules /Magento/Framework/*/. CE - missed usages - MAGETWO-66036 Remove usages of unserialize in module /Magento/Paypal/. CE - missed usages
…ighted and Combined upon Checkout page load #975
[EngCom] Public Pull Requests - 2.2-develop - MAGETWO-85332: Fix error loading theme configuration on PHP 7.2 #12606 - MAGETWO-85307: 12468: Sort by Price not working on CatalogSearch Page in Magento 2 #929 - MAGETWO-85303: #12582: Can't remove item description from wishlist #981 - MAGETWO-85297: 8410: Custom Checkout Step and Shipping Step are Highlighted and Combined upon Checkout page load #975 - MAGETWO-85290: 7467: File Put Contents file with empty content. #962
Adapt logic backItemQty and RevertQuote for new API
…ighted and Combined upon Checkout page load #975
Hi @fooman. Thank you for your report. The fix will be available with the upcoming 2.3.4 release. |
The auto generated Interceptor classes currently duplicate the code when they get generated. Since Magento is now 5.4+ have traits been considered to bring the common functionality into the generated classes?
It would also make this code
https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Interception/Code/Generator/Interceptor.php#L170
easier to discover, read and maintain.
The text was updated successfully, but these errors were encountered: