0
Mastering Composer
Adán Lobato
What’s up!

•

Soy Adán Lobato


•

Soy de Barcelona


•

Soy software developer


•

Backend Developer en SocialPoint


•...
Agenda
•

Minimum stability


•

Branch aliases


•

Semantic versioning


•

Private Repositories


•

Installers


•

Em...
Parental Advisory
Minimum stability
Minimum stability, the problem
Minimum stability exposed

Stable!
RC
“minimum-stability”:

Beta
Alpha
Dev

@stable
@rc
@beta
@alpha
@dev
minimum-stability, the global solution
{
"require": {
"php": ">=5.3.3",
"symfony/icu": "~1.0",
"doctrine/common": "~2.2",
...
@stability flags, the specific solution
{
"require": {
"php": ">=5.3.3",
"symfony/icu": "~1.0",
"doctrine/common": “~2.2@dev...
@stability flags, recursive stability
{
"require": {
"php": ">=5.3.3",
"symfony/icu": "~1.0",
"doctrine/orm": “~2.2",
"doct...
prefer-stable, the “magic” solution
{
"require": {
"php": ">=5.3.3",
"symfony/icu": "~1.0",
"doctrine/common": "~2.2",
"tw...
Branch aliases
Branch aliases, the problem
Branch aliases, the bad practice

{
"require": {
“welovephp/foobar”: “dev-master”
}
}
Branch aliases, the solution
{
“name”: “welovephp/foobar”
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
}
}
Branch aliases & stability flags

{
"require": {
“welovephp/foobar”: “2.5.*@dev”
}
}
Branch aliases, inline aliases

{
"require": {
“welovephp/foobar”: “my-branch as 2.5-dev”

}
}
Semantic
Versioning
Semantic versioning

X.Y.Z
Semantic versioning

X.Y.Z
Semantic versioning

X.Y.Z
Semantic versioning

X.Y.Z
Semantic versioning

1.*
Semantic versioning

>=1.1,<2.0
Semantic versioning

~1.1
Private

Repositories
Private Repositories, the basics
{
“repositories”: [
{
“type”: “git”,
“url”: “git@github.com/welovephp/foobar.git”
}
]
}
Private Repositories, the basics
{
“repositories”: [
{ “type”: “git”, “url”: “git@github.com/welovephp/foobar.git” },
{ “t...
Private Repositories, the basics
Private Repositories, the basics
Private Repositories:

Satis
Private Repositories, Satis

$ composer create-project composer/satis
Private Repositories, Satis
// config.json
{
"name": "WelovePhp",
"homepage": "http://packages.welovephp.es",
"require-all...
Private Repositories, Satis

$ php bin/satis build config.json web/
Private Repositories, Satis
Private Repositories, Satis
{
"repositories": [
{
"type": "composer",
"url": “http://packages.welovephp.es/“
}
]
}
Private Repositories, Satis
Security:

•

Basic HTTP Authentication


•

SSH


•

Private network

!

Updates

•

CRON job
Private Repositories:

Packagist
Private Repositories, Packagist

•

Packagist is an Open Source project


•

It is built as a Symfony application


•

You...
Private Repositories, Packagist

Requirements:

•

MySQL


•

Redis


•

Solr


•

git / svn / hg
Private Repositories:

Bottlenecks
Private Repositories, the bottlenecks
Installers
Installers, the official ones
•

Wordpress


•

Drupal


•

CakePHP


•

CodeIgniter


•

Laravel


•

Tons more!

http://g...
Installers, building your own installer
{
"name": "welovephp/blog-module",
"type": “welovephp-module",
"require": {
“welov...
Installers, building your own installer
{
"name": “welovephp/module-installer-plugin",
"type": "composer-plugin",
"autoloa...
Installers, building your own installer
namespace WeLovePhpComposer;
class ModuleInstallerPlugin implements PluginInterfac...
Installers, building your own installer
namespace phpDocumentorComposer;

!
class ModuleInstaller extends LibraryInstaller...
Embedded
Composer
By Beau Simensen
Embedded Composer, the problem
•

You have an application


•

Your application has dependencies


•

Your application can...
Embedded Composer, the solution

We need to be able to run Composer on runtime
Embedded Composer & Sculpin.io
Commands you
must know
diagnose

$ composer diagnose
Checks common errors to help debugging problems.
—verbose

$ composer command […] -v|vv|vvv
Increase output verbosity. Useful for debugging.
config —global

$ composer config —global […]
Read/Write Composer global settings.
global

$ composer global require phpunit/phpunit
Add COMPOSER_HOME/vendor/bin to PATH

!

Run Composer operations globall...
status

$ composer status
Displays a list of dependencies that have been
modified locally.
show

$ composer show package/name
Displays detailed information about a package.
dump-autoload —optimize

$ composer dump-autoload —
optimize
Dumps a classmap for PSR-0 vendors.
Useful links
Useful links
Composer

•

http://getcomposer.org/doc/


•

https://github.com/composer/composer


•

https://packagist.org...
Useful links
Minimum stability

•

http://getcomposer.org/doc/04-schema.md#minimum-stability


•

http://getcomposer.org/d...
Useful links
Private Repositories

•

https://github.com/composer/satis


•

https://github.com/composer/packagist


•

ht...
Useful links

Embedded Composer

•

https://speakerdeck.com/simensen/embedded-composer-sflive-portland-2013


•

https://gi...
That’s all folks!
Questions?
Upcoming SlideShare
Loading in...5
×

Mastering composer

8,998

Published on

0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
8,998
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
20
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

Transcript of "Mastering composer"

  1. 1. Mastering Composer Adán Lobato
  2. 2. What’s up! • Soy Adán Lobato • Soy de Barcelona • Soy software developer • Backend Developer en SocialPoint • Mi twitter es @adanlobato
  3. 3. Agenda • Minimum stability • Branch aliases • Semantic versioning • Private Repositories • Installers • Embedded Composer • Useful links
  4. 4. Parental Advisory
  5. 5. Minimum stability
  6. 6. Minimum stability, the problem
  7. 7. Minimum stability exposed Stable! RC “minimum-stability”: Beta Alpha Dev @stable @rc @beta @alpha @dev
  8. 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. 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. 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. 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. 12. Branch aliases
  13. 13. Branch aliases, the problem
  14. 14. Branch aliases, the bad practice { "require": { “welovephp/foobar”: “dev-master” } }
  15. 15. Branch aliases, the solution { “name”: “welovephp/foobar” "extra": { "branch-alias": { "dev-master": "2.5-dev" } } }
  16. 16. Branch aliases & stability flags { "require": { “welovephp/foobar”: “2.5.*@dev” } }
  17. 17. Branch aliases, inline aliases { "require": { “welovephp/foobar”: “my-branch as 2.5-dev” } }
  18. 18. Semantic Versioning
  19. 19. Semantic versioning X.Y.Z
  20. 20. Semantic versioning X.Y.Z
  21. 21. Semantic versioning X.Y.Z
  22. 22. Semantic versioning X.Y.Z
  23. 23. Semantic versioning 1.*
  24. 24. Semantic versioning >=1.1,<2.0
  25. 25. Semantic versioning ~1.1
  26. 26. Private Repositories
  27. 27. Private Repositories, the basics { “repositories”: [ { “type”: “git”, “url”: “git@github.com/welovephp/foobar.git” } ] }
  28. 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. 29. Private Repositories, the basics
  30. 30. Private Repositories, the basics
  31. 31. Private Repositories: Satis
  32. 32. Private Repositories, Satis $ composer create-project composer/satis
  33. 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. 34. Private Repositories, Satis $ php bin/satis build config.json web/
  35. 35. Private Repositories, Satis
  36. 36. Private Repositories, Satis { "repositories": [ { "type": "composer", "url": “http://packages.welovephp.es/“ } ] }
  37. 37. Private Repositories, Satis Security: • Basic HTTP Authentication • SSH • Private network ! Updates • CRON job
  38. 38. Private Repositories: Packagist
  39. 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. 40. Private Repositories, Packagist Requirements: • MySQL • Redis • Solr • git / svn / hg
  41. 41. Private Repositories: Bottlenecks
  42. 42. Private Repositories, the bottlenecks
  43. 43. Installers
  44. 44. Installers, the official ones • Wordpress • Drupal • CakePHP • CodeIgniter • Laravel • Tons more! http://github.com/composer/installers
  45. 45. Installers, building your own installer { "name": "welovephp/blog-module", "type": “welovephp-module", "require": { “welovephp/module-installer-plugin“: "*" } }
  46. 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. 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. 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. 49. Embedded Composer By Beau Simensen
  50. 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. 51. Embedded Composer, the solution We need to be able to run Composer on runtime
  52. 52. Embedded Composer & Sculpin.io
  53. 53. Commands you must know
  54. 54. diagnose $ composer diagnose Checks common errors to help debugging problems.
  55. 55. —verbose $ composer command […] -v|vv|vvv Increase output verbosity. Useful for debugging.
  56. 56. config —global $ composer config —global […] Read/Write Composer global settings.
  57. 57. global $ composer global require phpunit/phpunit Add COMPOSER_HOME/vendor/bin to PATH ! Run Composer operations globally. Useful for CLI tools.
  58. 58. status $ composer status Displays a list of dependencies that have been modified locally.
  59. 59. show $ composer show package/name Displays detailed information about a package.
  60. 60. dump-autoload —optimize $ composer dump-autoload — optimize Dumps a classmap for PSR-0 vendors.
  61. 61. Useful links
  62. 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. 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. 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. 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. 66. That’s all folks! Questions?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×