Friday, May 31, 2013

Using Composer with Laravel 3

Problem:
I found a well-written PayPal REST API that used Composer. My existing project was in Laravel 3. I wanted to make everything work without hacking all my files to bits. But how?

Solution:
By modifying 2 files and adding a new "vendor" directory, I was able to use the composer library as part of my Laravel 3 application.

First, add a "vendor" directory to the root project directory. Second, modify /public/index.php with the following lines BEFORE the launch Laravel directive.

// --------------------------------------------------------------
// Autoload composer vendors.
// --------------------------------------------------------------
require path('composer').'autoload.php';


Now we need to add the path reference being used here into paths.php. I put this after public and before the awesome dragon ASCII art.

// --------------------------------------------------------------
// The path to the composer vendors directory.
// --------------------------------------------------------------
$paths['composer'] = 'vendor';

Now you can place your composer.json in your root directory and run composer update on it. That should do it!



Note: Thanks to http://stackoverflow.com/questions/15205949/class-not-found-with-laravel-3-and-composer for laying some ground work, although that solution still had a bug for me.

No comments: