SlideShare a Scribd company logo
Tom Corrigan      Melbourne PHP Users Group
rostercloud.com         October 2012

 @t_corrigan
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]
What does that mean?
What does that mean?


•   Scope is per project, not global
What does that mean?


•   Scope is per project, not global

•   Resolves dependencies
What does that mean?


•   Scope is per project, not global

•   Resolves dependencies

•   Runs installation tasks
Who’s using Composer?
Packagist
Packagist
Packagist

     • Composer’s default repository
Packagist

     • Composer’s default repository
     • Put your open source libraries
       here
Packagist

     • Composer’s default repository
     • Put your open source libraries
       here

     • Great resource for well
       maintained PHP libraries
Statistics




[https://packagist.org/statistics]
Statistics



•   Over 4000 packages listed on packagist.org




    [https://packagist.org/statistics]
Statistics



•   Over 4000 packages listed on packagist.org

•   More than 4,500,000 package installations over the last 6 months


    [https://packagist.org/statistics]
Installing Composer
Installing Composer
Locally:
Installing Composer
Locally:
       $ cd /project/path
       $ curl -s https://getcomposer.org/installer | php
Installing Composer
Locally:
       $ cd /project/path
       $ curl -s https://getcomposer.org/installer | php

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

Globally:
       $ sudo mv composer.phar /usr/local/bin/composer
Staying current
Staying current
Locally:
Staying current
Locally:
       $ cd /project/path
       $ php composer.phar self-update
Staying current
Locally:
       $ cd /project/path
       $ php composer.phar self-update

Globally:
Staying current
Locally:
       $ cd /project/path
       $ php composer.phar self-update

Globally:
       $ composer self-update
Using Composer
Using Composer


•   Define project dependencies
Using Composer


•   Define project dependencies

•   Install them
Using Composer


•   Define project dependencies

•   Install them

•   Bootstrap the autoloader
Define your dependencies
Define your dependencies
composer.json
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"
    }
}
Install
Install
$ composer install
Install
$ composer install

vendor/
    .composer/
    phpmelb/
        project1/
        project2/
        project3/
        project4/
    autoload.php
Using the autoloader
<?php

require 'vendor/autoload.php';

$foo = new PHPMelbProject1Foo();

$bar = new PHPMelb_Project2_Bar();

...
Composer
{
    "name": "symfony/framework-standard-edition",
    "description": "The "Symfony Standard Edition" distribution",
{
    "name": "symfony/framework-standard-edition",
    "description": "The "Symfony Standard Edition" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
{
    "name": "symfony/framework-standard-edition",
    "description": "The "Symfony Standard Edition" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
{
    "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.*"
    },
{
    "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": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ]
    },
{
    "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": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
{
    "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": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "minimum-stability": "dev",
{
    "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": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "minimum-stability": "dev",
{
    "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": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap",
            "SensioBundleDistributionBundleComposerScriptHandler::clearCache",
            "SensioBundleDistributionBundleComposerScriptHandler::installAssets",
            "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "minimum-stability": "dev",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web"
    }
Composer: Killer Features
Composer: Killer Features

•   composer.lock
Composer: Killer Features

•   composer.lock

•   Satis - Your private repository
Composer: Killer Features

•   composer.lock

•   Satis - Your private repository

•   composer installers
Composer: Killer Features

•   composer.lock

•   Satis - Your private repository

•   composer installers

•   Get started with a new framework project directly from composer
composer.lock
composer.lock


•   Used when you call composer install
composer.lock


•   Used when you call composer install

•   Updated by composer update
composer.lock


•   Used when you call composer install

•   Updated by composer update

•   Everybody runs the exact same version of dependencies
Satis
Satis
•   Your very own packagist for your proprietary code
Satis
•   Your very own packagist for your proprietary code

•   Eases deployment
Satis
•   Your very own packagist for your proprietary code

•   Eases deployment

•   Composer will connect to it securely
Satis
•   Your very own packagist for your proprietary code

•   Eases deployment

•   Composer will connect to it securely

    •   HTTPS -Public key
Satis
•   Your very own packagist for your proprietary code

•   Eases deployment

•   Composer will connect to it securely

    •   HTTPS -Public key

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

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

•   Magically installs packages/      •drupal-drush
                                   •FuelPHP
                                      •fuelphp-module
                                                                    •phpbb-extension
                                                                 •PPI
                                                                    •ppi-module
    plugins to the correct         •Joomla                       •SilverStripe
                                      •joomla-component             •silverstripe-module
    location for framework            •joomla-module                •silverstripe-theme
                                      •joomla-template           •symfony1
                                      •joomla-plugin                •symfony1-plugin

•   See https://github.com/           •joomla-library
                                   •Kohana
                                      •kohana-module
                                                                 •WordPress
                                                                    •wordpress-plugin
                                                                    •wordpress-theme
    composer/installers            •Laravel                      •Zend
                                      •laravel-library              •zend-library
                                   •Lithium                         •zend-extra
                                      •lithium-library
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
?
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

More Related Content

Composer

  • 1. Tom Corrigan Melbourne PHP Users Group rostercloud.com October 2012 @t_corrigan
  • 2. 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]
  • 4. What does that mean? • Scope is per project, not global
  • 5. What does that mean? • Scope is per project, not global • Resolves dependencies
  • 6. What does that mean? • Scope is per project, not global • Resolves dependencies • Runs installation tasks
  • 10. Packagist • Composer’s default repository
  • 11. Packagist • Composer’s default repository • Put your open source libraries here
  • 12. Packagist • Composer’s default repository • Put your open source libraries here • Great resource for well maintained PHP libraries
  • 14. Statistics • Over 4000 packages listed on packagist.org [https://packagist.org/statistics]
  • 15. Statistics • Over 4000 packages listed on packagist.org • More than 4,500,000 package installations over the last 6 months [https://packagist.org/statistics]
  • 18. Installing Composer Locally: $ cd /project/path $ curl -s https://getcomposer.org/installer | php
  • 19. Installing Composer Locally: $ cd /project/path $ curl -s https://getcomposer.org/installer | php Globally:
  • 20. Installing Composer Locally: $ cd /project/path $ curl -s https://getcomposer.org/installer | php Globally: $ sudo mv composer.phar /usr/local/bin/composer
  • 23. Staying current Locally: $ cd /project/path $ php composer.phar self-update
  • 24. Staying current Locally: $ cd /project/path $ php composer.phar self-update Globally:
  • 25. Staying current Locally: $ cd /project/path $ php composer.phar self-update Globally: $ composer self-update
  • 27. Using Composer • Define project dependencies
  • 28. Using Composer • Define project dependencies • Install them
  • 29. Using Composer • Define project dependencies • Install them • Bootstrap the autoloader
  • 32. 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" } }
  • 35. Install $ composer install vendor/ .composer/ phpmelb/ project1/ project2/ project3/ project4/ autoload.php
  • 36. Using the autoloader <?php require 'vendor/autoload.php'; $foo = new PHPMelbProject1Foo(); $bar = new PHPMelb_Project2_Bar(); ...
  • 38. { "name": "symfony/framework-standard-edition", "description": "The "Symfony Standard Edition" distribution",
  • 39. { "name": "symfony/framework-standard-edition", "description": "The "Symfony Standard Edition" distribution", "autoload": { "psr-0": { "": "src/" } },
  • 40. { "name": "symfony/framework-standard-edition", "description": "The "Symfony Standard Edition" distribution", "autoload": { "psr-0": { "": "src/" } },
  • 41. { "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.*" },
  • 42. { "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": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ] },
  • 43. { "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": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ] }, "config": { "bin-dir": "bin" },
  • 44. { "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": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ] }, "config": { "bin-dir": "bin" }, "minimum-stability": "dev",
  • 45. { "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": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ] }, "config": { "bin-dir": "bin" }, "minimum-stability": "dev",
  • 46. { "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": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ], "post-update-cmd": [ "SensioBundleDistributionBundleComposerScriptHandler::buildBootstrap", "SensioBundleDistributionBundleComposerScriptHandler::clearCache", "SensioBundleDistributionBundleComposerScriptHandler::installAssets", "SensioBundleDistributionBundleComposerScriptHandler::installRequirementsFile" ] }, "config": { "bin-dir": "bin" }, "minimum-stability": "dev", "extra": { "symfony-app-dir": "app", "symfony-web-dir": "web" }
  • 49. Composer: Killer Features • composer.lock • Satis - Your private repository
  • 50. Composer: Killer Features • composer.lock • Satis - Your private repository • composer installers
  • 51. Composer: Killer Features • composer.lock • Satis - Your private repository • composer installers • Get started with a new framework project directly from composer
  • 53. composer.lock • Used when you call composer install
  • 54. composer.lock • Used when you call composer install • Updated by composer update
  • 55. composer.lock • Used when you call composer install • Updated by composer update • Everybody runs the exact same version of dependencies
  • 56. Satis
  • 57. Satis • Your very own packagist for your proprietary code
  • 58. Satis • Your very own packagist for your proprietary code • Eases deployment
  • 59. Satis • Your very own packagist for your proprietary code • Eases deployment • Composer will connect to it securely
  • 60. Satis • Your very own packagist for your proprietary code • Eases deployment • Composer will connect to it securely • HTTPS -Public key
  • 61. Satis • Your very own packagist for your proprietary code • Eases deployment • Composer will connect to it securely • HTTPS -Public key • SSH
  • 62. 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
  • 63. Composer Installers •CakePHP •lithium-source •cakephp-plugin •Magento •CodeIgniter •magento-library •codeigniter-library •magento-skin •codeigniter-third-party •magento-theme •codeigniter-module •Mako •Drupal •mako-package •drupal-module •MediaWiki •drupal-theme •mediawiki-extension •drupal-profile •phpBB •drupal-drush •phpbb-extension •FuelPHP •PPI •fuelphp-module •ppi-module •Joomla •SilverStripe •joomla-component •silverstripe-module •joomla-module •silverstripe-theme •joomla-template •symfony1 •joomla-plugin •symfony1-plugin •joomla-library •WordPress •Kohana •wordpress-plugin •kohana-module •wordpress-theme •Laravel •Zend •laravel-library •zend-library •Lithium •zend-extra •lithium-library
  • 64. Composer Installers •CakePHP •lithium-source •cakephp-plugin •Magento • Bring the power and ease •CodeIgniter •codeigniter-library •codeigniter-third-party •magento-library •magento-skin •magento-theme of Composer to your •codeigniter-module •Mako •Drupal •mako-package framework/CMS •drupal-module •MediaWiki •drupal-theme •mediawiki-extension •drupal-profile •phpBB •drupal-drush •phpbb-extension •FuelPHP •PPI •fuelphp-module •ppi-module •Joomla •SilverStripe •joomla-component •silverstripe-module •joomla-module •silverstripe-theme •joomla-template •symfony1 •joomla-plugin •symfony1-plugin •joomla-library •WordPress •Kohana •wordpress-plugin •kohana-module •wordpress-theme •Laravel •Zend •laravel-library •zend-library •Lithium •zend-extra •lithium-library
  • 65. Composer Installers •CakePHP •lithium-source •cakephp-plugin •Magento • Bring the power and ease •CodeIgniter •codeigniter-library •codeigniter-third-party •magento-library •magento-skin •magento-theme of Composer to your •codeigniter-module •Mako •Drupal •mako-package framework/CMS •drupal-module •MediaWiki •drupal-theme •mediawiki-extension •drupal-profile •phpBB • Magically installs packages/ •drupal-drush •FuelPHP •fuelphp-module •phpbb-extension •PPI •ppi-module plugins to the correct •Joomla •SilverStripe •joomla-component •silverstripe-module location for framework •joomla-module •silverstripe-theme •joomla-template •symfony1 •joomla-plugin •symfony1-plugin •joomla-library •WordPress •Kohana •wordpress-plugin •kohana-module •wordpress-theme •Laravel •Zend •laravel-library •zend-library •Lithium •zend-extra •lithium-library
  • 66. Composer Installers •CakePHP •lithium-source •cakephp-plugin •Magento • Bring the power and ease •CodeIgniter •codeigniter-library •codeigniter-third-party •magento-library •magento-skin •magento-theme of Composer to your •codeigniter-module •Mako •Drupal •mako-package framework/CMS •drupal-module •MediaWiki •drupal-theme •mediawiki-extension •drupal-profile •phpBB • Magically installs packages/ •drupal-drush •FuelPHP •fuelphp-module •phpbb-extension •PPI •ppi-module plugins to the correct •Joomla •SilverStripe •joomla-component •silverstripe-module location for framework •joomla-module •silverstripe-theme •joomla-template •symfony1 •joomla-plugin •symfony1-plugin • See https://github.com/ •joomla-library •Kohana •kohana-module •WordPress •wordpress-plugin •wordpress-theme composer/installers •Laravel •Zend •laravel-library •zend-library •Lithium •zend-extra •lithium-library
  • 67. 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
  • 68. ?

Editor's Notes

  1. Abstract: Composer is a tool for managing dependencies in PHP projects. This talk will introduce Composer and its associated package repository Packagist. The key features and benefits of using Composer will be explored and through practical demonstrations you will gain a working knowledge of using Composer for dependency management.\n
  2. \n
  3. Similar to Bundler for Ruby or npm for node. Per project\n
  4. Similar to Bundler for Ruby or npm for node. Per project\n
  5. Similar to Bundler for Ruby or npm for node. Per project\n
  6. plus many more\n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. Global is better, don&amp;#x2019;t have to run self-update in each project\n
  18. Global is better, don&amp;#x2019;t have to run self-update in each project\n
  19. Global is better, don&amp;#x2019;t have to run self-update in each project\n
  20. Global is better, don&amp;#x2019;t have to run self-update in each project\n
  21. Define, install, autoload(optional)\nexamine each step in detail\n
  22. Define, install, autoload(optional)\nexamine each step in detail\n
  23. Define, install, autoload(optional)\nexamine each step in detail\n
  24. 2 parts - package name &amp; package version\npackage name has two parts, vendor name &amp; project nameFirst example, Tag name in git\n
  25. 2 parts - package name &amp; package version\npackage name has two parts, vendor name &amp; project nameFirst example, Tag name in git\n
  26. \n
  27. \n
  28. DIR structure, composer.lock, \nAutoloader is designed for PSR-0 only, there are workarounds for other approaches. PHP-FIG\n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. Dev, prod, test, staging, Jim, Bob\n
  82. Dev, prod, test, staging, Jim, Bob\n
  83. Dev, prod, test, staging, Jim, Bob\n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. Official extension\n
  91. Official extension\n
  92. Official extension\n
  93. Official extension\n
  94. \n
  95. \n
  96. \n