简体   繁体   中英

composer package : how to require vendor lib autoload

I've opened an issue almost a year ago about a composer package I love : jobby (it allows to manage CRON tasks in PHP) : see issue

My problem with this package is that the composer vendor's lib is hardcoded in a file named BackgroundJob.php ( see file )

if (file_exists('vendor/autoload.php')) {
    require('vendor/autoload.php');
} else {
    require(dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/vendor/autoload.php');
}

But my vendor directory is not "vendor" but "php/lib" and it is not negociable ;)

My ugly solution is to hard code path to autoload file but I then have to manually edit BackgroundJob.php each time I install the lib.

As vendor lib can be any depth, I am really wandering what is THE GOOD solution to this problem : obviously Jobby is not the only package which requires others libraries from composer to be run. Could you point me on a library which handles that so I can have a look at it or give me your thoughts ?

Thanks

I think there is no clean nor THE GOOD solution to install a package you don't own yourself into another directory than vendor because it is a very bad idea. And this is by design of composer! This is one thing that makes composer awesome. There is a nice article about why it is a bad idea to install packages into a directory other than vendor .

If you have really good reasons that are not just "but I want to ..." and you really really need to do that (I would recommend not doing it!) but then you can do some tricks with composer scripts . It should be possible to run a post-package-update or post-package-install script to move the package from vendor to your desired directory.

But keep in mind every developer will hate you for doing this. There are reasons why vendor is the one and only directory for third party packages. This is not a restriction just for fun.

Here a bad solution but do the trick:

fork that project => change codes => make your custom package

later, you can just install your own custom package.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM