问题
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?
回答1:
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',
));
来源:https://stackoverflow.com/questions/14572354/laravel-4-loading-an-old-library-how