Mastering composer
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Mastering composer

on

  • 4,786 views

 

Statistics

Views

Total Views
4,786
Views on SlideShare
4,753
Embed Views
33

Actions

Likes
7
Downloads
14
Comments
0

1 Embed 33

https://twitter.com 33

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

Mastering composer Presentation Transcript

  • 1. Mastering Composer Adán Lobato
  • 2. What’s up! • Soy Adán Lobato • Soy de Barcelona • Soy software developer • Backend Developer en SocialPoint • Mi twitter es @adanlobato
  • 3. Agenda • Minimum stability • Branch aliases • Semantic versioning • Private Repositories • Installers • Embedded Composer • Useful links
  • 4. Parental Advisory
  • 5. Minimum stability
  • 6. Minimum stability, the problem
  • 7. Minimum stability exposed Stable! RC “minimum-stability”: Beta Alpha Dev @stable @rc @beta @alpha @dev
  • 8. minimum-stability, the global solution { "require": { "php": ">=5.3.3", "symfony/icu": "~1.0", "doctrine/common": "~2.2", "twig/twig": "~1.11", "psr/log": "~1.0" }, “minimum-stability”: “dev” }
  • 9. @stability flags, the specific solution { "require": { "php": ">=5.3.3", "symfony/icu": "~1.0", "doctrine/common": “~2.2@dev", "twig/twig": "~1.11", "psr/log": "~1.0" } }
  • 10. @stability flags, recursive stability { "require": { "php": ">=5.3.3", "symfony/icu": "~1.0", "doctrine/orm": “~2.2", "doctrine/dbal": “@dev", "twig/twig": "~1.11", "psr/log": "~1.0" } }
  • 11. prefer-stable, the “magic” solution { "require": { "php": ">=5.3.3", "symfony/icu": "~1.0", "doctrine/common": "~2.2", "twig/twig": "~1.11", "psr/log": "~1.0" }, “prefer-stable”: true }
  • 12. Branch aliases
  • 13. Branch aliases, the problem
  • 14. Branch aliases, the bad practice { "require": { “welovephp/foobar”: “dev-master” } }
  • 15. Branch aliases, the solution { “name”: “welovephp/foobar” "extra": { "branch-alias": { "dev-master": "2.5-dev" } } }
  • 16. Branch aliases & stability flags { "require": { “welovephp/foobar”: “2.5.*@dev” } }
  • 17. Branch aliases, inline aliases { "require": { “welovephp/foobar”: “my-branch as 2.5-dev” } }
  • 18. Semantic Versioning
  • 19. Semantic versioning X.Y.Z
  • 20. Semantic versioning X.Y.Z
  • 21. Semantic versioning X.Y.Z
  • 22. Semantic versioning X.Y.Z
  • 23. Semantic versioning 1.*
  • 24. Semantic versioning >=1.1,<2.0
  • 25. Semantic versioning ~1.1
  • 26. Private Repositories
  • 27. Private Repositories, the basics { “repositories”: [ { “type”: “git”, “url”: “git@github.com/welovephp/foobar.git” } ] }
  • 28. Private Repositories, the basics { “repositories”: [ { “type”: “git”, “url”: “git@github.com/welovephp/foobar.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/foobar-bundle.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/fizz.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/buzz.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/fizzbuzz-bundle.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/qwerty.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/doe.git” } ] }
  • 29. Private Repositories, the basics
  • 30. Private Repositories, the basics
  • 31. Private Repositories: Satis
  • 32. Private Repositories, Satis $ composer create-project composer/satis
  • 33. Private Repositories, Satis // config.json { "name": "WelovePhp", "homepage": "http://packages.welovephp.es", "require-all": true, “repositories”: [ { “type”: “git”, “url”: “git@github.com/welovephp/foobar.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/foobar-bundle.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/fizz.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/buzz.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/fizzbuzz-bundle.git” }, { “type”: “git”, “url”: “git@github.com/welovephp/qwerty.git” } ] }
  • 34. Private Repositories, Satis $ php bin/satis build config.json web/
  • 35. Private Repositories, Satis
  • 36. Private Repositories, Satis { "repositories": [ { "type": "composer", "url": “http://packages.welovephp.es/“ } ] }
  • 37. Private Repositories, Satis Security: • Basic HTTP Authentication • SSH • Private network ! Updates • CRON job
  • 38. Private Repositories: Packagist
  • 39. Private Repositories, Packagist • Packagist is an Open Source project • It is built as a Symfony application • You can have your own private Packagist • Supports Github Webhooks
  • 40. Private Repositories, Packagist Requirements: • MySQL • Redis • Solr • git / svn / hg
  • 41. Private Repositories: Bottlenecks
  • 42. Private Repositories, the bottlenecks
  • 43. Installers
  • 44. Installers, the official ones • Wordpress • Drupal • CakePHP • CodeIgniter • Laravel • Tons more! http://github.com/composer/installers
  • 45. Installers, building your own installer { "name": "welovephp/blog-module", "type": “welovephp-module", "require": { “welovephp/module-installer-plugin“: "*" } }
  • 46. Installers, building your own installer { "name": “welovephp/module-installer-plugin", "type": "composer-plugin", "autoload": { "psr-0": {"WeLovePhpComposer": "src/"} }, "extra": { "class": "WeLovePhpComposerModuleInstallerPlugin" }, "require": { "composer-plugin-api": “1.0.0" } }
  • 47. Installers, building your own installer namespace WeLovePhpComposer; class ModuleInstallerPlugin implements PluginInterface { public function activate(Composer $composer, IOInterface $io) { $installer = new ModuleInstaller($io, $composer); $composer->getInstallationManager()->addInstaller($installer); } }
  • 48. Installers, building your own installer namespace phpDocumentorComposer; ! class ModuleInstaller extends LibraryInstaller { public function getPackageBasePath(PackageInterface $package) { return 'welovephp/modules/'.$package->getPrettyName(); } ! public function supports($packageType) { return ‘welovephp-module' === $packageType; } }
  • 49. Embedded Composer By Beau Simensen
  • 50. Embedded Composer, the problem • You have an application • Your application has dependencies • Your application can be extended via third-party plugins • Those plugins depend on your app, but can have other extra dependencies • Both, app & plugins dependencies, must be installed once and be compatible between them
  • 51. Embedded Composer, the solution We need to be able to run Composer on runtime
  • 52. Embedded Composer & Sculpin.io
  • 53. Commands you must know
  • 54. diagnose $ composer diagnose Checks common errors to help debugging problems.
  • 55. —verbose $ composer command […] -v|vv|vvv Increase output verbosity. Useful for debugging.
  • 56. config —global $ composer config —global […] Read/Write Composer global settings.
  • 57. global $ composer global require phpunit/phpunit Add COMPOSER_HOME/vendor/bin to PATH ! Run Composer operations globally. Useful for CLI tools.
  • 58. status $ composer status Displays a list of dependencies that have been modified locally.
  • 59. show $ composer show package/name Displays detailed information about a package.
  • 60. dump-autoload —optimize $ composer dump-autoload — optimize Dumps a classmap for PSR-0 vendors.
  • 61. Useful links
  • 62. Useful links Composer • http://getcomposer.org/doc/ • https://github.com/composer/composer • https://packagist.org/ • #composerphp at twitter ! Composer Basics • http://www.slideshare.net/adanlobato/composer-gestor-de-dependencias-para-php • http://www.youtube.com/watch?v=U1dTiDlUUmU • http://adanlobato.github.io/composer-2013
  • 63. Useful links Minimum stability • http://getcomposer.org/doc/04-schema.md#minimum-stability • http://getcomposer.org/doc/04-schema.md#package-links • https://igor.io/2013/02/07/composer-stability-flags.html ! Branch alias • http://getcomposer.org/doc/articles/aliases.md • https://igor.io/2013/01/07/composer-versioning.html ! Semantic versioning • http://semver.org/
  • 64. Useful links Private Repositories • https://github.com/composer/satis • https://github.com/composer/packagist • https://help.github.com/articles/post-receive-hooks ! Installers • http://getcomposer.org/doc/articles/custom-installers.md • https://github.com/composer/installers !
  • 65. Useful links Embedded Composer • https://speakerdeck.com/simensen/embedded-composer-sflive-portland-2013 • https://github.com/dflydev/dflydev-embedded-composer • https://github.com/sculpin !
  • 66. That’s all folks! Questions?