composer | php dependency manager
DESCRIPTION
A quick start presentation on Composer, PHP dependency managerTRANSCRIPT
COMPOSERA PHP dependency manager
Who am I?• Ujjwal Ojha• BSc. CSIT• Hrevert Technologies• Web application development
Table Of Contents• Introduction• What is dependency?• Why not Pear?• Installation• Basic Usage
Introduction• PHP dependency manager
• Very useful to work with third party libraries
• Similar to npm for node.js, Bundler for Ruby, or pip for Python
What is dependency?
Recursive Dependencies
Two Way Recursive Dependencies
Why not Pear?• Pears installs packages globally
• With Pear, your code is scattered throughout the machine.
Installation
mkdir myprojectname
cd myprojectname
curl -s https://getcomposer.org/installer | php
Create composer.json
php composer.phar install
{"require": {
"silex/silex": "~1.0"}
}
Loading composer repositories with package informationInstalling dependencies- Installing psr/log (1.0.0)Loading from cache- Installing symfony/routing (v2.2.1)Downloading: 100%- Installing symfony/http-foundation (v2.2.1)Downloading: 100%- Installing symfony/event-dispatcher (v2.2.1)Loading from cache- Installing symfony/http-kernel (v2.2.1)Downloading: 100%- Installing pimple/pimple (v1.0.2)Downloading: 100%- Installing silex/silex (v1.0.0)Downloading: 100%Writing lock fileGenerating autoload files
Your dependencies dependency
Your dependency
Autoloading
Composer generates an
autoload file for all your
Dependencies
AutoloaderSupports
PSR-0 AutoloaderPSR-4 Autoloader
Classmap Autoloader
Autoloader usage
<?php// From your app`s bootstrap.phpinclude “vendor/autoload.php”;
Scripts
Perform custom actions during installation and update
"scripts": { "post-install-cmd": [
"Sensio\\...Composer\\ScriptHandler::buildBootstrap","Sensio\\...Composer\\ScriptHandler::clearCache","Sensio\\...Composer\\ScriptHandler::installAssets","Sensio\\...Composer\\
ScriptHandler::installRequirementsFile" ], "post-update-cmd": [
“Sensio\\...Composer\\ScriptHandler::buildBootstrap","Sensio\\...Composer\\ScriptHandler::clearCache","Sensio\\...Composer\\ScriptHandler::installAssets","Sensio\\...Composer\\
ScriptHandler::installRequirementsFile" ]},
Non-composer packages{ "repositories": [ { "type": "package", "package": { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "http://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" }, "source": { "url": "http://smarty-php.googlecode.com/svn/", "type": "svn" } } } ]}
Private dependencies with Satis
{ "repositories": [ { "type": "composer", "url": "http://packages.example.org/" } ], "require": { "company/package": "1.2.0", "company/package2": “1.5.2", } }
Thank You
Questions?
Ujjwal Ojha