Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Like this? Share it with your network

Share
  • 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
5,312
On Slideshare
5,289
From Embeds
23
Number of Embeds
5

Actions

Shares
Downloads
15
Comments
0
Likes
4

Embeds 23

https://twitter.com 10
http://a0.twimg.com 7
https://duckduckgo.com 4
https://twimg0-a.akamaihd.net 1
http://test.idoc.vn 1

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. Nils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 2. Using a Composed Project (I) 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/naderman/projects/composer/demo/phpugka/composer.phar Use it: php composer.pharNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 3. Using a Composed Project (II) php composer.phar install Installing from lock file - Package symfony/class-loader (2.1.0-dev) Downloading Unpacking archive Cleaning up [...] - Package predis/predis (master-dev) Downloading Unpacking archive Cleaning up - Package twig/twig (1.6.0-dev) Downloading Unpacking archive Cleaning up Generating autoload filesNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 4. Using a Composed Project (III) vendor/ .composer/ bin/ pimple/ pimple/ predis/ predis/ service-provider/ silex/ silex/ symfony/ browser-kit/ class-loader/ css-selector/ dom-crawler/ event-dispatcher/ finder/ http-foundation/ http-kernel/ routing/ twig/ twig/Nils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 5. Composer Goals Ease of Use Project Dependencies - No globally installed packages Flexibility/CustomizabilityNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 6. The Basics: Defining Dependencies composer.json Located in project root directory Defines dependencies { "require": { "silex/silex": ">=1.0.0-dev", "symfony/finder": ">=2.1-dev", "twig/twig": ">=1.4", "predis/service-provider": "master-dev" } }Nils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 7. The Basics: Package Metadata { "name": "predis/predis", "type": "library", "description": "Flexible and feature-complete PHP client library for Redis", "keywords": ["nosql", "redis", "predis"], "homepage": "http://github.com/nrk/predis", "license": "MIT", "version": "0.7.1" "authors": [ { "name": "Daniele Alessandri", "email": "suppakilla@gmail.com", "homepage": "http://clorophilla.net" } ], "require": { "php": ">=5.3.0" }, "autoload": { "psr-0": {"Predis": "lib/"} } }Nils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 8. Packagist Central composer package repository Open to packages from anyone GitHub Integration: Packages from tags & branches Browse & Search PackagesNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 9. Demo: packagist.orgNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 10. composer.lock (I) List of packages & versions If available, composer install uses composer.lock instead of composer.json Created by composer install Updated by composer updateNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 11. composer.lock (II) Commit composer.lock in your VCS and ship it with your releases 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 withNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 12. Development Installation Allows you to commit changes to projects in vendor/ php composer.phar install --dev Installing from lock file [...] - Package predis/service-provider (master-dev) Cloning v0.2.3 - Package pimple/pimple (1.0.0-dev) Cloning 321db91e49b6cf8cbeed58d8db662d40de96d2c3 - Package predis/predis (master-dev) Cloning v0.7.1 - Package twig/twig (1.6.0-dev) Cloning 8256bfa05c1604bf24d8c0d1627822b4fa503e2f Generating autoload filesNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 13. Autoloading "autoload": { "psr-0": {"Predis": "lib/"} } vendor/.composer/ autoload_namespaces.php autoload.php ClassLoader.php installed.json Trashbin uses the generated autoloader require_once __DIR__./../vendor/.composer/autoload.php; use SilexApplication; use SilexExtensionTwigExtension; use SymfonyComponentFinderFinder; use SymfonyComponentHttpFoundationResponse; $app = new Application();Nils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 14. Custom Repositories "repositories": { "my-repo": { "composer": { "url": "http://example.org" } }, "MyRepo": { "vcs": { "url": "git://example.org/MyRepo.git" } }, "example org": { "pear": { "url": "http://pear.example.org" } }, "packagist": false } Composer Repository Implementations (packages.json) Packagist SatisNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 15. Depending on packages without composer.json "repositories": { "some vendor repo": { "package": { "name": "vendor/package", "version": "1.0.0", "dist": { "url": "http://example.org/package.zip", "type": "zip" }, "source": { "url": "git://example.org/package.git", "type": "git", "reference": "tag name, branch name or commit hash" } } } }, "require": { "vendor/package": "1.0.0" }Nils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 16. Other Dependency Types: Replace Useful if a patch is not available in upstream "name": "myvendor/predis", "replace": { "predis/predis": "0.7.*" } Trashbin depends on predis/service-provider which depends on predis/predis php composer.phar update myvendor/predis is installed instead of predis/predisNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 17. Other Dependency Types: Provide my/cache is a virtual package, it does not exist "name": "my/library", "require": { "my/cache": "1.0.0" } "name": "my/apc-store", "provide": { "my/cache": "1.0.0" } "name": "my/memcache-store", "provide": { "my/cache": "1.0.0" } Installing my/library will install either my/apc-store or my/memcache-store If you require another package providing my/cache,Nils Adermann neither will be installed github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 18. Other Dependency Types Conflict If vendor/a conflicts with vendor/b, they cannot be both installed Recommend If vendor/a recommends vendor/b, it will be installed unless you specify --no-install-recommends Suggest If vendor/a suggests vendor/b, it will only be installed if you specify --install-suggestsNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 19. Dependency Resolution with SAT All packages in all repositories are collected in a package pool Dependencies between all packages are turned into boolean rules: install B (version 1 or 2) (B1|B2) A requires B (version 1 or 2): (-A|B1|B2) A conflicts with B (version 1 and 2): (-A|-B1), (-A|-B2) C and D provide E: (-E|C|D) B2 updates/obsoletes B1 (-B1|-B2) Example (-A|B1|B2) (-B2|C) (A) (-B1|-B2) (-A|-C) Now use a SAT solver to find boolean values for A, B1, B2, C so that all rules are true A, B1, -B2, -C If a variable is true, it will be installedNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 20. Composer Repositories vs. PEAR Channels Repositories allow easy proxying of packages: Proxy only reviewed open source packages to a company repository Easily aggregate all open source packages on a central repository PEAR requires explicit referencing of a channel when defining dependencies: Replacing a single package with your own in a chain of dependencies is impossibleNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 21. Composer as a reusable library Phar distribution with composer-installable plugins (Beau Simensen) phpBB4: Web UI for Plugin ManagementNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org
  • 22. Thank you! Learn more & contribute packagist.org/about-composer packagist.org/about github.com/composer groups.google.com/forum/#!forum/composer-devNils Adermann github.com/composerTwitter @naderman packagist.org & getcomposer.org