Composer: Game Changing Dependency Management

  • 1,686 views
Uploaded on

Managing dependencies and third-party code in PHP applications is a daily challenge, keeping everyone on the same versions during development and at deploy time a struggle. Meet Composer, a tool …

Managing dependencies and third-party code in PHP applications is a daily challenge, keeping everyone on the same versions during development and at deploy time a struggle. Meet Composer, a tool designed to help you maintain a consistent set of dependencies as well as share and discover new libraries. Let’s see how you can use this tool in your Applications and Libraries to wrangle your dependencies with a simple json configuration file and a command line interface.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,686
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
8
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Composer Game Changing Dependency Management php[architect] DevOps Summit Series Jeremy Kendall
  • 2. I love to code
  • 3. I love to code I’m terribly forgetful
  • 4. I love to code I’m terribly forgetful I take pictures
  • 5. I love to code I’m terribly forgetful I take pictures I work at OpenSky
  • 6. Adding Dependencies is Easy
  • 7. Adding Dependencies is Easy ‣ Copy and Paste
  • 8. Adding Dependencies is Easy ‣ Copy and Paste ‣ DIY Solution
  • 9. Adding Dependencies is Easy ‣ Copy and Paste ‣ DIY Solution ‣ SVN Externals
  • 10. Adding Dependencies is Easy ‣ Copy and Paste ‣ DIY Solution ‣ SVN Externals ‣ Git Submodules
  • 11. Managing them is Messy
  • 12. What is Composer?
  • 13. What is Composer? ‣ Dependency management tool
  • 14. What is Composer? ‣ Dependency management tool ‣ Per-project
  • 15. What is Composer? ‣ Dependency management tool ‣ Per-project ‣ Inspired by:
  • 16. What is Composer? ‣ Dependency management tool ‣ Per-project ‣ Inspired by: ‣ node’s npm
  • 17. What is Composer? ‣ Dependency management tool ‣ Per-project ‣ Inspired by: ‣ node’s npm ‣ ruby’s bundler
  • 18. Benefits
  • 19. Benefits ‣ Easily declare project dependencies
  • 20. Benefits ‣ Easily declare project dependencies ‣ Updating dependency versions extremely simple
  • 21. Benefits ‣ Easily declare project dependencies ‣ Updating dependency versions extremely simple ‣ Ensures your team is on the same page
  • 22. Benefits ‣ Easily declare project dependencies ‣ Updating dependency versions extremely simple ‣ Ensures your team is on the same page ‣ Tons of excellent related features
  • 23. Installing
  • 24. Installing Locally $ curl -sS https://getcomposer.org/installer | phpIn your project:
  • 25. Installing Locally $ curl -sS https://getcomposer.org/installer | phpIn your project: $ curl -sS https://getcomposer.org/installer | php -- --install-dir=binSpecify a directory:
  • 26. Installing Locally $ curl -sS https://getcomposer.org/installer | phpIn your project: $ curl -sS https://getcomposer.org/installer | php -- --install-dir=binSpecify a directory: $ curl -sS https://getcomposer.org/installer | php #!/usr/bin/env php All settings correct for using Composer Downloading... Composer successfully installed to: /Users/jkendall/dev/ composer.phar Use it: php composer.phar What you’ll see:
  • 27. Installing Globally $ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer Recommended
  • 28. Installing Globally $ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer (You might need to use sudo) Recommended
  • 29. (There’s an installer for Windows folks)
  • 30. Keeping up to Date $ composer self-update You are using the latest composer version. $ php composer.phar self-update You are using the latest composer version. or
  • 31. Keeping up to Date $ composer self-update You are using the latest composer version. (Always updates to the latest dev-master) $ php composer.phar self-update You are using the latest composer version. or
  • 32. Defining Dependencies
  • 33. composer.json { "require": { "monolog/monolog": "1.5.*" } }
  • 34. composer.json { "require": { "monolog/monolog": "1.5.*" } } ‣Place in the root of your project
  • 35. composer.json { "require": { "monolog/monolog": "1.5.*" } } ‣Place in the root of your project ‣“require” specifies package and version
  • 36. composer.json { "require": { "monolog/monolog": "1.5.*" } } ‣Place in the root of your project ‣“require” specifies package and version ‣monolog logging library
  • 37. composer.json { "require": { "monolog/monolog": "1.5.*" } } ‣Place in the root of your project ‣“require” specifies package and version ‣monolog logging library ‣Version >= 1.5.0 and < 1.6
  • 38. composer.json { "require": { "monolog/monolog": "1.5.*" } } ‣Place in the root of your project ‣“require” specifies package and version ‣monolog logging library ‣Version >= 1.5.0 and < 1.6 ‣No fuss, no muss
  • 39. Versions
  • 40. ‣ Exact version: 1.0.0, 12.2.4, etc. Versions
  • 41. ‣ Exact version: 1.0.0, 12.2.4, etc. ‣ Wildcard: 3.*, 4.2.* Versions
  • 42. ‣ Exact version: 1.0.0, 12.2.4, etc. ‣ Wildcard: 3.*, 4.2.* ‣ Range: >, >=, <=, != Versions
  • 43. ‣ Exact version: 1.0.0, 12.2.4, etc. ‣ Wildcard: 3.*, 4.2.* ‣ Range: >, >=, <=, != ‣ Example: >=2.4 Versions
  • 44. ‣ Exact version: 1.0.0, 12.2.4, etc. ‣ Wildcard: 3.*, 4.2.* ‣ Range: >, >=, <=, != ‣ Example: >=2.4 ‣ Range: >=1.0,<1.7 (comma separated) Versions
  • 45. ‣ Exact version: 1.0.0, 12.2.4, etc. ‣ Wildcard: 3.*, 4.2.* ‣ Range: >, >=, <=, != ‣ Example: >=2.4 ‣ Range: >=1.0,<1.7 (comma separated) ‣ Next Significant Release: ~1.3.3 Versions
  • 46. Installing Dependencies $ composer install Loading composer repositories with package information Installing dependencies (including require-dev) - Installing psr/log (1.0.0) Loading from cache - Installing monolog/monolog (1.5.0) Loading from cache monolog/monolog suggests installing mlehner/gelf-php (Allow sending log messages to a GrayLog2 server) monolog/monolog suggests installing raven/raven (Allow sending log messages to a Sentry server) monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server) monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required)) Writing lock file Generating autoload files composer install
  • 47. composer.lock
  • 48. composer.lock ‣ install writes a dependency lock file
  • 49. composer.lock ‣ install writes a dependency lock file ‣ List of exact versions installed
  • 50. composer.lock ‣ install writes a dependency lock file ‣ List of exact versions installed ‣ Commit both composer.lock and composer.json
  • 51. composer.lock ‣ install writes a dependency lock file ‣ List of exact versions installed ‣ Commit both composer.lock and composer.json ‣ composer install now checks the lock file, not composer.json
  • 52. composer.lock ‣ install writes a dependency lock file ‣ List of exact versions installed ‣ Commit both composer.lock and composer.json ‣ composer install now checks the lock file, not composer.json ‣ Update dependencies with composer update
  • 53. Updating Dependencies
  • 54. Updating Dependencies { "require": { "monolog/monolog": "1.6.*@dev" } }
  • 55. Updating Dependencies { "require": { "monolog/monolog": "1.6.*@dev" } } ‣Updates monolog library version
  • 56. Updating Dependencies { "require": { "monolog/monolog": "1.6.*@dev" } } ‣Updates monolog library version ‣Version >= 1.6.0 and < 1.7 (dev)
  • 57. Updating Dependencies $ composer update Loading composer repositories with package information Updating dependencies (including require-dev) - Removing monolog/monolog (1.5.0) - Installing monolog/monolog (dev-master c933bb6) Cloning c933bb67a8a2e45c42d0626a0cd6569789bf6ed7 Writing lock file Generating autoload files composer update
  • 58. Updating Dependencies $ composer update Loading composer repositories with package information Updating dependencies (including require-dev) - Removing monolog/monolog (1.5.0) - Installing monolog/monolog (dev-master c933bb6) Cloning c933bb67a8a2e45c42d0626a0cd6569789bf6ed7 Writing lock file Generating autoload files ‣Reads from composer.json composer update
  • 59. Updating Dependencies $ composer update Loading composer repositories with package information Updating dependencies (including require-dev) - Removing monolog/monolog (1.5.0) - Installing monolog/monolog (dev-master c933bb6) Cloning c933bb67a8a2e45c42d0626a0cd6569789bf6ed7 Writing lock file Generating autoload files ‣Reads from composer.json ‣Updates dependencies composer update
  • 60. Updating Dependencies $ composer update Loading composer repositories with package information Updating dependencies (including require-dev) - Removing monolog/monolog (1.5.0) - Installing monolog/monolog (dev-master c933bb6) Cloning c933bb67a8a2e45c42d0626a0cd6569789bf6ed7 Writing lock file Generating autoload files ‣Reads from composer.json ‣Updates dependencies ‣Rewrites lock file composer update
  • 61. Adding New Dependencies Edit composer.json . . . { "require": { "monolog/monolog": "1.6.*@dev", "ircmaxell/password-compat": "1.0.3" } }
  • 62. Adding New Dependencies Or use the command line $ composer require ircmaxell/password-compat:1.0.3 composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) - Installing ircmaxell/password-compat (1.0.3) Downloading: 100% Writing lock file Generating autoload files composer require
  • 63. Autoloading
  • 64. Autoloading ‣ Composer generates vendor/autoload.php
  • 65. Autoloading ‣ Composer generates vendor/autoload.php ‣ Add require ‘vendor/autoload.php’;
  • 66. Autoloading ‣ Composer generates vendor/autoload.php ‣ Add require ‘vendor/autoload.php’; ‣ Immediately begin using your dependencies
  • 67. Autoloading { "require": { "monolog/monolog": "1.6.*@dev" }, "autoload": { "psr-0": { "Beeblebrox": "src/" } } } Don’t forget to add your own code!
  • 68. Autoloading $loader = require 'vendor/autoload.php'; $loader->add('AcmeTest', __DIR__); Pro Tip Grab an autoloader instance and add more namespaces.
  • 69. Kickstart a Project $ composer create-project slim/slim-skeleton super-sweet-application Installing slim/slim-skeleton (1.1.0) - Installing slim/slim-skeleton (1.1.0) Downloading: 100% Created project in super-sweet-application Loading composer repositories with package information Installing dependencies (including require-dev) - Installing slim/slim (2.3.0) Downloading: 100% - Installing slim/extras (2.0.3) Loading from cache - Installing twig/twig (v1.13.1) Loading from cache Writing lock file Generating autoload files composer create-project
  • 70. YourVery Own Library
  • 71. Libraries
  • 72. Libraries ‣ Everyone has written a library of some sort
  • 73. Libraries ‣ Everyone has written a library of some sort ‣ Making up examples is not my strong suit
  • 74. Libraries ‣ Everyone has written a library of some sort ‣ Making up examples is not my strong suit ‣ Let’s walk through a real library . . .
  • 75. Libraries ‣ Everyone has written a library of some sort ‣ Making up examples is not my strong suit ‣ Let’s walk through a real library . . . ‣ . . . and check out some awesome Composer features
  • 76. PHP Domain Parser https://github.com/jeremykendall/php-domain-parser
  • 77. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } }
  • 78. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } } Package requirements
  • 79. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } } Package requirements Autoloading
  • 80. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } } Add the “name” key and it’s installable
  • 81. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } } Additional metadata
  • 82. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } } Don’t forget the license!
  • 83. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } } Full fledged library!
  • 84. Now for the cool(er) stuff . . .
  • 85. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } } require-dev
  • 86. require-dev
  • 87. require-dev ‣ Lists packages required for development (think tests)
  • 88. require-dev ‣ Lists packages required for development (think tests) ‣ Only applies to the root package
  • 89. require-dev ‣ Lists packages required for development (think tests) ‣ Only applies to the root package ‣ Both install and update install require-dev by default
  • 90. require-dev ‣ Lists packages required for development (think tests) ‣ Only applies to the root package ‣ Both install and update install require-dev by default ‣ (Use the --no-dev flag to skip installing dev dependencies)
  • 91. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } } bin
  • 92. bin
  • 93. bin ‣ cli scripts to pass along to package users
  • 94. bin ‣ cli scripts to pass along to package users ‣ A set of files that should be treated as binaries
  • 95. bin ‣ cli scripts to pass along to package users ‣ A set of files that should be treated as binaries ‣ Installs binaries to vendor/bin for any project that depends on your project
  • 96. bin ‣ cli scripts to pass along to package users ‣ A set of files that should be treated as binaries ‣ Installs binaries to vendor/bin for any project that depends on your project ‣ php-domain-parser uses a bin to update the local copy of the public suffix list
  • 97. { "name": "jeremykendall/php-domain-parser", "description": "Public Suffix List based URL parsing implemented in PHP.", "license": "MIT", "authors": [ { "name": "Jeremy Kendall", "homepage": "http://about.me/jeremykendall", "role": "Developer" } ], "bin": ["bin/pdp-psl"], "keywords": ["Public Suffix List", "domain parsing", "url parsing"], "require": { "php": ">=5.3.0", "ext-curl": "*" }, "require-dev": { "mikey179/vfsStream": "1.1.*", "jeremykendall/phpctagger": "0.0.*" }, "autoload": { "psr-0": { "Pdp": "library/" } }, "scripts": { "post-install-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ], "post-update-cmd": [ "PhpCtaggerComposerScriptCtagger::ctag" ] } } scripts
  • 98. scripts
  • 99. scripts ‣ Used to execute custom code during the Composer execution process
  • 100. scripts ‣ Used to execute custom code during the Composer execution process ‣ PHP callback (defined as a static method) . . .
  • 101. scripts ‣ Used to execute custom code during the Composer execution process ‣ PHP callback (defined as a static method) . . . ‣ . . . or any command-line executable command
  • 102. scripts ‣ Used to execute custom code during the Composer execution process ‣ PHP callback (defined as a static method) . . . ‣ . . . or any command-line executable command ‣ Only scripts defined in the root composer.json are executed
  • 103. scripts ‣ Used to execute custom code during the Composer execution process ‣ PHP callback (defined as a static method) . . . ‣ . . . or any command-line executable command ‣ Only scripts defined in the root composer.json are executed ‣ If a script is defined in a dependency, you can use it in your composer.json
  • 104. scripts
  • 105. scripts ‣ Composer fires “named events” during execution
  • 106. scripts ‣ Composer fires “named events” during execution ‣ Named events include:
  • 107. scripts ‣ Composer fires “named events” during execution ‣ Named events include: ‣ pre- and post-install-cmd
  • 108. scripts ‣ Composer fires “named events” during execution ‣ Named events include: ‣ pre- and post-install-cmd ‣ pre- and post-update-cmd
  • 109. scripts ‣ Composer fires “named events” during execution ‣ Named events include: ‣ pre- and post-install-cmd ‣ pre- and post-update-cmd ‣ post-root-package-install
  • 110. scripts ‣ Composer fires “named events” during execution ‣ Named events include: ‣ pre- and post-install-cmd ‣ pre- and post-update-cmd ‣ post-root-package-install ‣ Many more . . .
  • 111. Running scripts
  • 112. Running scripts Execute Composer (script will execute if the named event is triggered) or . . .
  • 113. Running scripts Execute Composer (script will execute if the named event is triggered) or . . .
  • 114. Running scripts Execute Composer (script will execute if the named event is triggered) or . . . composer run-script <named event>
  • 115. Example public static function create(Event $event) { $dir = dirname($event->getComposer()->getConfig()->get('vendor-dir')); $io = $event->getIO(); $io->write('Reviewing your Flaming Archer environment . . .', true); $configExists = file_exists($dir . '/config.php'); $configDistExists = file_exists($dir . '/config-dist.php'); if (!$configExists && $configDistExists) { $io->write('Creating config.php by copying config-dist.php . . .', true); copy($dir . '/config-dist.php', $dir . '/config.php'); $io->write("Done! Please edit config.php.", true); } else { $io->write('Found config.php.', true); } } https://github.com/jeremykendall/flaming-archer/blob/develop/library/Fa/Composer/Script/Config.php
  • 116. You’ve built your library. Now what?
  • 117. Push it to aVCS
  • 118. Push it to aVCS ‣ git, svn, or hg all work equally well
  • 119. Push it to aVCS ‣ git, svn, or hg all work equally well ‣ For the sake of simplicity I’ll assume git/github
  • 120. Push it to aVCS ‣ git, svn, or hg all work equally well ‣ For the sake of simplicity I’ll assume git/github ‣ Package versions:
  • 121. Push it to aVCS ‣ git, svn, or hg all work equally well ‣ For the sake of simplicity I’ll assume git/github ‣ Package versions: ‣ Tags are package versions (1.0.0, v2.5.4, etc)
  • 122. Push it to aVCS ‣ git, svn, or hg all work equally well ‣ For the sake of simplicity I’ll assume git/github ‣ Package versions: ‣ Tags are package versions (1.0.0, v2.5.4, etc) ‣ Branches are dev versions (dev-{branchname}, {branchname}-dev)
  • 123. Push it to aVCS ‣ git, svn, or hg all work equally well ‣ For the sake of simplicity I’ll assume git/github ‣ Package versions: ‣ Tags are package versions (1.0.0, v2.5.4, etc) ‣ Branches are dev versions (dev-{branchname}, {branchname}-dev) ‣ For this reason, I strongly recommend using semantic versioning: http://semver.org
  • 124. Share!
  • 125. Packagist
  • 126. Packagist
  • 127. Packagist ‣ The main package repository for Composer
  • 128. Packagist ‣ The main package repository for Composer ‣ (Aside: Search Packagist before “rolling your own”)
  • 129. Packagist ‣ The main package repository for Composer ‣ (Aside: Search Packagist before “rolling your own”) ‣ Packages published there need no special settings in composer.json to be installable (see “repositories” key)
  • 130. Packagist ‣ The main package repository for Composer ‣ (Aside: Search Packagist before “rolling your own”) ‣ Packages published there need no special settings in composer.json to be installable (see “repositories” key) ‣ Submitting is dead simple
  • 131. Packagist ‣ The main package repository for Composer ‣ (Aside: Search Packagist before “rolling your own”) ‣ Packages published there need no special settings in composer.json to be installable (see “repositories” key) ‣ Submitting is dead simple ‣ Create account, hit big green submit button
  • 132. Packagist
  • 133. Packagist: Package Search
  • 134. Packagist: Keyword Search
  • 135. Packagist: Package
  • 136. But what about internal proprietary packages?
  • 137. Satis to the Rescue
  • 138. Satis to the Rescue ‣ Static composer repository generator
  • 139. Satis to the Rescue ‣ Static composer repository generator ‣ Lightweight, static file based version of Packagist
  • 140. Satis to the Rescue ‣ Static composer repository generator ‣ Lightweight, static file based version of Packagist ‣ Simple to configure
  • 141. Satis to the Rescue ‣ Static composer repository generator ‣ Lightweight, static file based version of Packagist ‣ Simple to configure ‣ Flexible
  • 142. $ composer create-project composer/satis --stability=dev --keep-vcs Installing composer/satis (dev-master 059588ef0fd0977964ad13637e02012519686202) - Installing composer/satis (dev-master master) Cloning master Created project in /Users/jkendall/dev/satis Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Warning: The lock file is not up to date with the latest changes in composer.json . . . - Installing symfony/process (dev-master 75c8101) Cloning 75c810176f8e069714cef8696d7ecc3aa86e8168 - [ . . . ] - Installing twig/twig (v1.13.1) Loading from cache symfony/console suggests installing symfony/event-dispatcher () Generating autoload files composer create-project composer/satis --stability=dev --keep-vcs
  • 143. Satis config.json { "name": "Satis Demo", "homepage": "http://satis.dev", "repositories": [ { "type": "vcs", "url": "https://github.com/jeremykendall/php-domain-parser" }, { "type": "vcs", "url": "https://github.com/jeremykendall/phpctagger" } ], "require": { "jeremykendall/php-domain-parser": ">=0.0.5", "jeremykendall/phpctagger": ">0.0.6" }, "archive": { "directory": "dist", "format": "tar" } }
  • 144. Satis config.json { "name": "Satis Demo", "homepage": "http://satis.dev", "repositories": [ { "type": "vcs", "url": "https://github.com/jeremykendall/php-domain-parser" }, { "type": "vcs", "url": "https://github.com/jeremykendall/phpctagger" } ], "require": { "jeremykendall/php-domain-parser": ">=0.0.5", "jeremykendall/phpctagger": ">0.0.6" }, "archive": { "directory": "dist", "format": "tar" } }
  • 145. Satis config.json { "name": "Satis Demo", "homepage": "http://satis.dev", "repositories": [ { "type": "vcs", "url": "https://github.com/jeremykendall/php-domain-parser" }, { "type": "vcs", "url": "https://github.com/jeremykendall/phpctagger" } ], "require": { "jeremykendall/php-domain-parser": ">=0.0.5", "jeremykendall/phpctagger": ">0.0.6" }, "archive": { "directory": "dist", "format": "tar" } }
  • 146. Satis config.json { "name": "Satis Demo", "homepage": "http://satis.dev", "repositories": [ { "type": "vcs", "url": "https://github.com/jeremykendall/php-domain-parser" }, { "type": "vcs", "url": "https://github.com/jeremykendall/phpctagger" } ], "require": { "jeremykendall/php-domain-parser": ">=0.0.5", "jeremykendall/phpctagger": ">0.0.6" }, "archive": { "directory": "dist", "format": "tar" } }
  • 147. Satis config.json { "name": "Satis Demo", "homepage": "http://satis.dev", "repositories": [ { "type": "vcs", "url": "https://github.com/jeremykendall/php-domain-parser" }, { "type": "vcs", "url": "https://github.com/jeremykendall/phpctagger" } ], "require": { "jeremykendall/php-domain-parser": ">=0.0.5", "jeremykendall/phpctagger": ">0.0.6" }, "archive": { "directory": "dist", "format": "tar" } }
  • 148. Build Repo $ php bin/satis build config.json web/
  • 149. composer.json { "repositories": [ { "type": "composer", "url": "http://satis.dev" } ], "require": { "jeremykendall/php-domain-parser": "0.0.7" } }
  • 150. composer.json { "repositories": [ { "type": "composer", "url": "http://satis.dev" } ], "require": { "jeremykendall/php-domain-parser": "0.0.7" } }
  • 151. composer.json { "repositories": [ { "type": "composer", "url": "http://satis.dev" } ], "require": { "jeremykendall/php-domain-parser": "0.0.7" } }
  • 152. Satis Demo Project
  • 153. Satis Demo Project ‣ Want to goof around with Satis?
  • 154. Satis Demo Project ‣ Want to goof around with Satis? ‣ See: https://github.com/jeremykendall/satis-demo
  • 155. Satis Demo Project ‣ Want to goof around with Satis? ‣ See: https://github.com/jeremykendall/satis-demo ‣ Clone, follow instructions in README, and WIN
  • 156. Satis Demo Project ‣ Want to goof around with Satis? ‣ See: https://github.com/jeremykendall/satis-demo ‣ Clone, follow instructions in README, and WIN ‣ Satis really is dead simple to set up
  • 157. Parting Tips and Tricks
  • 158. composer install --no-dev --prefer-dist --optimize-autoloader
  • 159. “example/package”: “2.3.x-dev#5aec89a”
  • 160. Non-Composer and PEAR packages can be installed (see “repositories” key documentation)
  • 161. http://getcomposer.org #composer on irc.freenode.org
  • 162. There’s So Much More!
  • 163. Credits
  • 164. Credits ‣ Thanks to php[architect] for having me IMMA LET YOU FINISH, BUT RAFAEL DOHMS HAS THE BEST COMPOSER TALK OF ALL TIME.
  • 165. Credits
  • 166. Credits ‣ Thanks to Rafael Dohms, the Composer presenter
  • 167. Credits ‣ Thanks to Rafael Dohms, the Composer presenter ‣ Thanks to php[architect] for having me
  • 168. Credits ‣ Thanks to Rafael Dohms, the Composer presenter ‣ Thanks to php[architect] for having me ‣ Thanks to Jordi Boggiano, Nils Adermann, and the community for an amazing project (and all the documentation I cribbed from)
  • 169. Credits ‣ Thanks to Rafael Dohms, the Composer presenter ‣ Thanks to php[architect] for having me ‣ Thanks to Jordi Boggiano, Nils Adermann, and the community for an amazing project (and all the documentation I cribbed from) ‣ Thanks to our sponsors for help making this happen
  • 170. Credits ‣ Thanks to Rafael Dohms, the Composer presenter ‣ Thanks to php[architect] for having me ‣ Thanks to Jordi Boggiano, Nils Adermann, and the community for an amazing project (and all the documentation I cribbed from) ‣ Thanks to our sponsors for help making this happen ‣ Thanks to all of you for being here
  • 171. Thanks! jeremy@jeremykendall.net http://about.me/jeremykendall @jeremykendall https://joind.in/8968