Composer - The missing package manager for PHP
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Composer - The missing package manager for PHP

  • 5,463 views
Uploaded on

I gave the talk in on 6th June, 2014 at Digital World developer conference at Bangabandhu International Conference Center (BICC) in Dhaka, Bangladesh.

I gave the talk in on 6th June, 2014 at Digital World developer conference at Bangabandhu International Conference Center (BICC) in Dhaka, Bangladesh.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,463
On Slideshare
1,252
From Embeds
4,211
Number of Embeds
6

Actions

Shares
Downloads
65
Comments
0
Likes
7

Embeds 4,211

http://tareq.wedevs.com 4,195
https://twitter.com 11
http://tareq.wedevs.com&_=1409321363290 HTTP 1
http://tareq.wedevs.com. 1
http://translate.googleusercontent.com 1
http://www.slideee.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. COMPOSER The missing package manager for PHP
  • 2. PyPi
  • 3. Common Web Languages
  • 4. Communities inside PHP
  • 5. SHARING WASN’T CARING • Autoloading PHP Classes • Dependencies? • Where does this thing go?
  • 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
  • 8. SOLUTIONS • PEAR • SVN Externals • Git Submodules • Vendor Management Scripts
  • 9. SOLUTIONS • PEAR • SVN Externals • Git Submodules • Vendor Management Scripts
  • 10. SOLUTIONS • PEAR • SVN Externals • Git Submodules • Vendor Management Scripts
  • 11. SOLUTIONS • PEAR • SVN Externals • Git Submodules • Vendor Management Scripts
  • 12. SOLUTIONS • PEAR • SVN Externals • Git Submodules • Vendor Management Scripts
  • 13. SOLUTIONS • PEAR • SVN Externals • Git Submodules • Vendor Management Scripts Composer!
  • 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…
  • 20. http://getcomposer.org
  • 21. Install Composer
  • 22. Install Composer With PEAR
  • 23. Install Composer With PEAR For MaximumTrolling
  • 24. Install Composer With PEAR For MaximumTrolling
  • 25. Install Composer With PEAR For MaximumTrolling I am kidding!
  • 26. INSTALLING COMPOSER
  • 27. INSTALLING COMPOSER Locally
 $ curl -sS https://getcomposer.org/installer | php
  • 28. INSTALLING COMPOSER Locally
 $ curl -sS https://getcomposer.org/installer | php
  • 29. INSTALLING COMPOSER Locally
 $ curl -sS https://getcomposer.org/installer | php Globally
 $ curl -sS https://getcomposer.org/installer | php
 $ mv composer.phar /usr/local/bin/composer
  • 30. NowYou Can Use Composer
  • 31. I Am Building A Project How Composer can help me?
  • 32. COMPOSER 101 Getting the dependencies
  • 33. COMPOSER 101 Getting the dependencies $ cd ~/Desktop/composer-test/
  • 34. COMPOSER 101 Getting the dependencies $ cd ~/Desktop/composer-test/ $ vi composer.json
  • 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
  • 39. Your dependency
  • 40. Your dependency
  • 41. Your dependency’s dependencies Your dependency
  • 42. Your dependency’s dependencies Your dependency
  • 43. Your dependency’s dependencies Your dependency Suggested Package
  • 44. Checking Server Requirements I need your server to have these…
  • 45. File Organisation vendor/autoload.php
  • 46. UsingThe Libraries
  • 47. UsingThe Libraries require_once 'vendor/autload.php';
  • 48. UsingThe Libraries require_once 'vendor/autload.php'; Include the libraries
  • 49. UsingThe Libraries require_once 'vendor/autload.php'; Include the libraries Start using it
  • 50. UsingThe Libraries require_once 'vendor/autload.php'; Include the libraries Start using it As simple as that
  • 51. Installing, Updating And Moving On How does Composer guarantee consistency?
  • 52. composer.json composer.lock
  • 53. composer.json composer.lock Metadata and list your dependencies
  • 54. composer.json composer.lock Metadata and list your dependencies Existing dependencies and current commit hashes
  • 55. composer.json composer.lock
  • 56. composer.json composer.lock Update
  • 57. composer.json composer.lock Update
  • 58. composer.json composer.lock Update reads
  • 59. composer.json composer.lock Update reads
  • 60. composer.json composer.lock Update reads gets latest
  • 61. composer.json composer.lock Update reads gets latest
  • 62. composer.json composer.lock Update reads gets latest writes
  • 63. composer.json composer.lock Update Install reads gets latest writes
  • 64. composer.json composer.lock Update Install reads gets latest writes
  • 65. composer.json composer.lock Update Install reads gets latest writes reads
  • 66. composer.json composer.lock Update Install reads gets latest writes reads
  • 67. composer.json composer.lock Update Install reads gets latest writes reads compares
  • 68. composer.json composer.lock Update Install reads gets latest writes reads compares
  • 69. composer.json composer.lock Update Install reads gets latest writes reads compares gets locked version
  • 70. KeepTheTeam OnThe Same Page • Commit composer.lock into the repository • Use composer install • Ignore the vendor directory
  • 71. A Contributor Appears
  • 72. A Contributor Appears $ git clone git@github.com:tareq1988/composer-test.git
  • 73. A Contributor Appears $ git clone git@github.com:tareq1988/composer-test.git $ composer install
  • 74. A Contributor Appears $ git clone git@github.com:tareq1988/composer-test.git $ composer install
  • 75. A Contributor Appears $ git clone git@github.com:tareq1988/composer-test.git $ composer install
  • 76. A Contributor Appears $ git clone git@github.com:tareq1988/composer-test.git $ composer install Lock File
  • 77. Adding A New Package $ composer.phar require symfony/yaml=~2.1.0
  • 78. Finding A Package
  • 79. https://packagist.org/
  • 80. How Do I LoadThe Files? PSR-0 and the modern autoloader
  • 81. Composer Generates A Autoload File For AllYour Dependencies vendor/autoload.php
  • 82. Types Of Autoloading
  • 83. PSR-4 is the recommended way Types Of Autoloading
  • 84. PSR-4 is the recommended way Types Of Autoloading PSR-0 auto loading
  • 85. PSR-4 is the recommended way Types Of Autoloading PSR-0 auto loading PEAR packages and other libraries
  • 86. PSR-4 is the recommended way Types Of Autoloading PSR-0 auto loading PEAR packages and other libraries PHP Functions and helpers
  • 87. PSR What? PHP FIG: PHP Framework Interop Group PSR-0:Autoloading Standard
 PSR-1: Basic Coding Standard
 PSR-2: Coding Style Guide
 PSR-3: Logger Interface
 PSR-4: Improved Autoloading: http://www.php-fig.org/
  • 88. PSR What? PHP FIG: PHP Framework Interop Group PSR-0:Autoloading Standard
 PSR-1: Basic Coding Standard
 PSR-2: Coding Style Guide
 PSR-3: Logger Interface
 PSR-4: Improved Autoloading: http://www.php-fig.org/ Post Standards Recommendation
  • 89. OptimisingThe Autoloader • Adding huge library slows down • It calls file_exists every time
  • 90. OptimisingThe Autoloader • Adding huge library slows down • It calls file_exists every time $ composer dump-autoload -o
  • 91. OptimisingThe Autoloader • Adding huge library slows down • It calls file_exists every time $ composer dump-autoload -o
  • 92. OptimisingThe Autoloader • Adding huge library slows down • It calls file_exists every time $ composer dump-autoload -o Optimize flag
  • 93. 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
  • 94. I Am Developing A Library How Composer can spread my library around?
  • 95. https://packagist.org/about
 http://semver.org/
  • 96. https://packagist.org/about
 http://semver.org/ Name of the library
  • 97. https://packagist.org/about
 http://semver.org/ Name of the library Description
  • 98. https://packagist.org/about
 http://semver.org/ Name of the library Description tag
  • 99. https://packagist.org/about
 http://semver.org/ Name of the library Description tag About you
  • 100. https://packagist.org/about
 http://semver.org/ Name of the library Description tag About you Autoloader type
  • 101. 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
  • 102. Find Out More http://getcomposer.org https://packagist.org https://github.com/composer composer-dev google group #composer & #composer-dev
  • 103. Can I Use Composer with WordPress? http://wpackagist.org/ http://composer.rarst.net/resources
  • 104. Thats All
  • 105. Tareq Hasan @tareq_cse Founder, Lead Developer - weDevs http://tareq.weDevs.com http://wedevs.com
  • 106. Thanks