SlideShare a Scribd company logo
1 of 26
Download to read offline
Composer
Alessandro Minoccheri
Composer is a tool for dependency
management in PHP, is not a package
manager.
It allows you to declare the dependent
libraries your project needs and it will
install them in your project for you.
Composer What is composer?
What is composer?
How does it works?
• Install composer
• composer init
Composer How to start?
How to start?
• composer install
• composer update
• composer require vendor/package:1.1.*
• composer remove vendor/package
• composer update vendor/package
Composer How to start?
Basic commands
Don’t edit
composer.json
manually
Package version: x.y.z
• x: MAJOR version when you make incompatible API changes
• y: MINOR version when you add functionality in a backwards-
compatible manner
• z: PATCH version when you make backwards-compatible bug fixes
Composer Semantic versioning
Semantic versioning
• Exact version 2.3.1
• Version range >=1.0 <1.1 || >=1.2
• Tilde version range ~1.2.3 is equivalent to >=1.2.3 <1.3.0
• Caret version range ^1.2.3 is equivalent to >=1.2.3 <2.0.0
Composer Versions and constraints
Versions and constraints
Composer generate an autoload file for all your dependencies vendor/autoload.php

Now you can create a class inside app folder like Config.php and use this namespace: AppConfig

The base directory will be src/App/Config 

The resulting file path will be: ./src/App/Config/Config.php
Composer Autoload
Autoload
{
"autoload": {
"psr-4": { "App": "src/" }
},
"autoload-dev": {
"psr-4": { "AppTests": "tests/" }
}
}
A script, in Composer's
terms, can either be a
PHP callback (defined as
a static method) or any
command-line
executable command. 
Composer Scripts
Scripts
"scripts": {
"post-update-cmd": "MyVendor
MyClass::postUpdate",
"post-install-cmd": [
"MyVendorMyClass::warmCache",
"phpunit -c app/"
],
"post-create-project-cmd": [
"php -r "copy('config/local-
example.php', 'config/local.php');""
]
}
Composer Require
Require
{
"require": {
"php": "^7.1.1"
}
}
$ php -v
PHP 5.6.10
$ composer update
Your requirements could not be resolved
to an installable set of packages.
Problem 1
This package requires php ^7.1.1 but
your PHP version (5.6.10) does not
satisfy that requirement.
$ php -v
PHP 5.6.10
$ composer update
Success
Composer Platform requirements
Platform requirements
{
"require": {
"php": "^7.1.1"
},
"config": {
"platform": {
"php": "7.1.2"
}
}
}
• Minimum-stability field defines default stability flags: for example: dev,
alpha, beta, RC or stable
• -stable, -RC ecc… suffix specifies the stability
• If the stability is not specified, composer does it:

1.2.3 become = 1.2.3.0-stable

>1.2 become > 1.2.0.0-stable

>=1.2 become 1.2.0.0-dev

<1.3 become <1.3.0.0-dev
Composer Stability flags
Stability flags
When running composer install for the first time, or when
running composer update a lock file called composer.lock
will be created with the exact versions that are installed
so they can be re-installed.



composer.lock must be committed to keep all co-workers
in the same versions as you and to make deploy faster.
Composer Composer.lock
Composer.lock
To solve composer.lock conflicts you have different ways:
• Solve conflicts on .json file, accept your or another .lock and launch
composer install
• Solve conflicts on .json file, delete composer.lock file and launch
composer update
• Accept .json and .lock files from origin and re-apply your changes



The best solution is the last to be more safe.
Composer Composer.lock conflicts
Composer.lock conflicts
Composer install
vs update
• Check for composer.lock file
• If not, auto generate composer.lock file
(Using composer update)
• Install the specified versions recorded in
the composer.lock file
Composer Composer install vs update
Composer install
• Go through the composer.json file
• Check availability of newer (latest) versions, based
on the version criteria mentioned (e.g. 1.12.*)
• Install the latest possible (according to above)
versions
• Update composer.lock file with installed versions
Composer Composer install vs update
Composer update
• Use --prefer-dist to avoid git clones

Will always download zip files if possible
(default for stable versions)
• Store ~/.composer/cache between builds

How depends on CI product/setup you use
Composer Composer install vs update
Composer install performance
—optimize-autoloader

Class map generation essentially
converts PSR-4/PSR-0 rules into
classmap rules, performance increase
from 20% to 25%
Composer Composer install vs update
Autoloader optimization
composer install ——optimize-autoloader
composer install --classmap-authoritative
—classmap-authoritative 

If something is not found in the classmap,
then it does not exist and the autoloader
should not attempt to look on the
filesystem according to PSR-4 rules.
A git patch is a commit
converted into a file that
can be applied on a
different repository.



So if you have a pull request
not merged you can use the
PR as if it were merged.



Composer Patching with Composer
Patching with Composer
{
"require": {
"symfony/symfony": "4.1.0"
},
"config": {
"preferred-install": "source"
},
"extra": {
"patches": {
"symfony/symfony": {
"Something": “https://url.com/
foo.patch“
}
}
}
}
VCS stands for version
control system. This
includes versioning
systems like git, svn, fossil
or hg. Composer has a
repository type for
installing packages from
these systems.



Composer Use Private Package
Use Private Package
"require": {
"vendor/package": "dev-master"
},
“repositories”:[
{
“type”: “vcs”,
“url” :
“git@bitbucket.org:vendor/

package.git”
}
]
• Git: git-scm.com
• Subversion: subversion.apache.org
• Mercurial: mercurial-scm.org
• Fossil: fossil-scm.org
GitHub: github.com (Git)
BitBucket: bitbucket.org (Git and Mercurial)
Composer Git alternatives
Git alternatives
Packagist is the default
Composer package repository.
It lets you find packages and
lets Composer know where to
get the code from
Composer Packagist
Packagist
Put a file named composer.json at the root of your package's repository,
containing the at least a name of the package.



Commit the file to your git or other VCS repository.



Login or register on pakagist.org site, then hit the submit button in the
menu.
Once you entered your public repository URL in there, your package will
be automatically crawled periodically. 

You just have to make sure you keep the composer.json file up to date.
Composer Publishing a Package
Publishing a Package
Grazie.
Alessandro Minoccheri

Twitter: minompi

Github: AlessandroMinoccheri

Stackoverflow: Alessandro Minoccheri

More Related Content

What's hot

Continuous Delivery to Amazon ECS
Continuous Delivery to Amazon ECSContinuous Delivery to Amazon ECS
Continuous Delivery to Amazon ECSAmazon Web Services
 
London Community Summit - Habitat 2016
London Community Summit - Habitat 2016London Community Summit - Habitat 2016
London Community Summit - Habitat 2016Sarah Richards
 
[Jun AWS 201] Elastic Beanstalk for Startups
[Jun AWS 201] Elastic Beanstalk for Startups[Jun AWS 201] Elastic Beanstalk for Startups
[Jun AWS 201] Elastic Beanstalk for StartupsAmazon Web Services Korea
 
Lessons learned migrating 100+ services to Kubernetes
Lessons learned migrating 100+ services to KubernetesLessons learned migrating 100+ services to Kubernetes
Lessons learned migrating 100+ services to KubernetesJose Galarza
 
Spinnaker 파트 1
Spinnaker 파트 1Spinnaker 파트 1
Spinnaker 파트 1Steven Shim
 
Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020Anton Babenko
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele RialdiCodeFest
 
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + FlexWhat is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + FlexHaehnchen
 
Ansible Configuration Management Tool 소개 및 활용
Ansible Configuration Management Tool 소개 및 활용 Ansible Configuration Management Tool 소개 및 활용
Ansible Configuration Management Tool 소개 및 활용 Steven Shim
 
Amazon Web Services for the .NET Developer
Amazon Web Services for the .NET DeveloperAmazon Web Services for the .NET Developer
Amazon Web Services for the .NET DeveloperRob Gillen
 
Managing the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS LambdaManaging the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS LambdaAmazon Web Services
 
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020AWSKRUG - AWS한국사용자모임
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele RialdiCodeFest
 
Find your data - use GraphDB capabilities in XPages applications - and beyond
Find your data - use GraphDB capabilities in XPages applications - and beyond	Find your data - use GraphDB capabilities in XPages applications - and beyond
Find your data - use GraphDB capabilities in XPages applications - and beyond ICON UK EVENTS Limited
 
Servlets made easy. 
Write once and run everywhere.
Servlets made easy. 
Write once and run everywhere.Servlets made easy. 
Write once and run everywhere.
Servlets made easy. 
Write once and run everywhere.ICON UK EVENTS Limited
 
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...Corley S.r.l.
 
Modern Commandline Tool
Modern Commandline ToolModern Commandline Tool
Modern Commandline ToolYuji Shimada
 
Postman for Efficient Professional Services: Collaboration, Mocking Dependenc...
Postman for Efficient Professional Services: Collaboration, Mocking Dependenc...Postman for Efficient Professional Services: Collaboration, Mocking Dependenc...
Postman for Efficient Professional Services: Collaboration, Mocking Dependenc...Postman
 

What's hot (20)

Continuous Delivery to Amazon ECS
Continuous Delivery to Amazon ECSContinuous Delivery to Amazon ECS
Continuous Delivery to Amazon ECS
 
AWS elastic beanstalk
AWS elastic beanstalkAWS elastic beanstalk
AWS elastic beanstalk
 
London Community Summit - Habitat 2016
London Community Summit - Habitat 2016London Community Summit - Habitat 2016
London Community Summit - Habitat 2016
 
[Jun AWS 201] Elastic Beanstalk for Startups
[Jun AWS 201] Elastic Beanstalk for Startups[Jun AWS 201] Elastic Beanstalk for Startups
[Jun AWS 201] Elastic Beanstalk for Startups
 
Lessons learned migrating 100+ services to Kubernetes
Lessons learned migrating 100+ services to KubernetesLessons learned migrating 100+ services to Kubernetes
Lessons learned migrating 100+ services to Kubernetes
 
Spinnaker 파트 1
Spinnaker 파트 1Spinnaker 파트 1
Spinnaker 파트 1
 
Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + FlexWhat is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
What is new in Symfony 3,3, 3,4, 4.0, 4,1 + Flex
 
Ansible Configuration Management Tool 소개 및 활용
Ansible Configuration Management Tool 소개 및 활용 Ansible Configuration Management Tool 소개 및 활용
Ansible Configuration Management Tool 소개 및 활용
 
Amazon Web Services for the .NET Developer
Amazon Web Services for the .NET DeveloperAmazon Web Services for the .NET Developer
Amazon Web Services for the .NET Developer
 
Managing the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS LambdaManaging the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS Lambda
 
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
 
Raffaele Rialdi
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
 
Find your data - use GraphDB capabilities in XPages applications - and beyond
Find your data - use GraphDB capabilities in XPages applications - and beyond	Find your data - use GraphDB capabilities in XPages applications - and beyond
Find your data - use GraphDB capabilities in XPages applications - and beyond
 
Servlets made easy. 
Write once and run everywhere.
Servlets made easy. 
Write once and run everywhere.Servlets made easy. 
Write once and run everywhere.
Servlets made easy. 
Write once and run everywhere.
 
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour L...
 
Modern Commandline Tool
Modern Commandline ToolModern Commandline Tool
Modern Commandline Tool
 
.Net Core 1.0 vs .NET Framework
.Net Core 1.0 vs .NET Framework.Net Core 1.0 vs .NET Framework
.Net Core 1.0 vs .NET Framework
 
Postman for Efficient Professional Services: Collaboration, Mocking Dependenc...
Postman for Efficient Professional Services: Collaboration, Mocking Dependenc...Postman for Efficient Professional Services: Collaboration, Mocking Dependenc...
Postman for Efficient Professional Services: Collaboration, Mocking Dependenc...
 

Similar to Composer: The Dependency Manager for PHP Projects

Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with ComposerJason Grimes
 
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 PHPTareq Hasan
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning TalkEric Johnson
 
Composer the Right Way - MM16NL
Composer the Right Way - MM16NLComposer the Right Way - MM16NL
Composer the Right Way - MM16NLRafael Dohms
 
Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Micah Wood
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with ComposerAdam Englander
 
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2Meet Magento Italy
 
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 2016Clark Everetts
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupaldrubb
 
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using ComposerWordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using ComposerJeremy Ward
 
IBM Rational Rhapsody 8.4 install guide (including Cygwin and obtaining an ev...
IBM Rational Rhapsody 8.4 install guide (including Cygwin and obtaining an ev...IBM Rational Rhapsody 8.4 install guide (including Cygwin and obtaining an ev...
IBM Rational Rhapsody 8.4 install guide (including Cygwin and obtaining an ev...Fraser Chadburn
 
Composer the right way
Composer the right wayComposer the right way
Composer the right wayRafael Dohms
 
Composer the right way [SweetlakePHP]
Composer the right way [SweetlakePHP]Composer the right way [SweetlakePHP]
Composer the right way [SweetlakePHP]Rafael Dohms
 
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 2017Clark Everetts
 

Similar to Composer: The Dependency Manager for PHP Projects (20)

Composer
ComposerComposer
Composer
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with Composer
 
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
 
Composer Lightning Talk
Composer Lightning TalkComposer Lightning Talk
Composer Lightning Talk
 
Composer the Right Way - MM16NL
Composer the Right Way - MM16NLComposer the Right Way - MM16NL
Composer the Right Way - MM16NL
 
Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0Using Composer with WordPress - 2.0
Using Composer with WordPress - 2.0
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
Manuele Menozzi - Gestione delle dipendenze con Composer in Magento 2
 
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
 
Composer
ComposerComposer
Composer
 
Composer Helpdesk
Composer HelpdeskComposer Helpdesk
Composer Helpdesk
 
Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
 
Composer talk by Maxim Romanovsky
Composer talk by Maxim RomanovskyComposer talk by Maxim Romanovsky
Composer talk by Maxim Romanovsky
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupal
 
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using ComposerWordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
WordCamp Sacramento 2019: Modernizing Your Development Workflow Using Composer
 
IBM Rational Rhapsody 8.4 install guide (including Cygwin and obtaining an ev...
IBM Rational Rhapsody 8.4 install guide (including Cygwin and obtaining an ev...IBM Rational Rhapsody 8.4 install guide (including Cygwin and obtaining an ev...
IBM Rational Rhapsody 8.4 install guide (including Cygwin and obtaining an ev...
 
Composer the right way
Composer the right wayComposer the right way
Composer the right way
 
Composer the right way [SweetlakePHP]
Composer the right way [SweetlakePHP]Composer the right way [SweetlakePHP]
Composer the right way [SweetlakePHP]
 
Composer
ComposerComposer
Composer
 
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
 

More from Alessandro Minoccheri (8)

ServerSentEventsV2.pdf
ServerSentEventsV2.pdfServerSentEventsV2.pdf
ServerSentEventsV2.pdf
 
ServerSentEvents.pdf
ServerSentEvents.pdfServerSentEvents.pdf
ServerSentEvents.pdf
 
Kotlin hexagonal-architecture
Kotlin hexagonal-architectureKotlin hexagonal-architecture
Kotlin hexagonal-architecture
 
Hexagonal architecture ita
Hexagonal architecture itaHexagonal architecture ita
Hexagonal architecture ita
 
Hexagonal architecture
Hexagonal architectureHexagonal architecture
Hexagonal architecture
 
Smart working
Smart workingSmart working
Smart working
 
Doctrine
DoctrineDoctrine
Doctrine
 
Symfony4
Symfony4Symfony4
Symfony4
 

Recently uploaded

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 

Recently uploaded (20)

React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 

Composer: The Dependency Manager for PHP Projects

  • 2. Composer is a tool for dependency management in PHP, is not a package manager. It allows you to declare the dependent libraries your project needs and it will install them in your project for you. Composer What is composer? What is composer?
  • 3. How does it works?
  • 4. • Install composer • composer init Composer How to start? How to start?
  • 5. • composer install • composer update • composer require vendor/package:1.1.* • composer remove vendor/package • composer update vendor/package Composer How to start? Basic commands
  • 7. Package version: x.y.z • x: MAJOR version when you make incompatible API changes • y: MINOR version when you add functionality in a backwards- compatible manner • z: PATCH version when you make backwards-compatible bug fixes Composer Semantic versioning Semantic versioning
  • 8. • Exact version 2.3.1 • Version range >=1.0 <1.1 || >=1.2 • Tilde version range ~1.2.3 is equivalent to >=1.2.3 <1.3.0 • Caret version range ^1.2.3 is equivalent to >=1.2.3 <2.0.0 Composer Versions and constraints Versions and constraints
  • 9. Composer generate an autoload file for all your dependencies vendor/autoload.php
 Now you can create a class inside app folder like Config.php and use this namespace: AppConfig
 The base directory will be src/App/Config 
 The resulting file path will be: ./src/App/Config/Config.php Composer Autoload Autoload { "autoload": { "psr-4": { "App": "src/" } }, "autoload-dev": { "psr-4": { "AppTests": "tests/" } } }
  • 10. A script, in Composer's terms, can either be a PHP callback (defined as a static method) or any command-line executable command.  Composer Scripts Scripts "scripts": { "post-update-cmd": "MyVendor MyClass::postUpdate", "post-install-cmd": [ "MyVendorMyClass::warmCache", "phpunit -c app/" ], "post-create-project-cmd": [ "php -r "copy('config/local- example.php', 'config/local.php');"" ] }
  • 11. Composer Require Require { "require": { "php": "^7.1.1" } } $ php -v PHP 5.6.10 $ composer update Your requirements could not be resolved to an installable set of packages. Problem 1 This package requires php ^7.1.1 but your PHP version (5.6.10) does not satisfy that requirement.
  • 12. $ php -v PHP 5.6.10 $ composer update Success Composer Platform requirements Platform requirements { "require": { "php": "^7.1.1" }, "config": { "platform": { "php": "7.1.2" } } }
  • 13. • Minimum-stability field defines default stability flags: for example: dev, alpha, beta, RC or stable • -stable, -RC ecc… suffix specifies the stability • If the stability is not specified, composer does it:
 1.2.3 become = 1.2.3.0-stable
 >1.2 become > 1.2.0.0-stable
 >=1.2 become 1.2.0.0-dev
 <1.3 become <1.3.0.0-dev Composer Stability flags Stability flags
  • 14. When running composer install for the first time, or when running composer update a lock file called composer.lock will be created with the exact versions that are installed so they can be re-installed.
 
 composer.lock must be committed to keep all co-workers in the same versions as you and to make deploy faster. Composer Composer.lock Composer.lock
  • 15. To solve composer.lock conflicts you have different ways: • Solve conflicts on .json file, accept your or another .lock and launch composer install • Solve conflicts on .json file, delete composer.lock file and launch composer update • Accept .json and .lock files from origin and re-apply your changes
 
 The best solution is the last to be more safe. Composer Composer.lock conflicts Composer.lock conflicts
  • 17. • Check for composer.lock file • If not, auto generate composer.lock file (Using composer update) • Install the specified versions recorded in the composer.lock file Composer Composer install vs update Composer install
  • 18. • Go through the composer.json file • Check availability of newer (latest) versions, based on the version criteria mentioned (e.g. 1.12.*) • Install the latest possible (according to above) versions • Update composer.lock file with installed versions Composer Composer install vs update Composer update
  • 19. • Use --prefer-dist to avoid git clones
 Will always download zip files if possible (default for stable versions) • Store ~/.composer/cache between builds
 How depends on CI product/setup you use Composer Composer install vs update Composer install performance
  • 20. —optimize-autoloader
 Class map generation essentially converts PSR-4/PSR-0 rules into classmap rules, performance increase from 20% to 25% Composer Composer install vs update Autoloader optimization composer install ——optimize-autoloader composer install --classmap-authoritative —classmap-authoritative 
 If something is not found in the classmap, then it does not exist and the autoloader should not attempt to look on the filesystem according to PSR-4 rules.
  • 21. A git patch is a commit converted into a file that can be applied on a different repository.
 
 So if you have a pull request not merged you can use the PR as if it were merged.
 
 Composer Patching with Composer Patching with Composer { "require": { "symfony/symfony": "4.1.0" }, "config": { "preferred-install": "source" }, "extra": { "patches": { "symfony/symfony": { "Something": “https://url.com/ foo.patch“ } } } }
  • 22. VCS stands for version control system. This includes versioning systems like git, svn, fossil or hg. Composer has a repository type for installing packages from these systems.
 
 Composer Use Private Package Use Private Package "require": { "vendor/package": "dev-master" }, “repositories”:[ { “type”: “vcs”, “url” : “git@bitbucket.org:vendor/
 package.git” } ]
  • 23. • Git: git-scm.com • Subversion: subversion.apache.org • Mercurial: mercurial-scm.org • Fossil: fossil-scm.org GitHub: github.com (Git) BitBucket: bitbucket.org (Git and Mercurial) Composer Git alternatives Git alternatives
  • 24. Packagist is the default Composer package repository. It lets you find packages and lets Composer know where to get the code from Composer Packagist Packagist
  • 25. Put a file named composer.json at the root of your package's repository, containing the at least a name of the package.
 
 Commit the file to your git or other VCS repository.
 
 Login or register on pakagist.org site, then hit the submit button in the menu. Once you entered your public repository URL in there, your package will be automatically crawled periodically. 
 You just have to make sure you keep the composer.json file up to date. Composer Publishing a Package Publishing a Package
  • 26. Grazie. Alessandro Minoccheri
 Twitter: minompi
 Github: AlessandroMinoccheri
 Stackoverflow: Alessandro Minoccheri