Composer is a tool for managing dependencies in PHP: this talk starts from a basic introduction on what it is and goes through more advanced issues and solutions.
✗ Have PHP libraries your project depends on ✗ Have PHP libraries depending on other libraries Composer will ✗ Enable you to declare your dependencies ✗ Automatically download and install them ✗ Constantly manage them 5
composer.lock exists ✗ If not, perform a composer update to create one ✗ If composer.lock exists, install the specified versions from the lock file composer update will: ✗ Check composer.json ✗ Determine the latest versions to install based on your version specs ✗ Install the latest versions ✗ Update composer.lock to reflect the latest versions installed 14
it founds new dependency to install, it will: ✗ Download the package from remote repository ✗ Copy it into your <project dir>/vendor folder ✗ Generate (or update) the <project dir>/vendor/autoload.php file, so that you can just include it in your files
In a MAJOR.MINOR.PATCH format, increment : ✗ MAJOR version when you make incompatible API changes ✗ MINOR version when you add functionality in a backwards-compatible manner ✗ PATCH version when you make backwards-compatible bug fixes. Semantic versioning 17 More on https://semver.org
Version range, with comparison operators: >=1.0 greater than or equal to 1.0 ✗ Version range, with comparison and logical operators: >=1.0 <1.1 || >=1.2 (greater than or equal to 1.0 AND less than 1.1) OR (greater than or equal to 1.2) ✗ Hyphenated (-) version range: 1.0 - 2.0 greater than or equal to 1.0.0 AND less than 2.1 18
greater than 1.0 AND less than 1.1 ✗ Tilde (~) version range: ~1.2 greater than or equal to 1.2 AND less than 2.0.0 ~1.2.3 greater than or equal to 1.2.3 AND less than 1.3.0 (It works well with packages respecting semantic versioning) ✗ Caret (^) version range: ^1.2.3 greater than or equal to 1.2 AND less than 2.0.0 (It’s similar to ~ but it allows all non-breaking updates) 19
✗ minimum-stability field defines default stability flag: it can be dev, alpha, beta, RC or stable ✗ If you don’t specify a stability flag, Composer does it transparently: ✗ 1.2.3 become =1.2.3.0-stable ✗ >1.2 become >1.2.0.0-stable ✗ >=1.2 become >=1.2.0.0-dev ✗ <1.3 become <1.3.0.0-dev 20
between all members of team ✗ To have the same dependencies versions of production environment ✗ For faster deploys (updates are slow) But there will be problems with... 23
“your” or “their” .lock Run composer install NOT SAFE Solve conflicts on .json Delete .lock Run composer update SAFE Accept .json and .lock from origin Re-apply your changes 26 To solve conflicts with composer.lock you can:
changes directly version numbers, and EVERY package will be updated ✗ composer update vendor-name/package is quite safe: it changes just that package version ✗ composer install is safe: it adds just the new packages, it doesn’t change the others 27 http://naderman.de/slippy/slides/2017-11-16-SymfonyCon-composer-lock-demystified.pdf
into a file, that can be applied on a different repository With cweagans/composer-patches plugin you can automatically apply a GIT patch on a package 30
repository for public packages, you can submit yours ✗ You can specify other repositories, public or private, under repositories section in your composer.json file 33
and private packages ✗ Configurable with your composer.json ✗ Just put it in your repositories section in composer.json ✗ License review 39 https://packagist.com
the #PHP renaissance and modern PHP ecosystem. @seldaek and @naderman are heroes of our community. (And everyone else that's worked on Composer.) Thank you!“ 44