SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Downloaden Sie, um offline zu lesen
29/05/2015
FEDERICO LOZADA MOSTO
Twitter: @mostofreddy
Web: mostofreddy.com.ar
Facebook: /mostofreddy
Linkedin: ar.linkedin.com/in/federicolozadamosto
Github: /mostofreddy
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
What does that mean?
Scope is per project, not global
Resolves dependencies
Runs installation tasks
What does that mean?
✓ Autoload
✓ PSR-0/PSR-4
✓ Install dependencies & binaries
✓ Scripts
✓ Create project from a package
Features
✓ Installers
✓ Auth
✓ Semantic versioning
✓ Integrate with git/svn/mercurial/etc
✓ and more...
✓ 1st release: 1/03/2012
✓ Inspired by npm and bundler
✓ 100% PHP
✓ Use Symfony components
✓ Autoload
✓ Easy to use
Miscellaneous
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
Installing Composer
Globally
Require PHP >= 5.3.2!
How does it Works?
How does it Works?
Icons by: Ryan Beck, Pieter Smits, Kirill Ulitin from the Noun Project
composer.json
internal dependencies
external dependencies
git
svn
mercurial
etc
Packagist.org
github.com
etc
How it Work?
$ cd /var/www/myProject
$ tree vendor -L 2
vendor
├── autoload.php
├── composer
│ ├── autoload_classmap.php
│ ├── autoload_namespaces.php
│ ├── autoload_psr4.php
│ ├── autoload_real.php
│ ├── ClassLoader.php
│ └── installed.json
├── symfony
│ ├── confy
│ └── yaml
└── psr
└── log
Who’s using Composer?
and more...
Who’s using Composer?
60.125 packages registered
271.001 versions available
789.500.318 packages installed (since 2012-04-13)
Why to use composer?
Componentization
Standardization
Reuse
Speed
Agility
Basics
Basic commands
$ composer list
Display all commands
config Set config options
create-project Create new project from a package
global Allows running commands in the global composer dir
init Creates a basic composer.json file in current directory
install Installs the project dependencies
update Updates your dependencies to the latest version
self-update Updates composer.phar to the latest version
and more...
composer.json
composer.lock
✓ metadata
✓ configuration
✓ dependencies
✓ development dependencies
✓ locks versions of dependencies
✓ run the same version everywhere
{
"name": "Mostofreddy/MyProject",
"description": "My project",|
"version": "2.1.0",
"license": "MIT",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"MostofreddyMyProject": "src"
}
}
}
composer.json
{
"name": "Mostofreddy/MyProject",
"description": "My project",
"version": "2.1.0",
"license": "MIT",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"MostofreddyMyProject": "src"
}
}
}
composer.json
Metadata
Dependencies
Autoload
composer.json
$ composer validate
./composer.json is valid, but with a few warnings
See http://getcomposer.org/doc/04-schema.md for details on the schema
License "MIT" is not a valid SPDX license identifier, see http://www.spdx.org/licenses/ if
you use an open license.
If the software is closed-source, you may use "proprietary" as license.
The version field is present, it is recommended to leave it out if the package is published
on Packagist.
Name "Mostofreddy/MyProject" does not match the best practice (e.g. lower-cased/with-dashes).
Validate it!!
composer.lock
✓ Locks versions of dependencies
✓ Run the same version everywhere
! Is good practice to upload the file to the repository
Metadata
name
name: “Mostofreddy/MyProject”
The name of the package.
It consists of vendor name and project name, separated by /
name
name: “Mostofreddy/MyProject”
The name of the package.
It consists of vendor name and project name, separated by /
vendor
project name
version
version: “1.0.1”
The version of the package
! Semantic version format
type
type: “libray”
The type of the package. It defaults to library
! Only use a custom type if you need custom
logic during installation. It is recommended
to omit this field and have it just default to
library
licence
licence: “MIT”
The license of the package. This can be either a string or
an array of strings.
author
authors: [{...}]
The authors of the package. This is an array of objects.
✓ name: The author's name. Usually
his real name.
✓ email: The author's email address.
✓ homepage: An URL to the author's
website.
✓ role: The authors' role in the
project (e.g. developer or
translator)
{
"authors": [
{
"name": "Federico Mosto",
"email": "mosto.federico@gmail.com",
"homepage": "http://mostofreddy.com.ar",
"role": "Developer"
},
{
…
}
]
}
others
homepage: “https://www.github.com/...”
An URL to the website of the project
“keywords”: [“key1”, “key2”]
An array of keywords that the package is related to
and more
https://getcomposer.org/doc/04-schema.md
Dependencies
{
"require": {
}
}
require
{
"require": {
"php": ">=5.5.0"
}
}
require
PHP Version
{
"require": {
"php": ">=5.5.0",
"ext-gd": "*",
"lib-curl": "*"
}
}
require
PHP extension
& libraries
libraries available:
curl, iconv, libxml, openssl, pcre, uuid, xsl
Tip: composer show --platform
!
!
{
"require": {
"php": ">=5.5.0",
"ext-gd": "*",
"lib-curl": "*",
"symfony/symfony": "2.3.*",
"twig/extensions": "1.0.*",
"sensio/generator-bundle": "2.3.*",
"incenteev/composer-parameter-handler": "~2.0",
".../...": "...",
"ocramius/proxy-manager": "~0.3.1"
}
}
require
vendor project name version
require
✓ exact: 1.2.0
✓ range: >, >= <,<=, !=
✓ wildcard: 2.0.*
✓ next major release: ~ 1.5
Dependency version
require-dev
{
"require-dev": {
"phpunit/phpunit": "4.1.*",
"squizlabs/php_codesniffer": "1.*",
"satooshi/php-coveralls": "dev-master"
}
}
$ composer install --dev
$ composer install --no-dev
install without dev dependencies!
! install with dev dependencies
Autoload
Autoload
PSR-0
PSR-4
Classmap
Files
PSR-0
{
"autoload": {
"psr-0": {
"MyNamespace": ["src/"]
}
}
}
.
└── src
└── MyNamespace
└── Entity
└── Person.php
Filesystem
require_once ROOT_PATH."vendor/autoload.
php";
$person = new MyNamespaceEntityPerson();
How to use
PSR-0 definition: http://www.php-fig.org/psr/psr-0/
PSR-4
{
"autoload": {
"psr-4": {
"MyNamespace": ["src/"]
}
}
}
.
└── src
└── Entity
└── Person.php
Filesystem
require_once ROOT_PATH."vendor/autoload.
php";
$person = new MyNamespaceEntityPerson();
How to use
PSR-4 definition: http://www.php-fig.org/psr/psr-4/
Classmap
{
"autoload": {
"classmap": [
"src/", "lib/", "DB.php"
]
}
}
.
└── src
└── lib
└── DB.php
Filesystem
require_once ROOT_PATH."vendor/autoload.
php";
$person = new DB();
How to use
Files
{
"autoload": {
"files": ["classes/class.DB.php"]
}
}
.
└── classes
└── class.DB.php
Filesystem
require_once ROOT_PATH."vendor/autoload.
php";
$person = new DB();
How to use
Scripts / Events
Scripts
A script, in Composer's terms, can either be a PHP
callback (defined as a static method) or any command-
line executable command. Scripts are useful for
executing a package's custom code or package-specific
commands during the Composer execution process
Events
Composer fires the following named events during its execution process:
✓ pre-install-cmd
✓ post-install-cmd
✓ pre-update-cmd
✓ post-update-cmd
✓ pre-status-cmd
✓ post-status-cmd
✓ pre-dependencies-solving
✓ post-dependencies-solving
✓ pre-package-install
✓ post-package-install
✓ pre-package-update
✓ post-package-update
✓ pre-package-uninstall
✓ post-package-uninstall
✓ pre-autoload-dump
✓ post-autoload-dump
✓ post-root-package-install
✓ post-create-project-cmd
✓ pre-archive-cmd
✓ post-archive-cmd
throw script in events
{
"scripts": {
"post-update-cmd": "MyVendorMyClass::postUpdate",
"post-package-install": [
"MyVendorMyClass::postPackageInstall"
],
"post-install-cmd": [
"MyVendorMyClass::warmCache",
"phpunit -c tests/phpunit.xml"
],
"post-create-project-cmd" : [
"php -r "copy('config/local-example.php', 'config/local.
php');""
]
}
}
throw script in events
namespace MyVendor;
use ComposerScriptEvent;
class MyClass
{
public static function postUpdate(Event $event) {
// do stuff
}
public static function postPackageInstall(Event $event) {
// do stuff
}
public static function warmCache(Event $event) {
// make cache toasty
}
}
Composer + CI
Jenkins
<!-- COMPOSER -->
<target name="composer-install" description="Install Composer Deps"
depends="prepare" unless="${composer-lock}">
<echo message="- Running Composer Install" />
<exec executable="composer" dir="${basedir}/../php-project">
<arg value="install" />
<arg value="--verbose" />
<arg value="--no-interaction" />
<arg value="--no-plugins" />
</exec>
</target>
Travis - CI
language: php
php:
- 5.4
- 5.5
- 5.6
- hhvm
before_script:
- composer self-update
- composer install
script:
- php vendor/bin/phpcs --standard=psr2 src/
- php vendor/bin/phpunit -c tests/phpunit.xm
Web: https://travis-ci.org/
Change the
development culture
PACKAGES
LIBRARIES
COMPONENTS
REUSE!!!
Questions?
Thanks!
FEDERICO LOZADA MOSTO
TW: @mostofreddy
Web: mostofreddy.com.ar
FB: mostofreddy
In: ar.linkedin.com/in/federicolozadamosto
Git: mostofreddy

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Laravel
LaravelLaravel
Laravel
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Docker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to Docker
 
Micro frontend
Micro frontendMicro frontend
Micro frontend
 
php
phpphp
php
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
 
Docker on Docker
Docker on DockerDocker on Docker
Docker on Docker
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
PHP Basic & Variables
PHP Basic & VariablesPHP Basic & Variables
PHP Basic & Variables
 
HTML
HTMLHTML
HTML
 
Presentation joomla-introduction
Presentation joomla-introductionPresentation joomla-introduction
Presentation joomla-introduction
 
The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!The Benefits of Using React JS for Web Development!
The Benefits of Using React JS for Web Development!
 
Laravel 101
Laravel 101Laravel 101
Laravel 101
 
Front-End Frameworks: a quick overview
Front-End Frameworks: a quick overviewFront-End Frameworks: a quick overview
Front-End Frameworks: a quick overview
 
Maven Overview
Maven OverviewMaven Overview
Maven Overview
 

Ähnlich wie Composer

Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with ComposerJason Grimes
 
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
 
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
 
PHP Dependency Management with Composer
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with ComposerAdam Englander
 
Dependency management in Magento with Composer
Dependency management in Magento with ComposerDependency management in Magento with Composer
Dependency management in Magento with ComposerManuele Menozzi
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupaldrubb
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guidevjvarenya
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern ApproachAlessandro Fiore
 
12 Composer #burningkeyboards
12 Composer #burningkeyboards12 Composer #burningkeyboards
12 Composer #burningkeyboardsDenis Ristic
 
Dependent things dependency management for apple sw - slideshare
Dependent things   dependency management for apple sw - slideshareDependent things   dependency management for apple sw - slideshare
Dependent things dependency management for apple sw - slideshareCavelle Benjamin
 
Development Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP LibrariesDevelopment Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP LibrariesPantheon
 
Bower & Grunt - A practical workflow
Bower & Grunt - A practical workflowBower & Grunt - A practical workflow
Bower & Grunt - A practical workflowRiccardo Coppola
 
PHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the CloudPHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the CloudSalesforce Developers
 

Ähnlich wie Composer (20)

Composer namespacing
Composer namespacingComposer namespacing
Composer namespacing
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with 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
 
Composer Helpdesk
Composer HelpdeskComposer Helpdesk
Composer Helpdesk
 
Composer
ComposerComposer
Composer
 
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
PHP Dependency Management with ComposerPHP Dependency Management with Composer
PHP Dependency Management with Composer
 
Dependency management in Magento with Composer
Dependency management in Magento with ComposerDependency management in Magento with Composer
Dependency management in Magento with Composer
 
composer_talk_20160209
composer_talk_20160209composer_talk_20160209
composer_talk_20160209
 
Composer & Drupal
Composer & DrupalComposer & Drupal
Composer & Drupal
 
Prizm Installation Guide
Prizm Installation GuidePrizm Installation Guide
Prizm Installation Guide
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
 
Composer: Dependency Manager for PHP
Composer: Dependency Manager for PHPComposer: Dependency Manager for PHP
Composer: Dependency Manager for PHP
 
Composer
ComposerComposer
Composer
 
PHP Development Tools
PHP  Development ToolsPHP  Development Tools
PHP Development Tools
 
12 Composer #burningkeyboards
12 Composer #burningkeyboards12 Composer #burningkeyboards
12 Composer #burningkeyboards
 
Dependent things dependency management for apple sw - slideshare
Dependent things   dependency management for apple sw - slideshareDependent things   dependency management for apple sw - slideshare
Dependent things dependency management for apple sw - slideshare
 
Development Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP LibrariesDevelopment Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP Libraries
 
Bower & Grunt - A practical workflow
Bower & Grunt - A practical workflowBower & Grunt - A practical workflow
Bower & Grunt - A practical workflow
 
PHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the CloudPHP on Heroku: Deploying and Scaling Apps in the Cloud
PHP on Heroku: Deploying and Scaling Apps in the Cloud
 

Mehr von Federico Damián Lozada Mosto (8)

Php 5.6
Php 5.6Php 5.6
Php 5.6
 
Solid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examplesSolid Principles & Design patterns with PHP examples
Solid Principles & Design patterns with PHP examples
 
Implementando una Arquitectura de Microservicios
Implementando una Arquitectura de MicroserviciosImplementando una Arquitectura de Microservicios
Implementando una Arquitectura de Microservicios
 
Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6Key features PHP 5.3 - 5.6
Key features PHP 5.3 - 5.6
 
Travis-CI - Continuos integration in the cloud for PHP
Travis-CI - Continuos integration in the cloud for PHPTravis-CI - Continuos integration in the cloud for PHP
Travis-CI - Continuos integration in the cloud for PHP
 
Introduction to unit testing
Introduction to unit testingIntroduction to unit testing
Introduction to unit testing
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
Scrum
ScrumScrum
Scrum
 

Kürzlich hochgeladen

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Kürzlich hochgeladen (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Composer

  • 1.
  • 3. FEDERICO LOZADA MOSTO Twitter: @mostofreddy Web: mostofreddy.com.ar Facebook: /mostofreddy Linkedin: ar.linkedin.com/in/federicolozadamosto Github: /mostofreddy
  • 4. 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
  • 6. Scope is per project, not global Resolves dependencies Runs installation tasks What does that mean?
  • 7. ✓ Autoload ✓ PSR-0/PSR-4 ✓ Install dependencies & binaries ✓ Scripts ✓ Create project from a package Features ✓ Installers ✓ Auth ✓ Semantic versioning ✓ Integrate with git/svn/mercurial/etc ✓ and more...
  • 8. ✓ 1st release: 1/03/2012 ✓ Inspired by npm and bundler ✓ 100% PHP ✓ Use Symfony components ✓ Autoload ✓ Easy to use Miscellaneous
  • 9. $ curl -sS https://getcomposer.org/installer | php $ mv composer.phar /usr/local/bin/composer Installing Composer Globally Require PHP >= 5.3.2!
  • 10. How does it Works?
  • 11. How does it Works? Icons by: Ryan Beck, Pieter Smits, Kirill Ulitin from the Noun Project composer.json internal dependencies external dependencies git svn mercurial etc Packagist.org github.com etc
  • 12. How it Work? $ cd /var/www/myProject $ tree vendor -L 2 vendor ├── autoload.php ├── composer │ ├── autoload_classmap.php │ ├── autoload_namespaces.php │ ├── autoload_psr4.php │ ├── autoload_real.php │ ├── ClassLoader.php │ └── installed.json ├── symfony │ ├── confy │ └── yaml └── psr └── log
  • 14. Who’s using Composer? 60.125 packages registered 271.001 versions available 789.500.318 packages installed (since 2012-04-13)
  • 15. Why to use composer? Componentization Standardization Reuse Speed Agility
  • 17. Basic commands $ composer list Display all commands config Set config options create-project Create new project from a package global Allows running commands in the global composer dir init Creates a basic composer.json file in current directory install Installs the project dependencies update Updates your dependencies to the latest version self-update Updates composer.phar to the latest version and more...
  • 18. composer.json composer.lock ✓ metadata ✓ configuration ✓ dependencies ✓ development dependencies ✓ locks versions of dependencies ✓ run the same version everywhere
  • 19. { "name": "Mostofreddy/MyProject", "description": "My project",| "version": "2.1.0", "license": "MIT", "require": { "php": ">=5.3.0" }, "autoload": { "psr-4": { "MostofreddyMyProject": "src" } } } composer.json
  • 20. { "name": "Mostofreddy/MyProject", "description": "My project", "version": "2.1.0", "license": "MIT", "require": { "php": ">=5.3.0" }, "autoload": { "psr-4": { "MostofreddyMyProject": "src" } } } composer.json Metadata Dependencies Autoload
  • 21. composer.json $ composer validate ./composer.json is valid, but with a few warnings See http://getcomposer.org/doc/04-schema.md for details on the schema License "MIT" is not a valid SPDX license identifier, see http://www.spdx.org/licenses/ if you use an open license. If the software is closed-source, you may use "proprietary" as license. The version field is present, it is recommended to leave it out if the package is published on Packagist. Name "Mostofreddy/MyProject" does not match the best practice (e.g. lower-cased/with-dashes). Validate it!!
  • 22. composer.lock ✓ Locks versions of dependencies ✓ Run the same version everywhere ! Is good practice to upload the file to the repository
  • 24. name name: “Mostofreddy/MyProject” The name of the package. It consists of vendor name and project name, separated by /
  • 25. name name: “Mostofreddy/MyProject” The name of the package. It consists of vendor name and project name, separated by / vendor project name
  • 26. version version: “1.0.1” The version of the package ! Semantic version format
  • 27. type type: “libray” The type of the package. It defaults to library ! Only use a custom type if you need custom logic during installation. It is recommended to omit this field and have it just default to library
  • 28. licence licence: “MIT” The license of the package. This can be either a string or an array of strings.
  • 29. author authors: [{...}] The authors of the package. This is an array of objects. ✓ name: The author's name. Usually his real name. ✓ email: The author's email address. ✓ homepage: An URL to the author's website. ✓ role: The authors' role in the project (e.g. developer or translator) { "authors": [ { "name": "Federico Mosto", "email": "mosto.federico@gmail.com", "homepage": "http://mostofreddy.com.ar", "role": "Developer" }, { … } ] }
  • 30. others homepage: “https://www.github.com/...” An URL to the website of the project “keywords”: [“key1”, “key2”] An array of keywords that the package is related to and more https://getcomposer.org/doc/04-schema.md
  • 34. { "require": { "php": ">=5.5.0", "ext-gd": "*", "lib-curl": "*" } } require PHP extension & libraries libraries available: curl, iconv, libxml, openssl, pcre, uuid, xsl Tip: composer show --platform ! !
  • 35. { "require": { "php": ">=5.5.0", "ext-gd": "*", "lib-curl": "*", "symfony/symfony": "2.3.*", "twig/extensions": "1.0.*", "sensio/generator-bundle": "2.3.*", "incenteev/composer-parameter-handler": "~2.0", ".../...": "...", "ocramius/proxy-manager": "~0.3.1" } } require vendor project name version
  • 36. require ✓ exact: 1.2.0 ✓ range: >, >= <,<=, != ✓ wildcard: 2.0.* ✓ next major release: ~ 1.5 Dependency version
  • 37. require-dev { "require-dev": { "phpunit/phpunit": "4.1.*", "squizlabs/php_codesniffer": "1.*", "satooshi/php-coveralls": "dev-master" } } $ composer install --dev $ composer install --no-dev install without dev dependencies! ! install with dev dependencies
  • 40. PSR-0 { "autoload": { "psr-0": { "MyNamespace": ["src/"] } } } . └── src └── MyNamespace └── Entity └── Person.php Filesystem require_once ROOT_PATH."vendor/autoload. php"; $person = new MyNamespaceEntityPerson(); How to use PSR-0 definition: http://www.php-fig.org/psr/psr-0/
  • 41. PSR-4 { "autoload": { "psr-4": { "MyNamespace": ["src/"] } } } . └── src └── Entity └── Person.php Filesystem require_once ROOT_PATH."vendor/autoload. php"; $person = new MyNamespaceEntityPerson(); How to use PSR-4 definition: http://www.php-fig.org/psr/psr-4/
  • 42. Classmap { "autoload": { "classmap": [ "src/", "lib/", "DB.php" ] } } . └── src └── lib └── DB.php Filesystem require_once ROOT_PATH."vendor/autoload. php"; $person = new DB(); How to use
  • 43. Files { "autoload": { "files": ["classes/class.DB.php"] } } . └── classes └── class.DB.php Filesystem require_once ROOT_PATH."vendor/autoload. php"; $person = new DB(); How to use
  • 45. Scripts A script, in Composer's terms, can either be a PHP callback (defined as a static method) or any command- line executable command. Scripts are useful for executing a package's custom code or package-specific commands during the Composer execution process
  • 46. Events Composer fires the following named events during its execution process: ✓ pre-install-cmd ✓ post-install-cmd ✓ pre-update-cmd ✓ post-update-cmd ✓ pre-status-cmd ✓ post-status-cmd ✓ pre-dependencies-solving ✓ post-dependencies-solving ✓ pre-package-install ✓ post-package-install ✓ pre-package-update ✓ post-package-update ✓ pre-package-uninstall ✓ post-package-uninstall ✓ pre-autoload-dump ✓ post-autoload-dump ✓ post-root-package-install ✓ post-create-project-cmd ✓ pre-archive-cmd ✓ post-archive-cmd
  • 47. throw script in events { "scripts": { "post-update-cmd": "MyVendorMyClass::postUpdate", "post-package-install": [ "MyVendorMyClass::postPackageInstall" ], "post-install-cmd": [ "MyVendorMyClass::warmCache", "phpunit -c tests/phpunit.xml" ], "post-create-project-cmd" : [ "php -r "copy('config/local-example.php', 'config/local. php');"" ] } }
  • 48. throw script in events namespace MyVendor; use ComposerScriptEvent; class MyClass { public static function postUpdate(Event $event) { // do stuff } public static function postPackageInstall(Event $event) { // do stuff } public static function warmCache(Event $event) { // make cache toasty } }
  • 50. Jenkins <!-- COMPOSER --> <target name="composer-install" description="Install Composer Deps" depends="prepare" unless="${composer-lock}"> <echo message="- Running Composer Install" /> <exec executable="composer" dir="${basedir}/../php-project"> <arg value="install" /> <arg value="--verbose" /> <arg value="--no-interaction" /> <arg value="--no-plugins" /> </exec> </target>
  • 51. Travis - CI language: php php: - 5.4 - 5.5 - 5.6 - hhvm before_script: - composer self-update - composer install script: - php vendor/bin/phpcs --standard=psr2 src/ - php vendor/bin/phpunit -c tests/phpunit.xm Web: https://travis-ci.org/
  • 54. Thanks! FEDERICO LOZADA MOSTO TW: @mostofreddy Web: mostofreddy.com.ar FB: mostofreddy In: ar.linkedin.com/in/federicolozadamosto Git: mostofreddy