Slide 1

Slide 1 text

Tom Corrigan rostercloud.com @t_corrigan Melbourne PHP Users Group October 2012 Tuesday, 16 October 12

Slide 2

Slide 2 text

What is Composer? “Composer is a tool for dependency management. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.” [http://getcomposer.org/doc/00-intro.md] Tuesday, 16 October 12

Slide 3

Slide 3 text

What does that mean? Tuesday, 16 October 12

Slide 4

Slide 4 text

What does that mean? • Scope is per project, not global Tuesday, 16 October 12

Slide 5

Slide 5 text

What does that mean? • Scope is per project, not global • Resolves dependencies Tuesday, 16 October 12

Slide 6

Slide 6 text

What does that mean? • Scope is per project, not global • Resolves dependencies • Runs installation tasks Tuesday, 16 October 12

Slide 7

Slide 7 text

Who’s using Composer? Tuesday, 16 October 12

Slide 8

Slide 8 text

Packagist Tuesday, 16 October 12

Slide 9

Slide 9 text

Packagist Tuesday, 16 October 12

Slide 10

Slide 10 text

Packagist • Composer’s default repository Tuesday, 16 October 12

Slide 11

Slide 11 text

Packagist • Composer’s default repository • Put your open source libraries here Tuesday, 16 October 12

Slide 12

Slide 12 text

Packagist • Composer’s default repository • Put your open source libraries here • Great resource for well maintained PHP libraries Tuesday, 16 October 12

Slide 13

Slide 13 text

Statistics [https://packagist.org/statistics] Tuesday, 16 October 12

Slide 14

Slide 14 text

Statistics • Over 4000 packages listed on packagist.org [https://packagist.org/statistics] Tuesday, 16 October 12

Slide 15

Slide 15 text

Statistics • Over 4000 packages listed on packagist.org • More than 4,500,000 package installations over the last 6 months [https://packagist.org/statistics] Tuesday, 16 October 12

Slide 16

Slide 16 text

Installing Composer Tuesday, 16 October 12

Slide 17

Slide 17 text

Installing Composer Locally: Tuesday, 16 October 12

Slide 18

Slide 18 text

Installing Composer Locally: $ cd /project/path $ curl -s https://getcomposer.org/installer | php Tuesday, 16 October 12

Slide 19

Slide 19 text

Installing Composer Locally: $ cd /project/path $ curl -s https://getcomposer.org/installer | php Globally: Tuesday, 16 October 12

Slide 20

Slide 20 text

Installing Composer Locally: $ cd /project/path $ curl -s https://getcomposer.org/installer | php Globally: $ sudo mv composer.phar /usr/local/bin/composer Tuesday, 16 October 12

Slide 21

Slide 21 text

Staying current Tuesday, 16 October 12

Slide 22

Slide 22 text

Staying current Locally: Tuesday, 16 October 12

Slide 23

Slide 23 text

Staying current Locally: $ cd /project/path $ php composer.phar self-update Tuesday, 16 October 12

Slide 24

Slide 24 text

Staying current Locally: $ cd /project/path $ php composer.phar self-update Globally: Tuesday, 16 October 12

Slide 25

Slide 25 text

Staying current Locally: $ cd /project/path $ php composer.phar self-update Globally: $ composer self-update Tuesday, 16 October 12

Slide 26

Slide 26 text

Using Composer Tuesday, 16 October 12

Slide 27

Slide 27 text

Using Composer • Define project dependencies Tuesday, 16 October 12

Slide 28

Slide 28 text

Using Composer • Define project dependencies • Install them Tuesday, 16 October 12

Slide 29

Slide 29 text

Using Composer • Define project dependencies • Install them • Bootstrap the autoloader Tuesday, 16 October 12

Slide 30

Slide 30 text

Define your dependencies Tuesday, 16 October 12

Slide 31

Slide 31 text

Define your dependencies composer.json Tuesday, 16 October 12

Slide 32

Slide 32 text

Define your dependencies composer.json { "require": { "phpmelb/project1": "1.0.2" "phpmelb/project2": "1.0.*" "phpmelb/project3": ">=1.0,<2.0" "phpmelb/project4": "4d3fe5feaf" "phpmelb/project5": "dev-master" } } Tuesday, 16 October 12

Slide 33

Slide 33 text

Install Tuesday, 16 October 12

Slide 34

Slide 34 text

Install $ composer install Tuesday, 16 October 12

Slide 35

Slide 35 text

Install $ composer install vendor/ .composer/ phpmelb/ project1/ project2/ project3/ project4/ autoload.php Tuesday, 16 October 12

Slide 36

Slide 36 text

Using the autoloader

Slide 37

Slide 37 text

Tuesday, 16 October 12

Slide 38

Slide 38 text

{ "name": "symfony/framework-standard-edition", "description": "The \"Symfony Standard Edition\" distribution", Tuesday, 16 October 12

Slide 39

Slide 39 text

{ "name": "symfony/framework-standard-edition", "description": "The \"Symfony Standard Edition\" distribution", "autoload": { "psr-0": { "": "src/" } }, Tuesday, 16 October 12

Slide 40

Slide 40 text

{ "name": "symfony/framework-standard-edition", "description": "The \"Symfony Standard Edition\" distribution", "autoload": { "psr-0": { "": "src/" } }, Tuesday, 16 October 12

Slide 41

Slide 41 text

{ "name": "symfony/framework-standard-edition", "description": "The \"Symfony Standard Edition\" distribution", "autoload": { "psr-0": { "": "src/" } }, "require": { "php": ">=5.3.3", "symfony/symfony": "2.1.*", "doctrine/orm": ">=2.2.3,<2.4-dev", "doctrine/doctrine-bundle": "1.0.*", "twig/extensions": "1.0.*", "symfony/assetic-bundle": "2.1.*", "symfony/swiftmailer-bundle": "2.1.*", "symfony/monolog-bundle": "2.1.*", "sensio/distribution-bundle": "2.1.*", "sensio/framework-extra-bundle": "2.1.*", "sensio/generator-bundle": "2.1.*", "jms/security-extra-bundle": "1.2.*", "jms/di-extra-bundle": "1.1.*" }, Tuesday, 16 October 12

Slide 42

Slide 42 text

{ "name": "symfony/framework-standard-edition", "description": "The \"Symfony Standard Edition\" distribution", "autoload": { "psr-0": { "": "src/" } }, "require": { "php": ">=5.3.3", "symfony/symfony": "2.1.*", "doctrine/orm": ">=2.2.3,<2.4-dev", "doctrine/doctrine-bundle": "1.0.*", "twig/extensions": "1.0.*", "symfony/assetic-bundle": "2.1.*", "symfony/swiftmailer-bundle": "2.1.*", "symfony/monolog-bundle": "2.1.*", "sensio/distribution-bundle": "2.1.*", "sensio/framework-extra-bundle": "2.1.*", "sensio/generator-bundle": "2.1.*", "jms/security-extra-bundle": "1.2.*", "jms/di-extra-bundle": "1.1.*" }, "scripts": { "post-install-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ] }, Tuesday, 16 October 12

Slide 43

Slide 43 text

{ "name": "symfony/framework-standard-edition", "description": "The \"Symfony Standard Edition\" distribution", "autoload": { "psr-0": { "": "src/" } }, "require": { "php": ">=5.3.3", "symfony/symfony": "2.1.*", "doctrine/orm": ">=2.2.3,<2.4-dev", "doctrine/doctrine-bundle": "1.0.*", "twig/extensions": "1.0.*", "symfony/assetic-bundle": "2.1.*", "symfony/swiftmailer-bundle": "2.1.*", "symfony/monolog-bundle": "2.1.*", "sensio/distribution-bundle": "2.1.*", "sensio/framework-extra-bundle": "2.1.*", "sensio/generator-bundle": "2.1.*", "jms/security-extra-bundle": "1.2.*", "jms/di-extra-bundle": "1.1.*" }, "scripts": { "post-install-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ] }, "config": { "bin-dir": "bin" }, Tuesday, 16 October 12

Slide 44

Slide 44 text

{ "name": "symfony/framework-standard-edition", "description": "The \"Symfony Standard Edition\" distribution", "autoload": { "psr-0": { "": "src/" } }, "require": { "php": ">=5.3.3", "symfony/symfony": "2.1.*", "doctrine/orm": ">=2.2.3,<2.4-dev", "doctrine/doctrine-bundle": "1.0.*", "twig/extensions": "1.0.*", "symfony/assetic-bundle": "2.1.*", "symfony/swiftmailer-bundle": "2.1.*", "symfony/monolog-bundle": "2.1.*", "sensio/distribution-bundle": "2.1.*", "sensio/framework-extra-bundle": "2.1.*", "sensio/generator-bundle": "2.1.*", "jms/security-extra-bundle": "1.2.*", "jms/di-extra-bundle": "1.1.*" }, "scripts": { "post-install-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ] }, "config": { "bin-dir": "bin" }, "minimum-stability": "dev", Tuesday, 16 October 12

Slide 45

Slide 45 text

{ "name": "symfony/framework-standard-edition", "description": "The \"Symfony Standard Edition\" distribution", "autoload": { "psr-0": { "": "src/" } }, "require": { "php": ">=5.3.3", "symfony/symfony": "2.1.*", "doctrine/orm": ">=2.2.3,<2.4-dev", "doctrine/doctrine-bundle": "1.0.*", "twig/extensions": "1.0.*", "symfony/assetic-bundle": "2.1.*", "symfony/swiftmailer-bundle": "2.1.*", "symfony/monolog-bundle": "2.1.*", "sensio/distribution-bundle": "2.1.*", "sensio/framework-extra-bundle": "2.1.*", "sensio/generator-bundle": "2.1.*", "jms/security-extra-bundle": "1.2.*", "jms/di-extra-bundle": "1.1.*" }, "scripts": { "post-install-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ] }, "config": { "bin-dir": "bin" }, "minimum-stability": "dev", Tuesday, 16 October 12

Slide 46

Slide 46 text

{ "name": "symfony/framework-standard-edition", "description": "The \"Symfony Standard Edition\" distribution", "autoload": { "psr-0": { "": "src/" } }, "require": { "php": ">=5.3.3", "symfony/symfony": "2.1.*", "doctrine/orm": ">=2.2.3,<2.4-dev", "doctrine/doctrine-bundle": "1.0.*", "twig/extensions": "1.0.*", "symfony/assetic-bundle": "2.1.*", "symfony/swiftmailer-bundle": "2.1.*", "symfony/monolog-bundle": "2.1.*", "sensio/distribution-bundle": "2.1.*", "sensio/framework-extra-bundle": "2.1.*", "sensio/generator-bundle": "2.1.*", "jms/security-extra-bundle": "1.2.*", "jms/di-extra-bundle": "1.1.*" }, "scripts": { "post-install-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile" ] }, "config": { "bin-dir": "bin" }, "minimum-stability": "dev", "extra": { "symfony-app-dir": "app", "symfony-web-dir": "web" } } Tuesday, 16 October 12

Slide 47

Slide 47 text

Composer: Killer Features Tuesday, 16 October 12

Slide 48

Slide 48 text

Composer: Killer Features • composer.lock Tuesday, 16 October 12

Slide 49

Slide 49 text

Composer: Killer Features • composer.lock • Satis - Your private repository Tuesday, 16 October 12

Slide 50

Slide 50 text

Composer: Killer Features • composer.lock • Satis - Your private repository • composer installers Tuesday, 16 October 12

Slide 51

Slide 51 text

Composer: Killer Features • composer.lock • Satis - Your private repository • composer installers • Get started with a new framework project directly from composer Tuesday, 16 October 12

Slide 52

Slide 52 text

composer.lock Tuesday, 16 October 12

Slide 53

Slide 53 text

composer.lock • Used when you call composer install Tuesday, 16 October 12

Slide 54

Slide 54 text

composer.lock • Used when you call composer install • Updated by composer update Tuesday, 16 October 12

Slide 55

Slide 55 text

composer.lock • Used when you call composer install • Updated by composer update • Everybody runs the exact same version of dependencies Tuesday, 16 October 12

Slide 56

Slide 56 text

Satis Tuesday, 16 October 12

Slide 57

Slide 57 text

Satis • Your very own packagist for your proprietary code Tuesday, 16 October 12

Slide 58

Slide 58 text

Satis • Your very own packagist for your proprietary code • Eases deployment Tuesday, 16 October 12

Slide 59

Slide 59 text

Satis • Your very own packagist for your proprietary code • Eases deployment • Composer will connect to it securely Tuesday, 16 October 12

Slide 60

Slide 60 text

Satis • Your very own packagist for your proprietary code • Eases deployment • Composer will connect to it securely • HTTPS -Public key Tuesday, 16 October 12

Slide 61

Slide 61 text

Satis • Your very own packagist for your proprietary code • Eases deployment • Composer will connect to it securely • HTTPS -Public key • SSH Tuesday, 16 October 12

Slide 62

Slide 62 text

Satis • Your very own packagist for your proprietary code • Eases deployment • Composer will connect to it securely • HTTPS -Public key • SSH • See https://github.com/composer/satis Tuesday, 16 October 12

Slide 63

Slide 63 text

Composer Installers •CakePHP •cakephp-plugin •CodeIgniter •codeigniter-library •codeigniter-third-party •codeigniter-module •Drupal •drupal-module •drupal-theme •drupal-profile •drupal-drush •FuelPHP •fuelphp-module •Joomla •joomla-component •joomla-module •joomla-template •joomla-plugin •joomla-library •Kohana •kohana-module •Laravel •laravel-library •Lithium •lithium-library •lithium-source •Magento •magento-library •magento-skin •magento-theme •Mako •mako-package •MediaWiki •mediawiki-extension •phpBB •phpbb-extension •PPI •ppi-module •SilverStripe •silverstripe-module •silverstripe-theme •symfony1 •symfony1-plugin •WordPress •wordpress-plugin •wordpress-theme •Zend •zend-library •zend-extra Tuesday, 16 October 12

Slide 64

Slide 64 text

Composer Installers • Bring the power and ease of Composer to your framework/CMS •CakePHP •cakephp-plugin •CodeIgniter •codeigniter-library •codeigniter-third-party •codeigniter-module •Drupal •drupal-module •drupal-theme •drupal-profile •drupal-drush •FuelPHP •fuelphp-module •Joomla •joomla-component •joomla-module •joomla-template •joomla-plugin •joomla-library •Kohana •kohana-module •Laravel •laravel-library •Lithium •lithium-library •lithium-source •Magento •magento-library •magento-skin •magento-theme •Mako •mako-package •MediaWiki •mediawiki-extension •phpBB •phpbb-extension •PPI •ppi-module •SilverStripe •silverstripe-module •silverstripe-theme •symfony1 •symfony1-plugin •WordPress •wordpress-plugin •wordpress-theme •Zend •zend-library •zend-extra Tuesday, 16 October 12

Slide 65

Slide 65 text

Composer Installers • Bring the power and ease of Composer to your framework/CMS • Magically installs packages/ plugins to the correct location for framework •CakePHP •cakephp-plugin •CodeIgniter •codeigniter-library •codeigniter-third-party •codeigniter-module •Drupal •drupal-module •drupal-theme •drupal-profile •drupal-drush •FuelPHP •fuelphp-module •Joomla •joomla-component •joomla-module •joomla-template •joomla-plugin •joomla-library •Kohana •kohana-module •Laravel •laravel-library •Lithium •lithium-library •lithium-source •Magento •magento-library •magento-skin •magento-theme •Mako •mako-package •MediaWiki •mediawiki-extension •phpBB •phpbb-extension •PPI •ppi-module •SilverStripe •silverstripe-module •silverstripe-theme •symfony1 •symfony1-plugin •WordPress •wordpress-plugin •wordpress-theme •Zend •zend-library •zend-extra Tuesday, 16 October 12

Slide 66

Slide 66 text

Composer Installers • Bring the power and ease of Composer to your framework/CMS • Magically installs packages/ plugins to the correct location for framework • See https://github.com/ composer/installers •CakePHP •cakephp-plugin •CodeIgniter •codeigniter-library •codeigniter-third-party •codeigniter-module •Drupal •drupal-module •drupal-theme •drupal-profile •drupal-drush •FuelPHP •fuelphp-module •Joomla •joomla-component •joomla-module •joomla-template •joomla-plugin •joomla-library •Kohana •kohana-module •Laravel •laravel-library •Lithium •lithium-library •lithium-source •Magento •magento-library •magento-skin •magento-theme •Mako •mako-package •MediaWiki •mediawiki-extension •phpBB •phpbb-extension •PPI •ppi-module •SilverStripe •silverstripe-module •silverstripe-theme •symfony1 •symfony1-plugin •WordPress •wordpress-plugin •wordpress-theme •Zend •zend-library •zend-extra Tuesday, 16 October 12

Slide 67

Slide 67 text

Setup a new project • Symfony2 composer create-project symfony/framework-standard-edition path/to/install • Zend Framework 2 composer create-project --repository-url="http:// packages.zendframework.com" zendframework/skeleton-application path/to/ install Tuesday, 16 October 12

Slide 68

Slide 68 text

? Tuesday, 16 October 12

Slide 69

Slide 69 text

Thankyou Further Reading: http://getcomposer.org http://packagist.org http://symfony.com/video/26/in-depth-with-composer/English Slides available at https://speakerdeck.com/u/tommygnr Tuesday, 16 October 12