## COMPOSER Dependency Manager for PHP [https://getcomposer.org](https://getcomposer.org)
#### History * Developed by Nils Adermann (http://naderman.de) and by Jordi Boggiano (https://seld.be) * Inspired by Node.js's "npm" and Ruby's "bundler" * First released it on March 1, 2012 * 100% php * MIT License * https://github.com/composer/composer
#### Some features * Install dependencies and binaries * Create project from package * Event scripts and custom scripts * Support private packages and Auth * Central package repository [packagist.org](https://packagist.org/) * Autoloader file * Semantic versioning * Packages on git/svn/mercurial * Awesome documentation [getcomposer.org/doc](https://getcomposer.org/doc/) * ...
## Use composer
#### System Requirements * PHP 5.3.2+ * "A few sensitive php settings and compile flags are also required, but when using the installer you will be warned about any incompatibilities."
#### Installation Linux / Unix / OSX

							// Install local
							curl -s https://getcomposer.org/installer | php

							// Install global
							mv composer.phar /usr/local/bin/composer

							// Check installation
							composer --version

							// Update composer
							composer self-update

							// Rollback to previous version
							composer self-update --rollback
				
#### composer.json vs composer.lock composer.json ([JSON schema](http://json-schema.org/)) * metadata * configuration * dependencies * scripts * extra * ... composer.lock * based on composer.json file * lock dependencies versions * let developers run same dependencies
#### Composer.json One composer.json (Slim framework):

							{
								"name": "slim/slim",
								"type": "library",
								"description": "Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs",
								"keywords": ["framework","micro","api","router"],
								"homepage": "https://slimframework.com",
								"license": "MIT",
								"authors": [
									{
										"name": "Josh Lockhart",
										"email": "hello@joshlockhart.com",
										"homepage": "https://joshlockhart.com"
									},
									{
										"name": "Andrew Smith",
										"email": "a.smith@silentworks.co.uk",
										"homepage": "http://silentworks.co.uk"
									},
									{
										"name": "Rob Allen",
										"email": "rob@akrabat.com",
										"homepage": "http://akrabat.com"
									},
									{
										"name": "Gabriel Manricks",
										"email": "gmanricks@me.com",
										"homepage": "http://gabrielmanricks.com"
									}
								],
								"require": {
									"php": ">=5.5.0",
									"pimple/pimple": "^3.0",
									"psr/http-message": "^1.0",
									"nikic/fast-route": "^1.0",
									"container-interop/container-interop": "^1.2",
									"psr/container": "^1.0"
								},
								"require-dev": {
									"squizlabs/php_codesniffer": "^2.5",
									"phpunit/phpunit": "^4.0"
								},
								"provide": {
									"psr/http-message-implementation": "1.0"
								},
								"autoload": {
									"psr-4": {
										"Slim\\": "Slim"
									}
								},
								"scripts": {
									"test": [
										"@phpunit",
										"@phpcs"
									],
									"phpunit": "php vendor/bin/phpunit",
									"phpcs": "php vendor/bin/phpcs"
								}
							}
				
#### Basic commands * "composer install" : Install all dependencies on composer.lock, if composer.lock don't exits, install all dependencies on composer.json and create a composer.lock file. * "composer update": Update all dependencies and update composer.lock file, if only exists composer.json, works like "composer install".
#### More commands

							// Adds required packages to your composer.json
							// and installs them
							composer require vendor/package:version

							// Removes a package from the require or require-dev
							composer remove vendor/package

							// Dumps/regenerate autoloader
							composer dump-autoload

							// Get raw list of commands
							composer list --raw
				

Semantic versioning


1 . 2 . 5

Major . Minor . Patch

API breaks . New features . Bugs fixed


exact: 1.5.2
wildcard: 1.3.*
range: <, >, !=, <=, >=
next major release: ~2.4

## CREATE PROJECT WITH COMPOSER
#### composer create-project create new projects from an existing package. composer create-project = git clone + composer install
#### new laravel installation

								composer create-project
										--prefer-dist
										laravel/laravel
										myApp
										"5.5.*"
				
* --prefer-source == git clone * --prefer-dist == git clone ... ; rm -fr myApp/.git
#### What happens during installation? * create myApp folder * post-root-package-install (create .env file) * require packages * suggestions * create composer.lock and dump autoload * post-autoload-dump (laravel postAutoloadDump + package:discover) * post-create-project-cmd (key:generate)
#### Add external package

								composer require mobiledetect/mobiledetectlib
							
composer.json:

								"require": {
									"php": ">=7.0.0",
									...,
									...,
									"mobiledetect/mobiledetectlib": "^2.8"
								},
							
#### Use package

								Route::get('/', function () {

									$detect = new Mobile_Detect;

									return $detect->getUserAgent();

								});
							
#### Remove package

								composer remove mobiledetect/mobiledetectlib
							
## Create a package
### How to: * Create a composer.json file with "composer init" or * Create composer.json manually * Public packages: * Put your package on accesiblle repository (git/svn/hg) * Publish your package on https://packagist.org/ * Notify Packagist when your package is updated * Composer support private packages
### Use your package on your project Require on your composer.json project:

							"require": {
								"cowlab/checker": "dev-master"
							}
			
Use on your app:

							require '../vendor/autoload.php';

							use Cowlab\Checker\Http;
				
### Adding external package on your custom project

							composer require mobiledetect/mobiledetectlib
						
## Final recommendations
### Good practices * [Autoloader Optimization](https://getcomposer.org/doc/articles/autoloader-optimization.md) * Put "composer.lock" on repo and use "composer install" * [Don't use version constraints combining comparisons and wildcards](https://getcomposer.org/doc/faqs/why-are-version-constraints-combining-comparisons-and-wildcards-a-bad-idea.md)
### Some links * Composer Cheat Sheet: http://composer.json.jolicode.com * Composer parallel install plugin: [hirak/prestissimo](https://github.com/hirak/prestissimo) * Testing Version Constraints: https://semver.mwl.be