Composer



Installer Composer dans un projet

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"
composer.json

{
    "name": "Proxidata",
    "description": "Proxidata est une application web de visualisation et d'achat de données B2B.",
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=7.0.4",
        "silex/silex": "@stable",
        "silex/web-profiler": ">=2.0",
        "symfony/http-kernel": ">=3.1",
        "symfony/routing": ">=2.8|>=3.0",
        "symfony/asset": ">=2.8|3.0.*",
        "symfony/browser-kit": ">=2.8|3.0.*",
        "symfony/class-loader": ">=2.8|3.0.*",
        "symfony/config": ">=2.8|3.0.*",
        "symfony/console": ">=2.8|3.0.*",
        "symfony/css-selector": ">=2.8|3.0.*",
        "symfony/debug": ">=2.8|3.0.*",
        "symfony/var-dumper": ">=2.8|3.0.*",
        "symfony/finder": ">=2.8|3.0.*",
        "symfony/form": ">=2.8|3.0.*",
        "symfony/monolog-bridge": ">=2.8|3.0.*",
        "symfony/process": ">=2.8|3.0.*",
        "symfony/security": ">=2.8|3.0.*",
        "symfony/translation": ">=2.8|3.0.*",
        "symfony/twig-bridge": ">=2.8|3.0.*",
        "symfony/validator": ">=2.8|3.0.*",
        "symfony/yaml": ">=2.8|3.0.*",
        "symfony/http-foundation": ">=2.8|3.0.*",
        "deralex/yaml-config-service-provider": "2.0.x-dev",
        "phpmailer/phpmailer": ">=5.2",
        "spipu/html2pdf": "^4.6",
        "paypal/rest-api-sdk-php": "*"
    },
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "extra": {
        "branch-alias": {
            "dev-master": "2.0.x-dev"
        }
    },
    "scripts": {
        "run": [
            "echo 'Started web server on http://localhost:8888'",
            "php -S localhost:8888 -t web web/index_dev.php"
        ]
    }
}
Constraint Internally
1.2.3 =1.2.3.0-stable
>1.2 >1.2.0.0-stable
>=1.2 >=1.2.0.0-dev
>=1.2-stable >=1.2.0.0-stable
<1.3 <1.3.0.0-dev
<=1.3 <=1.3.0.0-stable
1 - 2 >=1.0.0.0-dev <3.0.0.0-dev
~1.3 >=1.3.0.0-dev <2.0.0.0-dev
1.4.* >=1.4.0.0-dev <1.5.0.0-dev
Tilde
The ~ operator is best explained by example: ~1.2 is equivalent to >=1.2 <2.0.0, while ~1.2.3 is equivalent to >=1.2.3 <1.3.0. As you can see it is mostly useful for projects respecting semantic versioning. A common usage would be to mark the minimum minor version you depend on, like ~1.2 (which allows anything up to, but not including, 2.0). Since in theory there should be no backwards compatibility breaks until 2.0, that works well. Another way of looking at it is that using ~ specifies a minimum version, but allows the last digit specified to go up.
Caret
The ^ operator behaves very similarly but it sticks closer to semantic versioning, and will always allow non-breaking updates. For example ^1.2.3 is equivalent to >=1.2.3 <2.0.0 as none of the releases until 2.0 should break backwards compatibility. For pre-1.0 versions it also acts with safety in mind and treats ^0.3 as >=0.3.0 <0.4.0.
Stability
To allow various stabilities without enforcing them at the constraint level however, you may use stability-flags like @<stability> (e.g. @dev) to let composer know that a given package can be installed in a different stability than your default minimum-stability setting.
Mettre à jour les paquets

php composer.phar update
Charger tous les paquets dans le projet (Autoload Dependencies)

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