// 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
{
"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"
}
}
// 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
exact: 1.5.2
wildcard: 1.3.*
range: <, >, !=, <=, >=
next major release: ~2.4
composer create-project
--prefer-dist
laravel/laravel
myApp
"5.5.*"
* --prefer-source == git clone
* --prefer-dist == git clone ... ; rm -fr myApp/.git
composer require mobiledetect/mobiledetectlib
composer.json:
"require": {
"php": ">=7.0.0",
...,
...,
"mobiledetect/mobiledetectlib": "^2.8"
},
Route::get('/', function () {
$detect = new Mobile_Detect;
return $detect->getUserAgent();
});
#### Remove package
composer remove mobiledetect/mobiledetectlib
"require": {
"cowlab/checker": "dev-master"
}
Use on your app:
require '../vendor/autoload.php';
use Cowlab\Checker\Http;
composer require mobiledetect/mobiledetectlib