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

[Question] Have traits been considered for the Interceptor classes? #975

Closed
fooman opened this issue Jan 16, 2015 · 14 comments
Closed

[Question] Have traits been considered for the Interceptor classes? #975

fooman opened this issue Jan 16, 2015 · 14 comments
Assignees
Labels
Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Progress: needs update

Comments

@fooman
Copy link
Contributor

fooman commented Jan 16, 2015

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.

@antonkril
Copy link
Contributor

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.

@antonkril antonkril self-assigned this Jan 16, 2015
@antonkril
Copy link
Contributor

Does this answer your question? Can we close the issue?

@fooman
Copy link
Contributor Author

fooman commented Feb 16, 2015

@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
https://github.com/fooman/magento2/compare/interceptor-as-trait#diff-7fea50965bcc6aeb72cc4f333e0f9912R1 is easier to read than this https://github.com/fooman/magento2/compare/interceptor-as-trait#diff-4c790e1d84b8acca1907cade0a2ae3d7L122

The code can also be subjected to code analysis plus the trait can be discovered from the generated code.

@SchumacherFM
Copy link
Member

The trait approach is more developer friendly as you can directly hack in the trait and try things out.

👍 for @fooman

@Flyingmana
Copy link
Member

If I understand it correctly, its about the shared code the generator adds to many classes, which is always the same.
Not knowing much of the code here, but does it change behavior if someone has an own __sleep method defined in a class?

@fooman
Copy link
Contributor Author

fooman commented Feb 16, 2015

@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 __sleep,__wakeup and __clone, so with current behaviour you would not be able to have your own implementations of these.

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.

@Marko-M
Copy link
Contributor

Marko-M commented Feb 16, 2015

👍 for trait approach. Traits are there, they make code more readable/maintainable therefore we should use it.

@antonkril
Copy link
Contributor

@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.

@fooman
Copy link
Contributor Author

fooman commented Feb 16, 2015

@antonkril In reply to this comment:

But we considered this low priority task because 3PDs are not supposed to work with this code anyway.

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?

@antonkril
Copy link
Contributor

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.

@antonkril
Copy link
Contributor

Update: Trait implementation is considered as a possible way of simplifying debugging of intercepted code

@vpelipenko
Copy link
Contributor

Guys, can we consider this question answered?

@Flyingmana
Copy link
Member

from my point of view: yes

@fooman fooman closed this as completed Apr 21, 2015
magento-team pushed a commit that referenced this issue Mar 29, 2017
- 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
magento-team pushed a commit that referenced this issue Dec 11, 2017
…ighted and Combined upon Checkout page load #975

 - Merge Pull Request magento-engcom/magento2ce#975 from RomaKis/magento2:8410
 - Merged commits:
   1. fd5f40a
   2. c12dc31
   3. 04ff661
   4. fccecf3
   5. f728923
   6. a0b5460
   7. 98e7951
magento-team pushed a commit that referenced this issue Dec 11, 2017
magento-team pushed a commit that referenced this issue Dec 11, 2017
[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
fe-lix- pushed a commit to fe-lix-/magento2 that referenced this issue Apr 29, 2018
Adapt logic backItemQty and RevertQuote for new API
magento-team pushed a commit that referenced this issue May 15, 2018
@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Oct 13, 2019
@magento-engcom-team
Copy link
Contributor

Hi @fooman. Thank you for your report.
The issue has been fixed in magento/graphql-ce#997 by @atwixfirster in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.4 release.

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Oct 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Progress: needs update
Projects
None yet
Development

No branches or pull requests

7 participants