134
Composer the right way @rdohms Rafael Dohms

Composer the right way - NomadPHP

Embed Size (px)

Citation preview

Page 1: Composer the right way - NomadPHP

Composerthe right way

@rdohmsRafael Dohms

Page 2: Composer the right way - NomadPHP

photo: smileymanwithahat

Page 3: Composer the right way - NomadPHP
Page 4: Composer the right way - NomadPHP
Page 5: Composer the right way - NomadPHP

photo: Rob Allen

Page 6: Composer the right way - NomadPHP

photo: 18millionpixels

Page 7: Composer the right way - NomadPHP

Library Publisher

photo: 18millionpixels

Page 8: Composer the right way - NomadPHP

Library Publisher

Library Consumer

photo: 18millionpixels

Page 9: Composer the right way - NomadPHP

Library Publisher

Library

Library Consumer

photo: 18millionpixels

Page 10: Composer the right way - NomadPHP

Library Publisher

Library

Library Consumer

Packagist

photo: 18millionpixels

Page 11: Composer the right way - NomadPHP

photo: 18millionpixels

Page 12: Composer the right way - NomadPHP

{ "require": { "monolog/monolog": “2.0” }}

photo: 18millionpixels

Page 13: Composer the right way - NomadPHP

{ "require": { "monolog/monolog": “2.0” }}

{ "name": “monolog/monolog”

...}

photo: 18millionpixels

Page 14: Composer the right way - NomadPHP

{ "require": { "monolog/monolog": “2.0” }}

{ "name": “monolog/monolog”

...}

./composer.json has been updatedLoading composer repositories with package informationUpdating dependencies (including require-dev)Your requirements could not be resolved to an installable set of packages.

Problem 1 - The requested package monolog/monolog could not be found in any version, there may be a typo in the package name.

Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

photo: 18millionpixels

Page 15: Composer the right way - NomadPHP

{ "require": { "monolog/monolog": “2.0” }}

{ "name": “monolog/monolog”

...}

./composer.json has been updatedLoading composer repositories with package informationUpdating dependencies (including require-dev)Your requirements could not be resolved to an installable set of packages.

Problem 1 - The requested package monolog/monolog could not be found in any version, there may be a typo in the package name.

Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

___~1.1

photo: 18millionpixels

Page 16: Composer the right way - NomadPHP

{ "require": { "monolog/monolog": “2.0” }}

{ "name": “monolog/monolog”

...}

./composer.json has been updatedLoading composer repositories with package informationUpdating dependencies (including require-dev)Your requirements could not be resolved to an installable set of packages.

Problem 1 - The requested package monolog/monolog could not be found in any version, there may be a typo in the package name.

Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

./composer.json has been updatedLoading composer repositories with package informationUpdating dependencies (including require-dev) - Installing psr/log (1.0.0) Loading from cache

- Installing monolog/monolog (1.11.0) Downloading: 100%

monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)[...]monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)Writing lock fileGenerating autoload files

___~1.1

photo: 18millionpixels

Page 17: Composer the right way - NomadPHP

composer

Page 18: Composer the right way - NomadPHP

composercomposer.json!

Page 19: Composer the right way - NomadPHP

composercomposer.json!

composer.lock!

Page 20: Composer the right way - NomadPHP

composercomposer.json!

composer.lock!

Page 21: Composer the right way - NomadPHP

discovery Packagist

"

composercomposer.json!

composer.lock!

Page 22: Composer the right way - NomadPHP

discovery sourcePackagist

"

Repository

#

composercomposer.json!

composer.lock!

Page 23: Composer the right way - NomadPHP

discovery source

installation

Packagist

"

Vendor Folder

$

Repository

#

composercomposer.json!

composer.lock!

Page 24: Composer the right way - NomadPHP

$ composer init

Library Publisher

Page 25: Composer the right way - NomadPHP

$ composer init

Library Publisher

$ composer require <vendor>/<package>

Library Consumer

Page 26: Composer the right way - NomadPHP

$ composer require monolog/monolog

Tip

Page 27: Composer the right way - NomadPHP

$ composer require monolog/monolog

Tip

Using version ~1.11 for monolog/monolog

Page 28: Composer the right way - NomadPHP

Release the @DOHMSRAKEN!!

photo by @rosstuck

Page 29: Composer the right way - NomadPHP

Library PublishersComposer for

Page 30: Composer the right way - NomadPHP

Library Publisher Unique vendor names

vendor / package

Page 31: Composer the right way - NomadPHP

Library Publisher Unique vendor names

pick your own unique vendor

Page 32: Composer the right way - NomadPHP

Library Publisher Unique vendor names

or join a collective

Page 33: Composer the right way - NomadPHP

README!

CHANGELOG%

LICENSE&

Library Publisher What’s in your library?

Page 34: Composer the right way - NomadPHP

README!

CHANGELOG%

LICENSE&

Library Publisher What’s in your library?

' What problem does it solve?' Usage examples' Install instructions' How can I contribute?

Page 35: Composer the right way - NomadPHP

README!

CHANGELOG%

LICENSE&

Library Publisher What’s in your library?

' List relevant changes' Make BC breaks prominent' Show examples of how to upgrade

' What problem does it solve?' Usage examples' Install instructions' How can I contribute?

Page 36: Composer the right way - NomadPHP

README!

CHANGELOG%

LICENSE&

Library Publisher What’s in your library?

' List relevant changes' Make BC breaks prominent' Show examples of how to upgrade

' Pick one that reflects your values' choosealicense.com can help

' What problem does it solve?' Usage examples' Install instructions' How can I contribute?

Page 37: Composer the right way - NomadPHP

Library Publisher Semantic Versioning

1 . 2 3.major minor patch

Page 38: Composer the right way - NomadPHP

Library Publisher Semantic Versioning

1 . 2 3.major minor patch

Bug Fixes

Page 39: Composer the right way - NomadPHP

Library Publisher Semantic Versioning

1 . 2 3.major minor patch

New Features Bug Fixes

Page 40: Composer the right way - NomadPHP

Library Publisher Semantic Versioning

1 . 2 3.major minor patch

API / BC Breaks New Features Bug Fixes

Page 41: Composer the right way - NomadPHP

Library Publisher Tagging

Tag it and Bag it

Page 42: Composer the right way - NomadPHP

Library Publisher Tagging

# Simple Tag$ git tag v1.2.3

# Annotated Tag $ git tag -a v1.2.3 -m “Description of Release"

Page 43: Composer the right way - NomadPHP

Library Publisher “I'm out"

photo: jilliancorinne

Page 44: Composer the right way - NomadPHP

Library Publisher “I'm out"

Page 45: Composer the right way - NomadPHP

Library Publisher “I'm out"

Click here and provide another

Page 46: Composer the right way - NomadPHP

Library Publisher “I'm out"

Page 47: Composer the right way - NomadPHP

Library Publisher “I'm out"

Page 48: Composer the right way - NomadPHP

Pick the correct version

Library Publisher Pick a Version

Page 49: Composer the right way - NomadPHP

*the asteriskLibrary Publisher Pick a Version

Page 50: Composer the right way - NomadPHP

*the asterisk○Library Publisher Pick a Version

Page 51: Composer the right way - NomadPHP

~the tilde

Library Publisher Pick a Version

Page 52: Composer the right way - NomadPHP

~1.2>=1.2.0, <2.0.0

Library Publisher Pick a Version

Page 53: Composer the right way - NomadPHP

~1.2>=1.2.0, <2.0.0

Library Publisher Pick a Version

)

Page 54: Composer the right way - NomadPHP

~1.2.3>=1.2.3, <1.3

Library Publisher Pick a Version

Page 55: Composer the right way - NomadPHP

~1.2.3>=1.2.3, <1.3

Library Publisher Pick a Version

)

Page 56: Composer the right way - NomadPHP

"require": { "zendframework/zend-stdlib": “2.1.*”, "zendframework/zend-servicemanager": "2.1.*",},

“require-dev": { “phpunit/phpunit": “~3.7”}

Library Publisher Pick a Version

"require": { "zendframework/zend-stdlib": “~2.3”, "zendframework/zend-servicemanager": “~2.3",},

“require-dev": { “phpunit/phpunit": “~4”}

3rd party library

Your application

Page 57: Composer the right way - NomadPHP

"require": { "zendframework/zend-stdlib": “2.1.*”, "zendframework/zend-servicemanager": "2.1.*",},

“require-dev": { “phpunit/phpunit": “~3.7”}

Library Publisher Pick a Version

"require": { "zendframework/zend-stdlib": “~2.3”, "zendframework/zend-servicemanager": “~2.3",},

“require-dev": { “phpunit/phpunit": “~4”}

3rd party library

Your application

*

Page 58: Composer the right way - NomadPHP

"require": { "zendframework/zend-stdlib": “2.1.*”, "zendframework/zend-servicemanager": "2.1.*",},

“require-dev": { “phpunit/phpunit": “~3.7”}

Library Publisher Pick a Version

"require": { "zendframework/zend-stdlib": “~2.3”, "zendframework/zend-servicemanager": “~2.3",},

“require-dev": { “phpunit/phpunit": “~4”}

3rd party library

Your application

*

Page 59: Composer the right way - NomadPHP

"require": { "zendframework/zend-stdlib": “2.1.*”, "zendframework/zend-servicemanager": "2.1.*",},

“require-dev": { “phpunit/phpunit": “~3.7”}

Library Publisher Pick a Version

"require": { "zendframework/zend-stdlib": “~2.3”, "zendframework/zend-servicemanager": “~2.3",},

“require-dev": { “phpunit/phpunit": “~4”}

3rd party library

Your application

*

~2.1

Page 60: Composer the right way - NomadPHP

Yo @rdohms, I’m really happy for you and

I’m gonna let you finish, but the tilde operator is

totally old news.

Page 61: Composer the right way - NomadPHP

^the caretLibrary Publisher Pick a Version

Page 62: Composer the right way - NomadPHP

1.2.3>=1.2.3, <2.0.0

Library Publisher Pick a Version

^

Page 63: Composer the right way - NomadPHP

1.2.3>=1.2.3, <2.0.0

Library Publisher Pick a Version

)

^)

Page 64: Composer the right way - NomadPHP

0.3.0>=0.3.0, <0.4.0

Library Publisher Pick a Version

^

Page 65: Composer the right way - NomadPHP

0.3.0>=0.3.0, <0.4.0

Library Publisher Pick a Version

^)

Page 66: Composer the right way - NomadPHP

0.3.0>=0.3.0, <0.4.0

Library Publisher Pick a Version

^)

Major Version Zero

Page 67: Composer the right way - NomadPHP

Library ConsumersComposer for

Page 68: Composer the right way - NomadPHP

Library Consumer Install or update?

install or update?

Page 69: Composer the right way - NomadPHP

Library Consumer Install or update?

Make sure you have installed the last updates from other developers.

?

install updateor

Page 70: Composer the right way - NomadPHP

Library Consumer Install or update?

Make sure you have installed the last updates from other developers.

?

install updateor

Page 71: Composer the right way - NomadPHP

Library Consumer Install or update?

Deploying a new release of your application to production.

?

install updateor

Page 72: Composer the right way - NomadPHP

Library Consumer Install or update?

Deploying a new release of your application to production.

?

install updateor

Page 73: Composer the right way - NomadPHP

Library Consumer Install or update?

Checked out a new project and want to start coding.

?

install updateor

Page 74: Composer the right way - NomadPHP

Library Consumer Install or update?

Checked out a new project and want to start coding.

?

install updateor

Page 75: Composer the right way - NomadPHP

Library Consumer Install or update?

Grab new versions for the dependencies of your project.

?

install updateor

Page 76: Composer the right way - NomadPHP

Library Consumer Install or update?

Grab new versions for the dependencies of your project.

?

install updateor

Page 77: Composer the right way - NomadPHP

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

composer installcomposer update

Page 78: Composer the right way - NomadPHP

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

read

composer installcomposer update

Page 79: Composer the right way - NomadPHP

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

read grab version

composer installcomposer update

Page 80: Composer the right way - NomadPHP

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

read grab version

check latest compatible release

composer installcomposer update

Page 81: Composer the right way - NomadPHP

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

read grab version

check latest compatible release

update

composer installcomposer update

Page 82: Composer the right way - NomadPHP

Library Consumer Install or update?

commit your lock file

Page 83: Composer the right way - NomadPHP

Library Consumer Install or update?

$ composer update --lock

Tip

Page 84: Composer the right way - NomadPHP

Pick the correct version

Library Consumer Version Selection

Page 85: Composer the right way - NomadPHP

Library Consumer Version Selection

dev-master

Page 86: Composer the right way - NomadPHP

Library Consumer Version Selection

Page 87: Composer the right way - NomadPHP

Library Consumer Version Selection

Page 88: Composer the right way - NomadPHP

Library Consumer Using forks

found a bug?

Page 89: Composer the right way - NomadPHP

Library Consumer Using forks

$ composer install --prefer-source

Tip

Page 90: Composer the right way - NomadPHP

Library Consumer Using forks

Page 91: Composer the right way - NomadPHP

Library Consumer Using forks

patch it,

Page 92: Composer the right way - NomadPHP

Library Consumer Using forks

patch it,fork it,

Page 93: Composer the right way - NomadPHP

Library Consumer Using forks

patch it,fork it,

push it…

Page 94: Composer the right way - NomadPHP

Library Consumer Using forks

patch it,fork it,

push it…wait for it.

Page 95: Composer the right way - NomadPHP

Library Consumer Using forks

patch it,fork it,

push it…wait for it.

Page 96: Composer the right way - NomadPHP

Library Consumer Using forks

symfony/symfony

Page 97: Composer the right way - NomadPHP

Library Consumer Using forks

symfony/symfony

rdohms/symfony

Page 98: Composer the right way - NomadPHP

Library Consumer Using forks

symfony/symfony

rdohms/symfony

"repositories": [ { "type": "vcs", "url": "https://github.com/rdohms/symfony" } ]

Page 99: Composer the right way - NomadPHP

Library Consumer Using forks

symfony/symfony

rdohms/symfony

"repositories": [ { "type": "vcs", "url": "https://github.com/rdohms/symfony" } ]

+

Page 100: Composer the right way - NomadPHP

Library Consumer Using forks

Do not put forked repositories

on packagist

,

Page 101: Composer the right way - NomadPHP

Library Consumer Using forks

"require": { "symfony/symfony": "dev-my-patch as 2.5.0"}

Tip

Page 102: Composer the right way - NomadPHP

Library Consumer Composer and deployments

Composer and

production

Page 103: Composer the right way - NomadPHP

Library Consumer Composer and deployments

Production Server

-

Packagist

.

Page 104: Composer the right way - NomadPHP

Library Consumer Composer and deployments

Production Server

-

Packagist

.

/ Man in the middle

Page 105: Composer the right way - NomadPHP

Library Consumer Composer and deployments

Build Server

0

Production Server

-

"

Packagist

.

/ Man in the middle

Page 106: Composer the right way - NomadPHP

Library Consumer Composer and deployments

$ composer install --prefer-dist --no-dev —optimize-autoloader

,

Page 107: Composer the right way - NomadPHP

Library Consumer Composer and deployments

$ composer install --prefer-dist --no-dev —optimize-autoloader

,

Page 108: Composer the right way - NomadPHP

Library Consumer Composer and deployments

$ composer install --prefer-dist --no-dev —optimize-autoloader

,

1 Install same versions

1 Uses information defined in the composer.lock file

Page 109: Composer the right way - NomadPHP

Library Consumer Composer and deployments

$ composer install --prefer-dist --no-dev —optimize-autoloader

,

Page 110: Composer the right way - NomadPHP

Library Consumer Composer and deployments

$ composer install --prefer-dist --no-dev —optimize-autoloader

,

1 Downloads distribution packages

1 Can use local cache for previously downloaded

1 No git required

Page 111: Composer the right way - NomadPHP

Library Consumer Composer and deployments

$ composer install --prefer-dist --no-dev —optimize-autoloader

,

Page 112: Composer the right way - NomadPHP

Library Consumer Composer and deployments

$ composer install --prefer-dist --no-dev —optimize-autoloader

,

1 Avoids download unnecessary developer libraries

Page 113: Composer the right way - NomadPHP

Library Consumer Composer and deployments

$ composer install --prefer-dist --no-dev —optimize-autoloader

,

Page 114: Composer the right way - NomadPHP

Library Consumer Composer and deployments

$ composer install --prefer-dist --no-dev —optimize-autoloader

,

1 Generates classmap from PSR-0/4 autoloaders

1 Speeds up autoloading

Page 115: Composer the right way - NomadPHP

Library Consumer Licensing

$ composer licenses

Name: __root__Version: 1.0.0Licenses: noneDependencies:

doctrine/annotations v1.2.1 MIT doctrine/cache v1.3.1 MIT doctrine/collections v1.2 MIT doctrine/common v2.4.2 MIT doctrine/inflector v1.0 MIT doctrine/lexer v1.0 MIT psr/log 1.0.0 MIT symfony/symfony v2.5.6 MIT twig/twig v1.16.2 BSD-3-Clause

Tip

Page 116: Composer the right way - NomadPHP

Library Consumer Private Packages and Proxy

Satis and Toran

Page 117: Composer the right way - NomadPHP

composer Packagist

"

Your application

$

Public Repository

#

Library Consumer Private Packages and Proxy

Page 118: Composer the right way - NomadPHP

composer

Packagist

"

Your application

$

Public Repository

#

Satis / Toran

"

Private Repository

2

proxy

Library Consumer Private Packages and Proxy

Page 119: Composer the right way - NomadPHP

Library Consumer Private Packages and Proxy

toranproxy.comprivate repos, automatic packagist proxy

and support composer development

Page 120: Composer the right way - NomadPHP

Library Consumer Tooling

$ composer require jquery/jquery

How many of you?

Page 121: Composer the right way - NomadPHP

Library Consumer Tooling

Page 122: Composer the right way - NomadPHP

Library Consumer Tooling

Page 123: Composer the right way - NomadPHP

Javascript only Developer

Library Consumer Tooling

3 my-js-library

4

Page 124: Composer the right way - NomadPHP

Javascript only Developer

Library Consumer Tooling

3 my-js-library! package.json

4

Page 125: Composer the right way - NomadPHP

Javascript only Developer

Library Consumer Tooling

3 my-js-library! package.json

! bower.json

4

Page 126: Composer the right way - NomadPHP

Javascript only Developer

Library Consumer Tooling

3 my-js-library

! composer.json

! package.json

! bower.json

4

Page 127: Composer the right way - NomadPHP

Javascript only Developer

Library Consumer Tooling

3 my-js-library

! composer.json

! package.json

! bower.json

! .gemspec

4

/

/

Page 128: Composer the right way - NomadPHP

Library Consumer Tooling

Page 129: Composer the right way - NomadPHP

Library Consumer Tooling

Right tool.Right job.

Page 130: Composer the right way - NomadPHP

Library Consumer One last thing

One last thing…

Page 131: Composer the right way - NomadPHP

Library Consumer pickle!

Page 132: Composer the right way - NomadPHP

Library Consumer pickle!

$ pickle install memcache

https://wiki.php.net/rfc/picklehttps://github.com/FriendsOfPHP/pickle

Page 133: Composer the right way - NomadPHP

Thank you.

https://joind.in/14092

https://leanpub.com/composer-cookbook

Page 134: Composer the right way - NomadPHP

Thank you.any questions?

5 http://slides.doh.ms

6 http://doh.ms

7 @rdohms

https://joind.in/14092

https://leanpub.com/composer-cookbook