Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP override conflict [closed]

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.

like image 727
madubois Avatar asked May 30 '26 00:05

madubois


1 Answers

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
like image 180
Yarimadam Avatar answered Jun 01 '26 16:06

Yarimadam