Dependency Management with Composer
Upcoming SlideShare
Loading in...5
×
 

Dependency Management with Composer

on

  • 4,471 views

Composer is a new PHP dependency manager. It resolves and downloads the packages your project requires.

Composer is a new PHP dependency manager. It resolves and downloads the packages your project requires.

Statistics

Views

Total Views
4,471
Views on SlideShare
4,456
Embed Views
15

Actions

Likes
3
Downloads
17
Comments
0

1 Embed 15

http://www.linkedin.com 15

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Dependency Management with Composer Dependency Management with Composer Presentation Transcript

  • Jordi Boggiano@seldaekhttp://nelm.io/Dependency Managementwith Composer
  • About Me Belgian living in Zürich, Switzerland Building the internet for 10 years http://seld.be Symfony2, Composer and other OSS contributions http://github.com/Seldaek Working at Nelmio http://nelm.io Symfony2 & frontend performance consultingJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Jordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Managing Packages vs DependenciesJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Package Management in PHPJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • The Composer Ecosystem github.com/composerJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • The Composer Ecosystem Composer - CLI Tool Easy to use Installs deps per-project Flexible and embeddableJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • The Composer Ecosystem Packagist - Package Repository Aggregates PHP libraries Open to all OSS projects Feeds on VCS repositoriesJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Early adopters are loving itJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • The Composer Ecosystem Satis - Micro Repository Minimalistic Useful for closed codeJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Usage Instructions
  • Using a Composed Project git clone https://github.com/igorw/trashbin Cloning into trashbin... cd trashbin/ curl -s http://getcomposer.org/installer | php All settings correct for using Composer Composer successfully installed to: /home/bob/trashbin/composer.phar Use it: php composer.pharJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Using a Composed Project php composer.phar install Installing from lock file - Package symfony/class-loader (2.1.0-dev) Downloading Unpacking archive Cleaning up [...] - Package predis/predis (dev-master) Downloading Unpacking archive Cleaning up - Package twig/twig (1.6.0) Downloading Unpacking archive Cleaning up Generating autoload filesJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Using a Composed Project 01 vendor/ 02 .composer/ 03 bin/ 04 pimple/ 05 pimple/ 06 predis/ 07 predis/ 08 service-provider/ 09 silex/ 10 silex/ 11 symfony/ 12 browser-kit/ 13 class-loader/ 14 css-selector/ 15 dom-crawler/ 16 event-dispatcher/ 17 finder/ 18 http-foundation/ 19 http-kernel/ 20 routing/ 21 twig/ 22 twig/Jordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Downloading Project Dependencies composer.json Located in project root directory Defines dependencies 1 { 2 "require": { 3 "silex/silex": ">=1.0.0-dev", 4 "symfony/finder": "2.1-dev", 5 "twig/twig": "1.*", 6 "predis/service-provider": "dev-master" 7 } 8 } Source install: With install --prefer-source it clones/checks out the code.Jordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Creating a Package Definition 01 { 02 "name": "predis/predis", 03 "type": "library", 04 "description": "Flexible and feature-complete Redis client", 05 "keywords": ["nosql", "redis", "predis"], 06 "homepage": "http://github.com/nrk/predis", 07 "license": "MIT", 08 "version": "0.7.1" 09 "authors": [ 10 { 11 "name": "Daniele Alessandri", 12 "email": "suppakilla@gmail.com", 13 "homepage": "http://clorophilla.net" 14 } 15 ], 16 "require": { 17 "php": ">=5.3.0" 18 }, 19 "autoload": { 20 "psr-0": {"Predis": "lib/"} 21 } 22 } Note: Package Definition === Application/Root PackageJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Avoiding version chaos in your team composer.lock Lists packages & versions Replaces composer.json Created by composer install (installs your dependencies) Updated by composer update (updates your dependencies) Must be committed in your VCS and shipped with your releases Benefits Everyone on a team works with exactly the same dependency versions When deploying, all machines run exactly the same dependency versions Users will never get dependency versions that you did not test withJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Autoloading Libraries/projects define their namespaces: 1 "autoload": { 2 "psr-0": {"Predis": "lib/"} 3 } Composer builds an autoloader for you: 1 vendor/.composer/ 2 autoload_namespaces.php 3 autoload.php 4 ClassLoader.php 5 installed.json Trashbin uses the generated autoloader: 1 require_once __DIR__./../vendor/.composer/autoload.php; 2 3 use SilexApplication; 4 use SilexExtensionTwigExtension; 5 6 use SymfonyComponentFinderFinder; 7 use SymfonyComponentHttpFoundationResponse; 8 9 $app = new Application();Jordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Autoloading Tests Add your own namespaces for testing purposes in PHPUnits bootstrap: 1 # tests/bootstrap.php 2 3 $loader = require_once __DIR__./../vendor/.composer/autoload.php; 4 5 $loader->add(MyTest, __DIR__);Jordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Alternative Repositories 01 "repositories": [ 02 { 03 "type": "composer", 04 "url": "http://example.org" 05 }, 06 { 07 "type": "vcs", 08 "url": "git://example.org/MyRepo.git" 09 }, 10 { 11 "type": "pear", 12 "url": "http://pear.example.org" 13 }, 14 { 15 "packagist": false 16 } 17 ] Composer Repository Implementations ($url/packages.json) Packagist Satis (Pirum)Jordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Depending on packages without composer.json 01 "repositories": [ 02 { 03 "type": "package", 04 "package": { 05 "name": "vendor/package", 06 "version": "1.0.0", 07 "dist": { 08 "url": "http://example.org/package.zip", 09 "type": "zip" 10 }, 11 "source": { 12 "url": "git://example.org/package.git", 13 "type": "git", 14 "reference": "tag name, branch name or commit hash" 15 } 16 } 17 } 18 ], 19 "require": { 20 "vendor/package": "1.0.0" 21 } Note: repositories are only available to the root packageJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • State of the ProjectJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Adoption >500 packages on Packagist (+150 in Feb.) Alpha1 just released Many early adopters Supported by frameworks/libs Chef recipes http://goo.gl/1QMKp (Integration in apps for plugins) (Integration by PaaS providers)Jordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Missing Features Human readable error reporting User-friendliness on expected failures Better support for beta/alpha/.. releases Many more little things: github.com/composer/composer/issuesJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Wishful Thinking
  • Look around. Write small libs. Share code. Reuse things. Reinvigorate PHPJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Find Out More GetComposer.org Packagist.org github.com/composer composer-dev google group #composer & #composer-devJordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Thank you.Jordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be
  • Questions? jordi@nelm.io @seldaek slides.seld.be Feedback: http://joind.in/6051Jordi Boggiano Company nelm.ioTwitter @seldaek Blog seld.be