Description
This issue is automatically created based on existing pull request: #33161: Allow only valid preferences during setup:di:compile
Description
The setup:di:compile
command has exclude lists to avoid loading / compiling dependency injection for 'test' classes. When preferences exist for these excluded classes, any plugins associated with the original classes are (potentially) rendered useless. This is because the child class (preference) can call the original class in a way which does not use Magento's plugin system (ie, parent::methodName()
). And it's impossible to plugin a class that does not go through Magento's compilation process (to have interceptors created, etc). See magento/security-package#296 for a real-world example of this problem in action.
This pull request began as a change to the regular expressions used to exclude classes, and has grown into expanding the exclude list to cover preferences. Changes include:
- Removal of invalid preferences already within the code-base.
- Alerting (exception) for preferences that do not exist.
- Alerting (exception) for preferences that do not exist because of the existing exclude lists.
- Various bug-fixes for
setup:di:compile
-related classes.
Related Pull Requests
- Remove invalid preferences inventory#3315
- https://github.com/magento-commerce/magento2-page-builder/pull/304
Fixed Issues (if relevant)
- Unable to Plugin to \Magento\TwoFactorAuth\Observer\ControllerActionPredispatch security-package#296
Manual testing scenarios
- Create a preference for a class which does not exist. The "for" class can exist or not; the "type" class should not exist.
- Create a preference for a class which is specifically excluded (like a "test" class). The "for" class can exist or not; the "type" class should exist, but not be eligible for dependency compilation - for example if the path includes
Test
.
Before this pull request, these would silently fail; after this pull request, an error is shown.
Questions or comments
None
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)
- README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
- All automated tests passed successfully (all builds are green)