1

I have a library that I am autoloading in my Laravel project and I want to have a fallback for that library.

The reason is that on some systems, the library will be on a different location (depending on the development/production mode)

For e.g. this below is the package being used:

"autoload": {
    "psr-4": {
        ...
        "MyCompany\\MyPackage\\": "../../libraries/MyCompany/MyPackage/src/",
        ...
    }
},

If there is a production package in another location, I want to use it as first preference, and if not found then fallback to the above.

Can I do something like this:

"autoload": {
    "psr-4": {
        ...
        "MyCompany\\MyPackage\\": "../encrypted/MyCompany/MyPackage/",
        "MyCompany\\MyPackage\\": "../../libraries/MyCompany/MyPackage/src/",
        ...
    }
},

The use case is that on production servers, I will not have to keep the source and will be able to make it work with the encoded files.

Someone might think why don't I edit the composer.json file on server, I can not do that because that file tracked on git.

M.Imran Mamda
  • 394
  • 1
  • 2
  • 13
  • You can change the composer.json file, with an `autoload-dev` – Gert B. Oct 19 '22 at 06:37
  • @GertB. is'nt `autoload-dev` just to avoid loading development packages in production? How should I use it to fallback to another package if one does not exist? – M.Imran Mamda Oct 19 '22 at 06:54

0 Answers0