Laravel 3: calling bundles from the CLI

We’ve been using Laravel for almost a year now in the Kent Uni webdev team on projects such as our course data tool. We’ve found it a great alternative both to older medium-weight PHP frameworks like CodeIgniter and to some of the newer ones like FuelPHP. Even when we’ve had a few issues with it we were able to get our changes merged into the core, thanks to the vibrant community.

One thing we started to use recently was the handy Laravel caching bundle Filch, which extends the built-in Laravel Cache class. It worked just fine until we needed to run a Laravel task from the command line. It just refused to acknowledge that the bundle even existed, even though it normally works just fine.

The solution, it seems, lies in the fact that in CLI Laravel calls a bundle’s start.php after it’s already set its drivers. It just won’t see any of your bundles.

Too late.

So instead just copy the contents of each bundle’s start.php into the application-level start.php

So in our case we had to put something like:

Autoloader::map(array(
 'Filch\\Cache' => Bundle::path('filch').'cache.php',
));
Cache::extend('filch', function(){
 return new Filch\Cache(path('storage').'cache'.DS);
});

into our main start.php

All done!

Of course, if you know a better way of doing this, drop us a line. And bear in mind Laravel 4 is coming out soon. I’m not too sure if all this changes in that. Probably.

 

2 responses to “Laravel 3: calling bundles from the CLI

Leave a Reply

Your email address will not be published.