Composer

Post on 17-Dec-2014

360 views 1 download

description

Presentazione di composer per l'incontro del PHP User Group Milano del 16 ottobre 2012

Transcript of Composer

COMPOSERE le dipendenze non sono più un problema

#pugMi16/10/2012

martedì 16 ottobre 12

martedì 16 ottobre 12

Esiste già PEAR!

martedì 16 ottobre 12

Esiste già PEAR!

★ installazione poco pulita

martedì 16 ottobre 12

Esiste già PEAR!

★ installazione poco pulita

★ canali sparsi

martedì 16 ottobre 12

Esiste già PEAR!

★ installazione poco pulita

★ canali sparsi

★ standard troppo restrittivi

martedì 16 ottobre 12

Vantaggi di composer

martedì 16 ottobre 12

Vantaggi di composer★ installazione legata al

progetto

martedì 16 ottobre 12

Vantaggi di composer★ installazione legata al

progetto

★ repository centrali

martedì 16 ottobre 12

Vantaggi di composer★ installazione legata al

progetto

★ repository centrali

★ non esiste processo di approvazione

martedì 16 ottobre 12

Vantaggi di composer★ installazione legata al

progetto

★ repository centrali

★ non esiste processo di approvazione

★ tutte le dipendenze sono gestite da un unico file

martedì 16 ottobre 12

Vantaggi di composer★ installazione legata al

progetto

★ repository centrali

★ non esiste processo di approvazione

★ tutte le dipendenze sono gestite da un unico file

★ composer.lock

martedì 16 ottobre 12

Problema

martedì 16 ottobre 12

ProblemaHo bisogno di gestire delle versioni specifiche

delle librerie che utilizza il mio progetto.

martedì 16 ottobre 12

ProblemaHo bisogno di gestire delle versioni specifiche

delle librerie che utilizza il mio progetto.

Ho bisogno di condividerle con i miei colleghi,con l’ambiente di sviluppo e quello di produzione.

martedì 16 ottobre 12

ProblemaHo bisogno di gestire delle versioni specifiche

delle librerie che utilizza il mio progetto.

Ho bisogno di condividerle con i miei colleghi,con l’ambiente di sviluppo e quello di produzione.

COMPOSER!

martedì 16 ottobre 12

composer

martedì 16 ottobre 12

composer

Composer è un gestore di dipendenze per progettoche permette di specificare le versioni specifiche

delle librerie utilizzate.

martedì 16 ottobre 12

composer

Composer è un gestore di dipendenze per progettoche permette di specificare le versioni specifiche

delle librerie utilizzate.

In senso opposto, permette di distribuire le mie librerie attraverseo packagist.com e di

non preoccuparmi delle dipendenze.

martedì 16 ottobre 12

martedì 16 ottobre 12

Installazione

martedì 16 ottobre 12

Installazione

$ curl -s http://getcomposer.org/installer | php

martedì 16 ottobre 12

Installazione

$ curl -s http://getcomposer.org/installer | php

$ curl -s http://getcomposer.org/installer | php -- --install-dir=bin

martedì 16 ottobre 12

Installazione

$ curl -s http://getcomposer.org/installer | php

$ curl -s http://getcomposer.org/installer | php -- --install-dir=bin

$ composer.phar self-update

martedì 16 ottobre 12

composer.json

martedì 16 ottobre 12

composer.json{ "require": { "silex/silex": "1.0.*" },

"minimum-stability": "dev"}

martedì 16 ottobre 12

composer.json{ "require": { "silex/silex": "1.0.*" },

"minimum-stability": "dev"}

Root del progetto

martedì 16 ottobre 12

composer.json{ "require": { "silex/silex": "1.0.*" },

"minimum-stability": "dev"}

Root del progetto Require

martedì 16 ottobre 12

composer.json{ "require": { "silex/silex": "1.0.*" },

"minimum-stability": "dev"}

Root del progetto Require Minimum stability

martedì 16 ottobre 12

martedì 16 ottobre 12

Bootstrap progetto

martedì 16 ottobre 12

Bootstrap progetto

$ composer.phar create-project fabpot/silex-skeleton ~/dev/myproject

martedì 16 ottobre 12

Bootstrap progetto

$ composer.phar create-project fabpot/silex-skeleton ~/dev/myproject

TIP: possiamo creare un progetto, eliminare le librerie che non ci servono da composer.json e rilanciare$ php composer.phar update

martedì 16 ottobre 12

Contribuire a un progetto

martedì 16 ottobre 12

Contribuire a un progetto

$ composer.phar create-project dms/dms --dev ~/dev/oss/dms

martedì 16 ottobre 12

Contribuire a un progetto

$ composer.phar create-project dms/dms --dev ~/dev/oss/dms

Tramite l’opzione --dev il sistema scarica anche le librerie necessarie per contribuire ad un progetto

martedì 16 ottobre 12

autoload.php

martedì 16 ottobre 12

autoload.php

Composer genererà un file per il loading di tutte le tue librerie

martedì 16 ottobre 12

autoload.php

Composer genererà un file per il loading di tutte le tue librerie

vendor/autoload.php

martedì 16 ottobre 12

composer everyday

martedì 16 ottobre 12

composer everyday

composer.json

martedì 16 ottobre 12

composer everyday

Lista delle dipendenzecomposer.json

martedì 16 ottobre 12

composer everyday

Lista delle dipendenzecomposer.json

composer.lock

martedì 16 ottobre 12

composer everyday

Lista delle dipendenzecomposer.json

Dipendenze esistenticomposer.lock

martedì 16 ottobre 12

UPDATE

martedì 16 ottobre 12

UPDATE

★ lettura di composer.json

martedì 16 ottobre 12

UPDATE

★ lettura di composer.json

★ download delle librerie necessarie

martedì 16 ottobre 12

UPDATE

★ lettura di composer.json

★ download delle librerie necessarie

★ scrittura del file composer.lock

martedì 16 ottobre 12

INSTALL

martedì 16 ottobre 12

INSTALL

★ lettura di composer.json

martedì 16 ottobre 12

INSTALL

★ lettura di composer.json

★ controllo del file composer.lock

martedì 16 ottobre 12

INSTALL

★ lettura di composer.json

★ controllo del file composer.lock

★ recupero delle versioni “lockate”

martedì 16 ottobre 12

martedì 16 ottobre 12

composer.lock in versioning

martedì 16 ottobre 12

composer.lock

composer.lock in versioning

martedì 16 ottobre 12

composer.lock

composer install

composer.lock in versioning

martedì 16 ottobre 12

composer.lock

composer install

composer.lock in versioning

Certezza di avere tutti i sistemi allineati

martedì 16 ottobre 12

martedì 16 ottobre 12

{ "repositories": [ { "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "http://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" }, "source": { "url": "http://smarty-php.googlecode.com/svn/", "type": "svn", "reference": "tags/Smarty_3_1_7/distribution/" } } } ]}

N!.-C!"p#$r P'*4'/$

martedì 16 ottobre 12

{ "repositories": [ { "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "http://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" }, "source": { "url": "http://smarty-php.googlecode.com/svn/", "type": "svn", "reference": "tags/Smarty_3_1_7/distribution/" } } } ]}

“package”: on-the-fly package, injecting a composer.json

N!.-C!"p#$r P'*4'/$

martedì 16 ottobre 12

{ "repositories": [ { "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "http://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" }, "source": { "url": "http://smarty-php.googlecode.com/svn/", "type": "svn", "reference": "tags/Smarty_3_1_7/distribution/" } } } ]}

SVN / Git

“package”: on-the-fly package, injecting a composer.json

N!.-C!"p#$r P'*4'/$

martedì 16 ottobre 12

I .$$- (+)0 PEAR p'*4'/$...No Problem!

martedì 16 ottobre 12

{ "repositories": [ { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }}

martedì 16 ottobre 12

{ "repositories": [ { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }}

“pear”: official PEAR and custom PEAR channels

martedì 16 ottobre 12

{ "repositories": [ { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }}

“pear”: official PEAR and custom PEAR channels

Remember the prefix!

martedì 16 ottobre 12

{ "repositories": [ { "type": "pear", "url": "http://pear2.php.net" } ], "require": { "pear-pear2.php.net/PEAR2_Text_Markdown": "*", "pear-pear2/PEAR2_HTTP_Request": "*" }}

“pear”: official PEAR and custom PEAR channels

Remember the prefix!

Warning: PEAR causes a overhead of requests! !

martedì 16 ottobre 12

Script: composer eventmartedì 16 ottobre 12

martedì 16 ottobre 12

“oggi avrei voglia di qualcosa di buono...”

martedì 16 ottobre 12

packagist.orgmartedì 16 ottobre 12

martedì 16 ottobre 12

martedì 16 ottobre 12

martedì 16 ottobre 12

martedì 16 ottobre 12

$ composer.phar search filter

dms/dms-filter-bundle : DMS Filter Bundle, makes Annotation based ...lexik/form-filter-bundle : This bundle aim to provide classes to build...rollerworks/recordfilter-bundle : Record search-filtering bundle for Symfonybrikou/zend_filter : Zend Framework Filter Libraryext-filter : The filter PHP extensiondms/dms-filter : DMS Library, includes various bundles and ...shtumi/useful-bundle : Symfony ShtumiUsefulBundle

martedì 16 ottobre 12

martedì 16 ottobre 12

$ composer.phar show dms/dms-filter-bundle

name : dms/dms-filter-bundledescrip. : DMS Filter Bundle, makes Annotation based entity filtering availablein Symfonykeywords : symfony, bundle, filter, dmsversions : dev-master, v1.1.1, v1.1, 1.0.2, 1.0.1, 1.0.0type : symfony-bundlelicense : MITsource : [git] https://github.com/rdohms/DMSFilterBundle v1.1.1dist : [zip] https://github.com/rdohms/DMSFilterBundle/zipball/v1.1.1 v1.1.1names : dms/dms-filter-bundleautoload

psr-0

DMS\Bundle\FilterBundle => .requires

php >=5.3.2dms/dms-filter >=1.0.2

martedì 16 ottobre 12

martedì 16 ottobre 12

Compiti a casahttps://github.com/composer/satis

Satis - Package Repository Generator

Simple static Composer repository generator.

It uses any composer.json file as input and dumps all the required (according to their version constraints)

packages to a Composer Repository file.

martedì 16 ottobre 12