Attempting to override a core Spryker protected method within the Pyz namespace
I am attempting to override a core Spryker method by modifying a file within the Pyz namespace in Spryker. The specific file is located at:
vendor/spryker/glue-application/src/Spryker/Glue/GlueApplication/Rest/Request/RestRequestValidator.php
My goal is to update the validateRequest() method. I have taken the following steps, but the changes are not taking effect:
- Created a class with the same name in the Pyz namespace as a child class of the Spryker namespace.
- Defined a private method with the name validateRequest();
If you have further details about the issue or additional steps you've taken, providing that information could help in offering more specific assistance.
Answers
-
If you have defined method as private and you are trying to extend protected method from parent. You in fact did not extend but created new method.
There is plugin that helps a lot with extending of core spryker classes and methods.
0 -
That was my mistake while writing here, but I am defining the method with same scope. Even I tried my code with all the scopes, private, public and protected. But it's still going to the vendor file.
As this is not any module of Spryker but the core class, is this the reason it is not being executed?
0 -
Use plugin I provided to properly extend class to project level. After that you need to instantiate new extended class from project factory of that module. In your case
src/Pyz/Glue/GlueApplication/GlueApplicationFactory.php
public function createRestRequestValidator(): RestRequestValidatorInterface { return new RestRequestValidator($this->getValidateRestRequestPlugins(), $this->getRestRequestValidatorPlugins()); }
0 -
@filip.gojkovic955 I don't have a PhpStrom, is there any extension for a VSCode?
0 -
Don't override protected methods. It is not good idea.
-1 -
@info460 please provide some explanation.
0 -
I don't know for VSCode but plugin makes things easier. You can extend it without plugin. But be careful you match file path/structure like in core.
0 -
Documentation says that we can, also I didn't find anything on internet why it would be bad idea to extend protected method.
0
Categories
- All Categories
- 42 Getting Started & Guidelines
- 7 Getting Started in the Community
- 8 Additional Resources
- 7 Community Ideas and Feedback
- 69 Spryker News
- 896 Developer Corner
- 758 Spryker Development
- 83 Spryker Dev Environment
- 361 Spryker Releases
- 3 Oryx frontend framework
- 34 Propel ORM
- 68 Community Projects
- 3 Community Ideation Board
- 30 Hackathon
- 3 PHP Bridge
- 6 Gacela Project
- 23 Job Opportunities
- 3.2K 📜 Slack Archives
- 116 Academy
- 5 Business Users
- 370 Docker
- 551 Slack General
- 2K Help
- 75 Knowledge Sharing
- 6 Random Stuff
- 4 Code Testing
- 32 Product & Business Questions
- 68 Spryker Safari Questions
- 50 Random