composer the right way

Post on 02-Jul-2015

3.111 Views

Category:

Engineering

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

Composer has triggered a renaissance in the PHP community, it has changed the way we deal with other people’s code and it has changed the way we share our code. We are all slowly moving to using Composer, from Wordpress to Joomla and Drupal and frameworks in between. But many of us mistreat composer, follow outdated practices or simply lack a few tricks. In this session i’ll get you the low down on how to use composer the right way.

TRANSCRIPT

Composerthe right way

@rdohmsRafael Dohms

photo: smileymanwithahat

photo: Rob Allen

The Composer Cookbookhttps://leanpub.com/composer-cookbook

photo: 18millionpixels

Library Publisher

photo: 18millionpixels

Library Publisher

Library Consumer

photo: 18millionpixels

Library Publisher

Library

Library Consumer

photo: 18millionpixels

Library Publisher

Library

Library Consumer

Packagist

photo: 18millionpixels

photo: 18millionpixels

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

photo: 18millionpixels

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

{ "name": “monolog/monolog” ...}

photo: 18millionpixels

{ "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

{ "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

{ "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

composer

composercomposer.json!

composercomposer.json!

composer.lock!

composercomposer.json!

composer.lock!

discovery Packagist

"

composercomposer.json!

composer.lock!

discovery sourcePackagist

"

Repository

#

composercomposer.json!

composer.lock!

discovery source

installation

Packagist

"

Vendor Folder

$

Repository

#

composercomposer.json!

composer.lock!

$ composer init

Library Publisher

$ composer init

Library Publisher

$ composer require <vendor>/<package>

Library Consumer

$ composer require monolog/monologUsing version ~1.11 for monolog/monolog

Tip

Library PublishersComposer for

Library Publisher Unique vendor names

vendor / package

Library Publisher Unique vendor names

pick your own unique vendor

Library Publisher Unique vendor names

or join a collective

README!

CHANGELOG%

LICENSE&

Library Publisher What’s in your library?

README!

CHANGELOG%

LICENSE&

Library Publisher What’s in your library?

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

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?

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?

Library Publisher Semantic Versioning

1 . 2 3.major minor patch

Library Publisher Semantic Versioning

1 . 2 3.major minor patch

Bug Fixes

Library Publisher Semantic Versioning

1 . 2 3.major minor patch

New Features Bug Fixes

Library Publisher Semantic Versioning

1 . 2 3.major minor patch

API / BC Breaks New Features Bug Fixes

Library Publisher Tagging

Tag it and Bag it

Library Publisher Tagging

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

Library Publisher “I'm out"

photo: jilliancorinne

Library Publisher “I'm out"

Library Publisher “I'm out"

Click here and provide another

Library Publisher “I'm out"

Library Publisher “I'm out"

coming soon

Pick the correct version

Library Publisher Pick a Version

*the asteriskLibrary Publisher Pick a Version

*the asterisk○Library Publisher Pick a Version

~the tilde

Library Publisher Pick a Version

~1.2>=1.2.0, <2.0.0

Library Publisher Pick a Version

~1.2>=1.2.0, <2.0.0

Library Publisher Pick a Version

)

~1.2.3>=1.2.0, <1.3

Library Publisher Pick a Version

~1.2.3>=1.2.0, <1.3

Library Publisher Pick a Version

)

"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

"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

*

"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

*

"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

Library ConsumersComposer for

Library Consumer Install or update?

install or update?

Library Consumer Install or update?

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

?

install updateor

Library Consumer Install or update?

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

?

install updateor

Library Consumer Install or update?

Deploying a new release of your application to production.

?

install updateor

Library Consumer Install or update?

Deploying a new release of your application to production.

?

install updateor

Library Consumer Install or update?

Checked out a new project and want to start coding.

?

install updateor

Library Consumer Install or update?

Checked out a new project and want to start coding.

?

install updateor

Library Consumer Install or update?

Grab new versions for the dependencies of your project.

?

install updateor

Library Consumer Install or update?

Grab new versions for the dependencies of your project.

?

install updateor

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

composer installcomposer update

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

read

composer installcomposer update

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

read grab version

composer installcomposer update

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

read grab version

check latest compatible release

composer installcomposer update

Your application

$

Public Repository

#

Library Consumer Install or update?

composer.lock!

read grab version

check latest compatible release

update

composer installcomposer update

Library Consumer Install or update?

commit your lock file

Library Consumer Install or update?

$ composer update --lock

Tip

Pick the correct version

Library Consumer Version Selection

Library Consumer Version Selection

dev-master

Library Consumer Version Selection

Library Consumer Version Selection

Library Consumer Using forks

found a bug?

Library Consumer Using forks

$ composer install --prefer-source

Tip

Library Consumer Using forks

Library Consumer Using forks

patch it,

Library Consumer Using forks

patch it,fork it,

Library Consumer Using forks

patch it,fork it,

push it…

Library Consumer Using forks

patch it,fork it,

push it…wait for it.

Library Consumer Using forks

patch it,fork it,

push it…wait for it.

Library Consumer Using forks

symfony/symfony

Library Consumer Using forks

symfony/symfony

rdohms/symfony

Library Consumer Using forks

symfony/symfony

rdohms/symfony

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

Library Consumer Using forks

symfony/symfony

rdohms/symfony

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

+

Library Consumer Using forks

$ composer show -v symfony/symfony

Tip

Library Consumer Using forks

Do not put forked repositories

on packagist

,

Library Consumer Using forks

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

Tip

Library Consumer Composer and deployments

Composer and

production

Library Consumer Composer and deployments

Production Server

-

Packagist

.

Library Consumer Composer and deployments

Production Server

-

Packagist

.

/ Man in the middle

Library Consumer Composer and deployments

Build Server

0

Production Server

-

"

Packagist

.

/ Man in the middle

Library Consumer Composer and deployments

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

,

Library Consumer Composer and deployments

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

,

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

Library Consumer Composer and deployments

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

,

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

Library Consumer Composer and deployments

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

,

Library Consumer Composer and deployments

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

,

1 Avoids download unnecessary developer libraries

Library Consumer Composer and deployments

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

,

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

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

Library Consumer Private Packages and Proxy

Satis and Toran

composer Packagist

"

Your application

$

Public Repository

#

Library Consumer Private Packages and Proxy

composer

Packagist

"

Your application

$

Public Repository

#

Satis / Toran

"

Private Repository

2

proxy

Library Consumer Private Packages and Proxy

Library Consumer Private Packages and Proxy

toranproxy.comprivate repos, automatic packagist proxy

and support composer development

Library Consumer Tooling

$ composer require jquery/jquery

How many of you?

Library Consumer Tooling

Library Consumer Tooling

Javascript only Developer

Library Consumer Tooling

3 my-js-library

4

Javascript only Developer

Library Consumer Tooling

3 my-js-library! package.json

4

Javascript only Developer

Library Consumer Tooling

3 my-js-library! package.json

! bower.json

4

Javascript only Developer

Library Consumer Tooling

3 my-js-library

! composer.json

! package.json

! bower.json

4

Javascript only Developer

Library Consumer Tooling

3 my-js-library

! composer.json

! package.json

! bower.json

! .gemspec

4

Javascript only Developer

Library Consumer Tooling

3 my-js-library

! composer.json

! package.json

! bower.json

! .gemspec

4

/

/

Library Consumer Tooling

Library Consumer Tooling

Right tool.Right job.

Library Consumer One last thing

One last thing…

Library Consumer pickle!

Library Consumer pickle!

$ pickle install memcache

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

Thank you.

https://joind.in/11878

Thank you.any questions?

5 http://slides.doh.ms

6 http://doh.ms

7 @rdohms

https://joind.in/11878

top related