SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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...
 

Ähnlich wie Composer

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
 

Ähnlich wie Composer (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
 

Mehr von 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
 

Kürzlich hochgeladen

WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%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 masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
%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 sowetomasabamasaba
 
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...SelfMade bd
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%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 tembisamasabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
%+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
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
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.pptxAnnaArtyushina1
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%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 tembisamasabamasaba
 
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 ProgramWSO2
 
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...WSO2
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 

Kürzlich hochgeladen (20)

WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%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
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%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
 
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...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%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
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%+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...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
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
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%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
 
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
 
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 Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 

Composer

  • 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