SlideShare une entreprise Scribd logo
1  sur  25
Télécharger pour lire hors ligne
Composer: Dependency
Manager for PHP
Guillermo A. Fisher
What is a Dependency?
A dependency is a library of code that your
project needs in order to function.
What is a Dependency?
<?php
// Your project needs the “HelloWorld” library
require ‘/path/to/HelloWorld.php’;
// Now that we have the code, we can say hi!
$greeter = new HelloWorld();
$greeter->sayHello();
What is a Dependency?
The project in the example is dependent upon
the “HelloWorld” library.
Dependency Dependencies
Sometimes your dependencies will have their
own dependencies.
Dependency Dependencies
<?php
// “HelloWorld” needs the “Hello” library
require ‘/path/to/Hello.php’;
class HelloWorld extends Hello
{
…
}
Managing Dependencies
● What libraries am I using?
● What versions of those libraries am I using?
● What libraries do my libraries need?
● What versions of those libraries do my
libraries need?
● Where can I find those libraries?
Managing Dependencies
Dependency Managers
● Maven for Java
● bundler for Ruby
● npm for Node.js
PHP Dependency Managers
Composer - http://getcomposer.org
Use when managing dependencies for a
single project
PEAR - http://pear.php.net
Use when managing dependencies for PHP
on your system (multiple projects)
What is Composer?
“Composer is a tool for dependency
management in PHP. It allows you to declare
the dependent libraries your project needs and
it will install them in your project for you.”
Why Composer?
● You have a project that depends on a
number of libraries.
● Some of those libraries depend on other
libraries.
● You declare the things you depend on.
● Composer finds out which versions of which
packages need to be installed and installs
them.
Download Composer
● Need PHP 5.3.2+
● Download Composer
● For information about installing on your OS,
visit http://getcomposer.org/download
Get Started Using Composer
$ cd myproject
$ curl -sS https://getcomposer.org/installer |
php
$ vi composer.json
$ php composer.phar install
Declaring Dependencies
Project dependencies are declared in a
composer.json file.
Declaring Dependencies
Your project depends on “monolog” (http://bit.
ly/1bjz17Z) to log information.
$log = new MonologLogger(‘name’);
$log->pushHandler(new
MonologHandlerStreamHandler(‘app.log’,
MonologLogger::WARNING));
$log->addWarning(‘Foo’);
composer.json
{
“require”: {
“monolog/monolog”: “1.0.*”
}
}
composer.json : require
The require key tells Composer which
packages your project depends on.
composer.json : require
“Package names are mapped to package
versions.”
// “vendor/project”: “version”
“monolog/monolog”: “1.0.*”
Packagist
“Packagist (http://packagist.org) is the main
Composer repository. A Composer
repository is basically a package source: a
place where you can get packages from.”
Autoloading
“Composer generates a vendor/autoload.php file.
You can simply include this file and you will get
autoloading for free.”
composer.lock
“After installing the dependencies, Composer
writes the list of the exact versions it installed
into a composer.lock file. This locks the project to
those specific versions… Commit your
application’s composer.lock (along with composer.
json) into version control.”
Updating Dependencies
New versions of your project’s dependencies
will more than likely be released. “To update to
the new version, use [the] update command.
This will fetch the latest matching versions
(according to your composer.json file) and also
update the lock file with the new version.”
Updating Dependencies
$ php composer.phar update
References
Composer
http://getcomposer.org
Packagist
http://packagist.org
PHP The Right Way
http://phptherightway.com

Contenu connexe

Tendances

Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 
Building a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQueryBuilding a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 

Tendances (20)

Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budget
 
Alamofire
AlamofireAlamofire
Alamofire
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
 
Ruby On Grape
Ruby On GrapeRuby On Grape
Ruby On Grape
 
A Deeper Look at Cargo
A Deeper Look at CargoA Deeper Look at Cargo
A Deeper Look at Cargo
 
Writing multi-language documentation using Sphinx
Writing multi-language documentation using SphinxWriting multi-language documentation using Sphinx
Writing multi-language documentation using Sphinx
 
Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?Composer - Package Management for PHP. Silver Bullet?
Composer - Package Management for PHP. Silver Bullet?
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
WTF Is Rancher?
WTF Is Rancher?WTF Is Rancher?
WTF Is Rancher?
 
Scaling up development of a modular code base
Scaling up development of a modular code baseScaling up development of a modular code base
Scaling up development of a modular code base
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)Vagrant for real (codemotion rome 2016)
Vagrant for real (codemotion rome 2016)
 
Introduction to chef framework
Introduction to chef frameworkIntroduction to chef framework
Introduction to chef framework
 
Travis CI - PHP
Travis CI - PHPTravis CI - PHP
Travis CI - PHP
 
SDKMAN!
SDKMAN!SDKMAN!
SDKMAN!
 
Building a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQueryBuilding a desktop app with HTTP::Engine, SQLite and jQuery
Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Cocoa pods
Cocoa podsCocoa pods
Cocoa pods
 
Haibu: dev deployment is fast and easy again
Haibu: dev deployment is fast and easy againHaibu: dev deployment is fast and easy again
Haibu: dev deployment is fast and easy again
 

Similaire à Composer: Dependency Manager for PHP

Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with Composer
Jason Grimes
 

Similaire à Composer: Dependency Manager for PHP (20)

Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning Talk
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
Php Dependency Management with Composer ZendCon 2017
Php Dependency Management with Composer ZendCon 2017Php Dependency Management with Composer ZendCon 2017
Php Dependency Management with Composer ZendCon 2017
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with Composer
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupal
 
Composer
ComposerComposer
Composer
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
Composer
ComposerComposer
Composer
 
Composer
ComposerComposer
Composer
 
Composer Best Practices
Composer Best PracticesComposer Best Practices
Composer Best Practices
 
Composer Best Practices
Composer Best PracticesComposer Best Practices
Composer Best Practices
 
Composer Best Practices.pdf
Composer Best Practices.pdfComposer Best Practices.pdf
Composer Best Practices.pdf
 
Composer - The missing package manager for PHP
Composer - The missing package manager for PHPComposer - The missing package manager for PHP
Composer - The missing package manager for PHP
 
PHP
PHPPHP
PHP
 
Composer
ComposerComposer
Composer
 
Composer intro
Composer introComposer intro
Composer intro
 
12 Composer #burningkeyboards
12 Composer #burningkeyboards12 Composer #burningkeyboards
12 Composer #burningkeyboards
 
Mastering composer
Mastering composerMastering composer
Mastering composer
 
Composer
ComposerComposer
Composer
 
Using Composer to create manageable WordPress websites
Using Composer to create manageable WordPress websitesUsing Composer to create manageable WordPress websites
Using Composer to create manageable WordPress websites
 

Dernier

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Dernier (20)

WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 

Composer: Dependency Manager for PHP