Dependency management in Magento with Composer

Preview:

DESCRIPTION

Dependency management in Magento with Composer. Talk at MageDay 2014 in Parma, Italy.

Citation preview

Dependencymanagement inMagento with

ComposerManuele Menozzi

Senior PHP Developer @ Zend Certified PHP EngineerProud & member

Email: / Twitter:

Webgriffe®

GrUSP PUG MoRe

mmenozzi@webgriffe.com @mmenozzi

About Composer

Composer is a tool for dependency management in PHP. It allows you todeclare 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 howcomposer install

1. Available packages indexing2. Dependency tree and packages list calculation3. Packages list locking (composer.lock file)4. Packages download (in vendor folder)5. Custom installers6. Autoload dump

Benefits

Time saveCode reuseCode sharingEasy upgradesSame code usage

Composer & MagentoThe 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 & MagentoThe solution

1. Available packages indexing2. Dependency tree and packages list calculation3. Packages list locking (composer.lock file)4. Packages download (in vendor folder)5. Custom installers6. Autoload dump

Magento Composer Installerby Magento Hackathon

github.com/magento-hackathon/magento-composer-installer

Magento Composer InstallerInstall 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 InstallerFiles mapping

There are several ways how the mapping from files in the package intothe Magento source is accomplished:

1. A mapping in the composer.json2. The MagentoConnect package.xml file3. The modman file (see )github.com/colinmollenhour/modman

Magento Composer InstallerInstall a MagentoConnect module

http://packages.firegento.com/{ "require": { "connect20/locale_mage_community_it_it": "*" }, "repositories": [ { "type": "composer", "url": "http://packages.firegento.com" } ]}

Magento Composer InstallerInstall 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 InstallerMake 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 InstallerMake a module installable with Composer

Files mapping (modman example)./modman

src app/code/local/AcmeCompany/ModuleNameetc/AcmeCompany_ModuleName.xml app/etc/modules/locale/it_IT/* app/locale/it_IT/

See for further info.github.com/colinmollenhour/modman

Magento Composer InstallerUseful extras…

Deploy strategy (magento-deploystrategy)Auto append to gitignore (auto-append-gitignore)Mapping overwrite (magento-map-overwrite)

Joind.injoind.in/talk/view/12698

Any Question?

WebgriffeTailored Digital Works

| webgriffe.com @webgriffe5+ Years of Experience with Magento5 Certified Developers (Zend & Magento)350+ Customers20+ Magento Extensions450+ Extensions Sold

Thank you!

Recommended