Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4: loading an old library: how?

I have an old library (phpquery) that I'd like to include in my project. I've put it inside vendor, but it doesn't work, as it's not PSR-0 compliant. I don't want it to load for every request, so I didn't put the require inside bootstrap autoload.php.

I don't even know, how I can get the root of the app. Running path() gives me a URL, not what I'm after.

So how can I do that?

like image 532
duality_ Avatar asked Jan 28 '13 22:01

duality_


1 Answers

You can create a libraries directory just like in laravel 3 and include it in your class loader. You can do this via composer or laravel.

//composer.json
"autoload": {
    "classmap": [
        "app/commands",
        "app/libraries",
        "app/database/migrations",
        "app/tests/TestCase.php",
    ]
},

//app/starts/global.php
ClassLoader::register(new ClassLoader(array(
    app_path().'/libraries',
)));

Autoloading via Laravel does not require you to run "composer dumpautoload" every time a class is created or removed.

UPDATE - L4 Beta 4

ClassLoader::addDirectories(array(
    app_path().'/libraries',
));
like image 149
Blessing Avatar answered Nov 19 '22 21:11

Blessing