What is: Composer

Composer is a command line tool for dependency management in PHP. With its help, you can define the libraries that your project needs and it will install and update them for you.

Here is an example below. Open a command line tool like ConEmu and run the following command to install Carbon, a simple PHP API extension for DateTime.

composer require nesbot/carbon

Composer downloads the library into your project’s vendor folder and generates a vendor/autoload.php file. You can simply include this file and start using the classes that those libraries provide without any extra work:

require __DIR__ . '/vendor/autoload.php';

use Carbon\Carbon;

$tomorrow = Carbon::now()->addDay();
$lastWeek = Carbon::now()->subWeek();
$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;

You can browse PHP libraries at https://packagist.org/.

For more information visit the official documentation.

Recent articles