Dependency 
management in 
Magento with 
Composer 
Manuele Menozzi 
Senior PHP Developer @ 
Webgriffe® 
Zend Certified PHP Engineer 
Proud & member 
Email: / Twitter: 
GrUSP PUG MoRe 
mmenozzi@webgriffe.com @mmenozzi
About Composer 
Composer is a tool for dependency management in PHP. It allows you to 
declare the dependent libraries your project needs and it will install 
them in your project for you.
What Composer does… 
/composer.json 
{ 
"require": { 
"psr/log": "~1.0", 
"acme/foo": "*", 
"monolog/monolog": "dev-master#2eb0c09" 
}, 
"require-dev": { 
"phpunit/phpunit": "~3.7.0" 
}, 
"repositories": [ 
{ 
"type": "vcs", 
"url": "git@github.com:AcmeCompany/FooLibrary.git" 
}, 
] 
} 
$ composer install
… and how 
composer install 
1. Available packages indexing 
2. Dependency tree and packages list calculation 
3. Packages list locking (composer.lock file) 
4. Packages download (in vendor folder) 
5. Custom installers 
6. Autoload dump
Benefits 
Time save 
Code reuse 
Code sharing 
Easy upgrades 
Same code usage
Composer & Magento 
The problem… 
Composer Magento 
./ 
├── htdocs/ 
└── vendor/ 
├── vendor-name-1/ 
│ ├── package-1/ 
│ ├── package-2/ 
│ └── package-n/ 
├── vendor-name-2/ 
└── vendor-name-n/ 
./ 
├── app/ 
│ ├── code/ 
│ │ ├── community/ 
│ │ └── local/ 
│ ├── design/ 
│ └── etc/ 
│ └── modules/ 
└── skin/
Composer & Magento 
The solution 
1. Available packages indexing 
2. Dependency tree and packages list calculation 
3. Packages list locking (composer.lock file) 
4. Packages download (in vendor folder) 
5. Custom installers 
6. Autoload dump
Magento Composer Installer 
by Magento Hackathon 
github.com/magento-hackathon/magento-composer-installer
Magento Composer Installer 
Install a module in your project 
./composer.json 
{ 
"require": { 
"foo/bar-module": "*", 
"magento-hackathon/magento-composer-installer": "*" 
}, 
"repositories": [ 
{ 
"type": "composer", 
"url": "http://packages.firegento.com" 
} 
], 
"extra":{ 
"magento-root-dir": "htdocs/" 
} 
} 
$ composer install
Magento Composer Installer 
Files mapping 
There are several ways how the mapping from files in the package into 
the Magento source is accomplished: 
1. A mapping in the composer.json 
2. The MagentoConnect package.xml file 
3. The modman file (see github.com/colinmollenhour/modman)
Magento Composer Installer 
Install a MagentoConnect module 
http://packages.firegento.com/ 
{ 
"require": { 
"connect20/locale_mage_community_it_it": "*" 
}, 
"repositories": [ 
{ 
"type": "composer", 
"url": "http://packages.firegento.com" 
} 
] 
}
Magento Composer Installer 
Install the Magento-Core and initialize your project 
Package magento/core on packages.firegento.com 
./composer.json 
{ 
"require": { 
"magento/core": "1.9.0.1" 
}, 
"repositories": [ 
{ 
"type": "composer", 
"url": "http://packages.firegento.com" 
} 
], 
"extra":{ 
"magento-root-dir": "htdocs/" 
} 
} 
Only 1.9.0.1 avaliable... :(
Magento Composer Installer 
Make a module installable with Composer 
./composer.json 
(important: "type": "magento-module") 
{ 
"name": "acme-company/module-name", 
"type": "magento-module", 
"license":"OSL-3.0", 
"description":"A short one line description of your module", 
"repositories": [ 
{ 
"type": "vcs", 
"url": "your/github/or/git/or/svn/etc/repository/uri" 
} 
], 
}
Magento Composer Installer 
Make a module installable with Composer 
Files mapping (modman example) 
./modman 
src app/code/local/AcmeCompany/ModuleName 
etc/AcmeCompany_ModuleName.xml app/etc/modules/ 
locale/it_IT/* app/locale/it_IT/ 
See github.com/colinmollenhour/modman for further info.
Magento Composer Installer 
Useful extras… 
Deploy strategy (magento-deploystrategy) 
Auto append to gitignore (auto-append-gitignore) 
Mapping overwrite (magento-map-overwrite)
Joind.in 
joind.in/talk/view/12698 
Any Question? 
Webgriffe 
Tailored Digital Works 
webgriffe.com | @webgriffe 
5+ Years of Experience with Magento 
5 Certified Developers (Zend & Magento) 
350+ Customers 
20+ Magento Extensions 
450+ Extensions Sold
Thank you!

Dependency management in Magento with Composer

  • 1.
    Dependency management in Magento with Composer Manuele Menozzi Senior PHP Developer @ Webgriffe® Zend Certified PHP Engineer Proud & member Email: / Twitter: GrUSP PUG MoRe mmenozzi@webgriffe.com @mmenozzi
  • 2.
    About Composer Composeris 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.
  • 3.
    What Composer does… /composer.json { "require": { "psr/log": "~1.0", "acme/foo": "*", "monolog/monolog": "dev-master#2eb0c09" }, "require-dev": { "phpunit/phpunit": "~3.7.0" }, "repositories": [ { "type": "vcs", "url": "git@github.com:AcmeCompany/FooLibrary.git" }, ] } $ composer install
  • 4.
    … and how composer install 1. Available packages indexing 2. Dependency tree and packages list calculation 3. Packages list locking (composer.lock file) 4. Packages download (in vendor folder) 5. Custom installers 6. Autoload dump
  • 5.
    Benefits Time save Code reuse Code sharing Easy upgrades Same code usage
  • 6.
    Composer & Magento The problem… Composer Magento ./ ├── htdocs/ └── vendor/ ├── vendor-name-1/ │ ├── package-1/ │ ├── package-2/ │ └── package-n/ ├── vendor-name-2/ └── vendor-name-n/ ./ ├── app/ │ ├── code/ │ │ ├── community/ │ │ └── local/ │ ├── design/ │ └── etc/ │ └── modules/ └── skin/
  • 7.
    Composer & Magento The solution 1. Available packages indexing 2. Dependency tree and packages list calculation 3. Packages list locking (composer.lock file) 4. Packages download (in vendor folder) 5. Custom installers 6. Autoload dump
  • 8.
    Magento Composer Installer by Magento Hackathon github.com/magento-hackathon/magento-composer-installer
  • 9.
    Magento Composer Installer Install a module in your project ./composer.json { "require": { "foo/bar-module": "*", "magento-hackathon/magento-composer-installer": "*" }, "repositories": [ { "type": "composer", "url": "http://packages.firegento.com" } ], "extra":{ "magento-root-dir": "htdocs/" } } $ composer install
  • 10.
    Magento Composer Installer Files mapping There are several ways how the mapping from files in the package into the Magento source is accomplished: 1. A mapping in the composer.json 2. The MagentoConnect package.xml file 3. The modman file (see github.com/colinmollenhour/modman)
  • 11.
    Magento Composer Installer Install a MagentoConnect module http://packages.firegento.com/ { "require": { "connect20/locale_mage_community_it_it": "*" }, "repositories": [ { "type": "composer", "url": "http://packages.firegento.com" } ] }
  • 12.
    Magento Composer Installer Install the Magento-Core and initialize your project Package magento/core on packages.firegento.com ./composer.json { "require": { "magento/core": "1.9.0.1" }, "repositories": [ { "type": "composer", "url": "http://packages.firegento.com" } ], "extra":{ "magento-root-dir": "htdocs/" } } Only 1.9.0.1 avaliable... :(
  • 13.
    Magento Composer Installer Make a module installable with Composer ./composer.json (important: "type": "magento-module") { "name": "acme-company/module-name", "type": "magento-module", "license":"OSL-3.0", "description":"A short one line description of your module", "repositories": [ { "type": "vcs", "url": "your/github/or/git/or/svn/etc/repository/uri" } ], }
  • 14.
    Magento Composer Installer Make a module installable with Composer Files mapping (modman example) ./modman src app/code/local/AcmeCompany/ModuleName etc/AcmeCompany_ModuleName.xml app/etc/modules/ locale/it_IT/* app/locale/it_IT/ See github.com/colinmollenhour/modman for further info.
  • 15.
    Magento Composer Installer Useful extras… Deploy strategy (magento-deploystrategy) Auto append to gitignore (auto-append-gitignore) Mapping overwrite (magento-map-overwrite)
  • 16.
    Joind.in joind.in/talk/view/12698 AnyQuestion? Webgriffe Tailored Digital Works webgriffe.com | @webgriffe 5+ Years of Experience with Magento 5 Certified Developers (Zend & Magento) 350+ Customers 20+ Magento Extensions 450+ Extensions Sold
  • 17.