I am facing a PHP arrangement problem. Here is some context :
I am using a PHP OpenSource framework (Prestashop).
I modified its behaviour using overrides (Extending a class to redefine one of its function) and by adding new modules that I developped.
I am running PHP 7.1, using Docker and Gitlab CI/CD.
I want to keep on maintaining only one application for multiple clients.
Now, here is my problem :
A client wants to use a Prestashop module (Bought from their marketplace), this module, however needs to override a class (and potentially a function) I already overriden.
What would be the best course of action, should I copy / manual merge the aforementioned code and condition its use based on client context ?
Any suggestion is welcomed,
Thank you.
If your project uses composer to autoload dependencies, you can use following pattern:
1) Create a directory inside your source root. (eg: src/VendorOverride)
Example Directory Structure:
|-- src
|----- VendorOverride
|-------- VendorName
|----------- SomeNamespace
|-------------- ClassThatYouWantToOverride.php
|-- vendor
|----- VendorName
|-------- SomeNamespace
|----------- ClassThatYouWantToOverride.php
2) Configure composer autoload to load class that you want.
"autoload": {
... (your original mapping here)
"psr-4": {
"VendorName\\": "src/VendorOverride/VendorName"
}
}
3) Dump autoload to get changes reflected.
composer dump-autoload
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With