Composer Tutorial (PHP Hampshire Sept 2013)

14
Composer A Lightning Talk by James Titcumb

description

Watch the presentation video here: http://www.youtube.com/watch?v=nnDUSkvdvWg

Transcript of Composer Tutorial (PHP Hampshire Sept 2013)

Page 1: Composer Tutorial (PHP Hampshire Sept 2013)

ComposerA Lightning Talk by James Titcumb

Page 2: Composer Tutorial (PHP Hampshire Sept 2013)

● Your app depends on libraries● Maintenance - keeping up to date● Libraries depend on other libraries● Could result in conflicting code - MESS

The Problems

Guzzle Twig PSR-3

Pimple

Page 3: Composer Tutorial (PHP Hampshire Sept 2013)

nooooo!!!!!!

Page 4: Composer Tutorial (PHP Hampshire Sept 2013)

Nils Adermann (phpBB)Jordi Boggiano (SF2, Doctrine)

Page 5: Composer Tutorial (PHP Hampshire Sept 2013)

Say hello to...

Page 6: Composer Tutorial (PHP Hampshire Sept 2013)

What Does It Do?

● You tell it what libraries you want● Manages dependencies● Installs them (downloads them)● Creates an autoloader

Page 7: Composer Tutorial (PHP Hampshire Sept 2013)

Installing composer.phar

$ curl -sS https://getcomposer.org/installer | php

#!/usr/bin/env php

All settings correct for using Composer

Downloading...

Composer successfully installed to: composer.phar

Use it: php composer.phar

$

Page 8: Composer Tutorial (PHP Hampshire Sept 2013)

composer.json

{

"require": {

"php": ">= 5.3",

"symfony/console": "2.3.*"

}

}

Page 9: Composer Tutorial (PHP Hampshire Sept 2013)

Now Install$ php composer.phar install

Loading composer repositories with package information

Installing dependencies (including require-dev)

- Installing symfony/console (v2.3.4)

Downloading: 100%

Writing lock file

Generating autoload files

$

Page 10: Composer Tutorial (PHP Hampshire Sept 2013)

Where Did You Come From?

● Packagist - main repository

● You can make your own (Satis)

Page 11: Composer Tutorial (PHP Hampshire Sept 2013)

Autoloading!

index.php

<?php

require 'vendor/autoload.php';

// You can use your dependencies

// without requiring them all the time

use Symfony\Component\Console\Application;

Page 12: Composer Tutorial (PHP Hampshire Sept 2013)

60 seconds Live Demo (!)

● Download Composer● Create composer.json● Run Composer install● Write index.php

Page 13: Composer Tutorial (PHP Hampshire Sept 2013)

● It’s very simple● Magical dependencies (recursively)● You can make your own packages!● Composer autoloader rocks (PSR-0/4)● Simplifies deployment!

● Get it here:

Summary

getcomposer.org

Page 14: Composer Tutorial (PHP Hampshire Sept 2013)

Thanks!

@asgrimgithub.com/asgrim