SlideShare uma empresa Scribd logo
1 de 54
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocket
Ming-Ying Wu
 
FIWARE Training: IoT and Legacy
FIWARE Training: IoT and LegacyFIWARE Training: IoT and Legacy
FIWARE Training: IoT and Legacy
FIWARE
 

Mais procurados (20)

Attacking thru HTTP Host header
Attacking thru HTTP Host headerAttacking thru HTTP Host header
Attacking thru HTTP Host header
 
XSS Magic tricks
XSS Magic tricksXSS Magic tricks
XSS Magic tricks
 
Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with Augeas
 
Terraform Introduction
Terraform IntroductionTerraform Introduction
Terraform Introduction
 
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webappsMikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
Mikhail Egorov - Hunting for bugs in Adobe Experience Manager webapps
 
Pentesting Android Applications
Pentesting Android ApplicationsPentesting Android Applications
Pentesting Android Applications
 
A story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEMA story of the passive aggressive sysadmin of AEM
A story of the passive aggressive sysadmin of AEM
 
Reverse proxies & Inconsistency
Reverse proxies & InconsistencyReverse proxies & Inconsistency
Reverse proxies & Inconsistency
 
Introduction to SoapUI day 1
Introduction to SoapUI day 1Introduction to SoapUI day 1
Introduction to SoapUI day 1
 
Introduction to helm
Introduction to helmIntroduction to helm
Introduction to helm
 
Extending kubernetes with CustomResourceDefinitions
Extending kubernetes with CustomResourceDefinitionsExtending kubernetes with CustomResourceDefinitions
Extending kubernetes with CustomResourceDefinitions
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Hacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sitesHacking Adobe Experience Manager sites
Hacking Adobe Experience Manager sites
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocket
 
Behind the curtain - How Django handles a request
Behind the curtain - How Django handles a requestBehind the curtain - How Django handles a request
Behind the curtain - How Django handles a request
 
HTTP Security Headers
HTTP Security HeadersHTTP Security Headers
HTTP Security Headers
 
introduction about REST API
introduction about REST APIintroduction about REST API
introduction about REST API
 
FIWARE Training: IoT and Legacy
FIWARE Training: IoT and LegacyFIWARE Training: IoT and Legacy
FIWARE Training: IoT and Legacy
 
Express node js
Express node jsExpress node js
Express node js
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 

Semelhante a Composer

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

Semelhante a 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
 

Mais de Federico Damián Lozada Mosto

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
Federico Damián Lozada Mosto
 

Mais de 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
 

Último

%+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
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
+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
 

Último (20)

%+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...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
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-...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
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
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
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...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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 🔝✔️✔️
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in 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
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
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...
 
+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...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
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...
 

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