Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Composer Revolution

The Composer Revolution

Given at DallasPHP May 2013

Daniel Cousineau

May 14, 2013
Tweet

More Decks by Daniel Cousineau

Other Decks in Technology

Transcript

  1. Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com <?php

    require_once '../vendor/autoload.php'; $app = new Silex\Application(); $app->run();
  2. Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com <?php

    namespace App; class SampleClass { public function foo() { return 'bar'; } }
  3. Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com {

    "require": { "silex/silex": "~1.0" }, "autoload": { "psr-0": { "App": "src/" } } }
  4. Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com <?php

    require_once '../vendor/autoload.php'; $sample = new App\SampleClass(); $sample->foo();
  5. +Version Specification Daniel Cousineau // follow me : @dcousineau or

    http://dcousineau.com { "require": { "vendor/pkg1": "1.2.3", "vendor/pkg2": "1.2.*", "vendor/pkg3": "1.2.*@dev", "vendor/pkg4": ">=1.2,<2.0", "vendor/pkg5": "~1.2", "vendor/pkg6": "dev-master" }, }
  6. +Next Significant Version Operator Daniel Cousineau // follow me :

    @dcousineau or http://dcousineau.com ~1.2 >=1.2,<2.0 ~1.2.3 >=1.2.3,<1.3
  7. +Branch Aliases Daniel Cousineau // follow me : @dcousineau or

    http://dcousineau.com dev-master git checkout master dev-feature-test git checkout feature-test
  8. +Branch Aliases Daniel Cousineau // follow me : @dcousineau or

    http://dcousineau.com dev-master#2eb0c0 git checkout 2eb0c0
  9. +Minimum Stability Daniel Cousineau // follow me : @dcousineau or

    http://dcousineau.com { "require": { "silex/silex": "~1.0", }, "minimum-stability": "dev" }
  10. +Custom/Private Packages Daniel Cousineau // follow me : @dcousineau or

    http://dcousineau.com { "repositories": [ { "type": "vcs", "url": "https://github.com/myghaccount/custom-package-repo.git" } ], "require": { "custom/package": "dev-master", }, }
  11. +Overriding Packages/Using Forks Daniel Cousineau // follow me : @dcousineau

    or http://dcousineau.com { "repositories": [ { "type": "vcs", "url": "https://github.com/myghaccount/silex.git" } ], "require": { "silex/silex": "dev-fix-bug as 1.0.x-dev", "dcousineau/orlex": "dev-master" }, }
  12. +vendor/autoload.php Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

    All packages (optionally) register autoload Composer compiles autoload Information Simply require vendor/autoload.php!!
  13. +PSR-0 Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

    { "require": { "silex/silex": "~1.0" }, "autoload": { "psr-0": { "App\\Namespace": "src/" } } } App\Namespace\Class src/App/Namespace/Class App\Different\NS\Class NOT AUTO-LOADED!
  14. +PSR-0 Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

    { "require": { "silex/silex": "~1.0" }, "autoload": { "psr-0": { "App\\Namespace": "src/" } } } App\Namespace\Class src/App/Namespace/Class App\Different\NS\Class NOT AUTO-LOADED! NOT REQUIRED But highly encouraged
  15. +Classmap Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

    { "require": { "silex/silex": "~1.0" }, "autoload": { "classmap": ["src/"] } } Scan directories inspecting each file for classes, adding a class-to- file entry in the autoloader
  16. +Files Daniel Cousineau // follow me : @dcousineau or http://dcousineau.com

    { "require": { "silex/silex": "~1.0" }, "autoload": { "files": ["src/functions.php"] } }
  17. +Advanced Usage Daniel Cousineau // follow me : @dcousineau or

    http://dcousineau.com <?php /** @var $loader \Composer\Autoload\ClassLoader */ $loader = require_once 'vendor/autoload.php'; $loader->add('App\\Namespace', __DIR__); { "autoload": { "psr-0": { "App\\Namespace": "src/" } } }
  18. +Dev Dependencies Daniel Cousineau // follow me : @dcousineau or

    http://dcousineau.com { "require": { "silex/silex": "~1.0" }, "require-dev": { "phpunit/phpunit": "3.7.*" } } Only installs when root-level Not when included in another project
  19. +Override Bin Directory Daniel Cousineau // follow me : @dcousineau

    or http://dcousineau.com { "require": { "silex/silex": "~1.0" }, "require-dev": { "phpunit/phpunit": "3.7.*" }, "config": { "bin-dir": "bin" } }
  20. +Install or Update? Daniel Cousineau // follow me : @dcousineau

    or http://dcousineau.com composer install composer update Use composer.lock No Dev Deps By Default Ignore composer.lock Dev Deps Default
  21. +Install or Update? Daniel Cousineau // follow me : @dcousineau

    or http://dcousineau.com composer update Ignore composer.lock Dev Deps Default My dependencies have released new versions and I want them!
  22. +Install or Update? Daniel Cousineau // follow me : @dcousineau

    or http://dcousineau.com composer install Use composer.lock No Dev Deps By Default I’ve deployed my code and I want to make sure the production server has the exact version I had when I wrote my code
  23. +Install or Update? Daniel Cousineau // follow me : @dcousineau

    or http://dcousineau.com composer install Use composer.lock No Dev Deps By Default composer install --dev Oh yeah I need those dev dependencies on my production server too!
  24. Q& A Put your questions Daniel Cousineau // follow me

    : @dcousineau or http://dcousineau.com
  25. THANKS. FOR YOUR ATTENTION Daniel Cousineau // follow me :

    @dcousineau or http://dcousineau.com