Composer
Install
  • Installation will generate a composer.phar file, save it in ./bin folder
  • curl -sS https://getcomposer.org/installer --output installer
    php installer # download composer.phar
    			
    sudo mv composer.phar /usr/local/bin/composer
    			
    Installing Packages

    1. Add "vendor" to .gitignore to instruct Git to ignore all the vendor folder
    2. Search required libraries at Packagist
    3. Edit composer.json
    4. {
          "require": {
              "monolog/monolog": "1.0.*", 
      	"facebook/php-sdk": "3.2.3"
          }
      }
      			
    5. composer install --no-dev, install those dependencies from lock file
    6. If add new libraries in composer.json, run "php bin/composer.phar update" to install those libraries
    7. require_once 'vendor/autoload.php', add it to your code
    8. Check for known security issues by uploading composer.lock file to sensiolabs
    9. Build with Grunt and Gulp
    General
  • composer.lock, store the library versioin information
  • add your own code to the autoloader

    1. Add your code to /src folder
    2. <?php
      namespace Acme;
      
      class Foo
      {
          public static function world()
          {
              return 'Hello World, Composer!';
          }
      }
      ?>
      
      			
    3. Add autoload field to composer.json
    4. {
          "require": {
              "monolog/monolog": "1.0.*", 
      	"facebook/php-sdk": "3.2.3",
      	"facebook/webdriver": "1.6.0",
      	"facebook/php-sdk-v4": "5.5.0"
          },
      
          "autoload": {
              "psr-4": {"Acme\\": "src/"}
          }
      }
      			
    5. composer install, create new autoload.php
    6. Use your own library
    7. <?php
      require __DIR__ . '/vendor/autoload.php';
      
      use Acme\Foo;
      echo Foo::world();
      ?>
      			
  • Reference
  • PHP Tutorial: Getting Started with Composer
  • Dependency Manager for PHP
  • Creating your first Composer/Packagist package
  • Packagist
  • Symfony
  • Laravel