Love Fuel?    Donate

Thoughts, ideas, random notes, ramblings...

Anything about PHP in general, and FuelPHP in particular. Sometimes serious, sometimes with a big wink. But always with a message. Do you have an opinion about an article? Don't forget to comment!

There is a lot of discussion going on about PSR-1, Composer, Packagist packages, and whether or not FuelPHP supports or will support this. With this blog post I will try to make it clear where FuelPHP stands in terms of Composer, how you can use it now, and how it's going to be used in the future.

Can I use composer packages today?

The simple answer is "Yes, absolutely!".

The fact that FuelPHP in version 1.x doesn't use Composer itself doesn't mean you can't use Composer to include Composer packages into your application. So, how would you go about including a Composer package in your application? Simple, just follow these steps:

  1. Install composer into APPATH (not the project root!), according the the instructions.
  2. Create a composer.json file which will install the package(s) of your choice, as documented here.
  3. Run the composer installer to install the dependencies defined in your composer.json file

After you've done this, Composer will have installed the dependencies into the application "vendor" folder, that exists in every default FuelPHP installation.

The next step is to inform the framework that you have installed these dependencies. This needs to be done because the framework doesn't use the Composer autoloader, it uses it's own internal PSR-1 compliant autoloader. To do so, in your app bootstrap.php, just after the line that says:

	Autoloader::register();

add

        // load the Composer autoloader
        require APPPATH.'vendor/autoload.php';

This will load the Composer autoloader, which will be used whenever you call a class that can't be found by FuelPHPs internal autoloader. From now, you can use the classes in the installed packages in your application, just like any class.

What about the future?

FuelPHP version 2 will be build entirely out of Composer components, including the application itself, which will no longer be part of the framework repository. You can have a look at the current framework repository here. For now, during development of version 2, we will use the Packagist repository for all our composer packages.

We have not made a descision on what we're going to do towards the release of 2.0, especially when it comes to FuelPHP specific packages. Using Packagist for those might be the easiest and most convinient route to take, on the other hand a FuelPHP specific package repository might be more accessable for the users of the framework. Let us know your thoughts on this!