6. WHY BOTHER?
• As a developer, you want to use consistent
version of libraries/dependencies and tools
• Consistent versioning across all team members
• Share your own library
7. WHY BOTHER?
More developers, more dependency problem
PHPUnit 3.6.10
Behat 2.3.5
Monolog 1.0
PHPUnit 3.4.15
Behat 2.2
Monolog 1.2
Hasin Rifat
14. Isn’t PEAR and the PEAR installer the
de-facto PHP package manager?
15. Isn’t PEAR and the PEAR installer the
de-facto PHP package manager?
Yep
16. Why not PEAR?
• PEAR tends to be used globally*
• Composer is intended to be used in a
per-project manner
• Spread out channels
• Strict Standards
* pear can be installed per-project. But we are not gonna talk about it.
17. COMMON SOLUTION
$ cd ~/projects/my_awesome_project/vendor/
$ mkdir Behat && cd Behat
$ wget https://github.com/downloads/Behat/Behat/behat.phar
$ cd ../../
$ php vendor/Behat/behat.phar tests/features/
18. COMMON SOLUTION
$ cd ~/projects/my_awesome_project/vendor/
$ mkdir Behat && cd Behat
$ wget https://github.com/downloads/Behat/Behat/behat.phar
$ cd ../../
$ php vendor/Behat/behat.phar tests/features/
Or use a git submodule…
or an SVN external if it’s still 2007
19. COMMON SOLUTION
$ cd ~/projects/my_awesome_project/vendor/
$ mkdir Behat && cd Behat
$ wget https://github.com/downloads/Behat/Behat/behat.phar
$ cd ../../
$ php vendor/Behat/behat.phar tests/features/
Or use a git submodule…
or an SVN external if it’s still 2007
BUT, we can do better…
35. COMPOSER 101
Getting the dependencies
$ cd ~/Desktop/composer-test/
$ vi composer.json put this in your project root
36. COMPOSER 101
Getting the dependencies
$ cd ~/Desktop/composer-test/
$ vi composer.json put this in your project root
37. COMPOSER 101
Getting the dependencies
$ cd ~/Desktop/composer-test/
$ vi composer.json put this in your project root
• Exact version
• Range
• Wildcard
• Tilde
38. COMPOSER 101
Getting the dependencies
$ cd ~/Desktop/composer-test/
$ vi composer.json
$ composer.phar install
put this in your project root
• Exact version
• Range
• Wildcard
• Tilde
100. OptimisingThe Autoloader
• Adding huge library slows down
• It calls file_exists every time
$ composer dump-autoload -o
Optimize flag
A bit slower, but performance boost
101. I Am Developing A Library
How Composer can spread my library around?
108. I Have A Private Repository
Will it work if I am developing applications in-house?
• Composer
• VCS
• PEAR
https://getcomposer.org/doc/05-repositories.md