Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Composer with PHP global include path

I was using Zend's autoloader before meeting with Composer.

I have got a library (let's call it LibEx) which is in PHP's global include path (c:\xampp\php\pear). It must be in a global include folder because a lot of project uses it. So, if I change a function in LibEx every project can access the latest version.

And if I want to push my code to server, I simply copy my LibEx folder to library folder which is autoloadable by Zend. Before Composer I was using this method:

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/library'),
    realpath(APPLICATION_PATH . '/library/Zend'),
    get_include_path(),
)));

include "Zend/Loader/Autoloader.php";
Zend_Loader_Autoloader::getInstance()->registerNamespace('LibEx');

Now I'm in love with Composer. It's really fantastic and I can autoload my project specific library with it too:

"autoload": {
    "psr-0": {"MyLib": "src/"}
}

But how can I autoload LibEx folder which is not in the DocumentRoot or WebRoot? And how to still autoload even if it's in server and copied under src folder?

like image 382
cnkt Avatar asked Oct 25 '25 22:10

cnkt


2 Answers

Did you try this?

"autoload": {
    "psr-0": {"MyLib": "c:\somewhere\project\src"}
}

On Linux soft linking folders would be a possible solution, I don't know if Windows do support it this days or not.

like image 166
Miro Avatar answered Oct 28 '25 14:10

Miro


You can add :

"config": {
    "use-include-path": true
},

to your composer.json, this will take into account paths defined in global php configuration, and you don't have to hardcode the full path.

like image 38
ip512 Avatar answered Oct 28 '25 12:10

ip512



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!