Using Composer in CakePHP
Composer, a magnificent dependency manager. CakePHP, a brilliant MVC framework. What's stopping you from using both in your application? Nothing at all! Personally, I have been using Composer exclusively in my applications to handle all my dependencies and even my CakePHP plugins. It's very easy to do.
The first thing you need to do is create a composer.json file within your application. It's best to place the file in app/composer.json as it would share the same directory structure with Vendor. Here's a quick example:
{
"config": {
"vendor-dir": "Vendor"
},
"require": {
"mjohnson/uploader": "4.*",
"mjohnson/decoda": "6.*"
}
}
Since this is an application and not a dependency, all you need to define is the "require" property. We also set the vendor folder to use CakePHP's naming convention, because why not?
To benefit from Composer's autoloader, include the autoload.php file at the very top of Config/core.php.
require_once dirname(__DIR__) . '/Vendor/autoload.php';
Brilliant! Now we have full dependency and autoloading support. Can't get easier than that.