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

Composer: Modern PHP Package Management

Composer: Modern PHP Package Management

Justin Yost

April 08, 2016
Tweet

More Decks by Justin Yost

Other Decks in Programming

Transcript

  1. Why Do I Care? —Multiple teammates —Install multiple versions on

    your machine —Easily stay up to date —Build new projects with Awesome Framework
  2. require __DIR__ . '/vendor/autoload.php'; $random = new Rych\Random\Random(); $randomInt =

    $random->getRandomInteger(1, 100); echo $randomInt . "\r\n";
  3. Where should you use Composer —Everywhere you have a dependency

    as part of your PHP projects —Everywhere you have a shared PHP project
  4. What all can Composer do? —It doesn't have to be

    PHP —Loadsys has a suite of shell scripts managed via Composer —github.com/loadsys/CakePHP-Shell-Scripts
  5. What all can Composer do? —It doesn't have to be

    public facing —Composer will hook into private repositories
  6. What all can Composer do? —The project doesn't even have

    to use Composer itself —Composer will install Git/SVN/Mercurial/PEAR backed projects by itself
  7. What all can Composer do? —Install Dependencies for Dev Only

    —composer require --dev {vendor/package} —composer install --dev/--no-dev
  8. What all can Composer do? —SubDependencies —Example chain: symfony/symfony ->

    doctrine/common -> doctrine/inflector -> php >=5.3.2
  9. What all can Composer do? —SubDependencies in DevMode —Only installs

    top level dev dependencies —Example chain: symfony/symfony -> cache/integration- tests -> psr/cache -> php: >=5.3.0
  10. What all can Composer do? —Lock to Major/Minor/Patch Releases vendor/package:

    3.* vendor/package: 3.0.* vendor/package: ~1.2 vendor/package: ~1.2.3 vendor/package: ^1.2.3 vendor/package: ^0.3
  11. What all can Composer do? —Suggest other packages "suggest": {

    "vendor/package": "Allow you to do other awesome thing.", },
  12. What all can Composer do? —List Meta Information for Package

    "homepage", "license", "authors", "support", "keywords", "description",
  13. What all can Composer do? —Install Custom Types —https://github.com/composer/installers "type":

    "wordpress-plugin", "require": { "composer/installers": "~1.0" }
  14. Composer Create Project composer create-project —create-project is pretty unique to

    Composer —Clones a package, installs dependencies and run scripts for setup, etc
  15. Packagist —Packagist is a repository of Composer Packages for the

    PHP Community —Packagist is open source and you can add your own packages
  16. Upgrade Your Development Process —Composer will make your projects easier

    to manage —Composer will make dependencies less of a hassle —Composer will make deployments simpler and easier
  17. Final Thoughts —Composer is PHP's way of handling dependency management

    —Composer is pretty easy to get started with —Publish your stuff with Composer/Packagist