Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add an external library to symfony

I'm trying to add an external library to symfony. I've tried this on the app/autoload.php:

$loader->add('LibCokeId',__DIR__ . '/../vendor/libcokeid/libcokeid/lib');

However when I try to use it in a controller:

use libCokeId\LibCokeId

Libcokeid::init()

I get the miss use statement error.

Any help?

like image 610
Sergio González Avatar asked Dec 18 '22 11:12

Sergio González


1 Answers

In the situation where you have a library that doesn't use composer and you can't retrieve it from packagist, you can manipulate the Composer autoload.

Simply add the class in the composer.json files, as example:

"autoload": {
    "psr-0": { "": "src/" },
    "files": [
        "vendor/folder/my_custom_lib/myFiles.php",
        "vendor/libcokeid/libcokeid/lib/libCokeId/LibCokeId.php"
    ]
},

OR you can Autoload the whole folder in composer.json:

"autoload": {
    "psr-0": { "": "src/" },
    "classmap": [
        "vendor/libcokeid/libcokeid/lib"
    ],
},

Remember to make a composer install after setting this.

Hope this help.

like image 181
Matteo Avatar answered Jan 01 '23 16:01

Matteo