Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊

10,013 views

Published on

對於 PHP 開發者而言,使用 Composer 處理套件相依已是標準程序,對於習於使用框架的開發者而言更是如此。但也往往因為太習以為常,導致僅會使用基本指令而忽略進階技巧。

在這場講座裡,講者將從日常開發工作中汲取出幾個常見情境,依此脈絡分享數個關於 Composer 的使用錦囊,做為進一步認識 Composer 核心的敲門磗,期盼能讓更多 PHP 開發者熟悉自己的工具。

Published in: Technology
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ❶❶❶ http://bit.ly/369VOVb ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ♥♥♥ http://bit.ly/369VOVb ♥♥♥
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

[Modern Web Conf 2015] 給 PHP 開發者的 Composer 錦囊

  1. 1. PHP Composer 話 Shengyou Fan ‧ 學友 2015/05/16
  2. 2. 范聖佑 @shengyou http://www.shengyoufan.com https://www.facebook.com/shengyoufan 得寬科技 研究員 Laravel 台灣 傳教士 Laravel Dojo 作者
  3. 3. 2015 Modern Web Conference 7 話 1. Composer 2. Skeleton 3. 起⽅方 4. composer.lock 5. 的 repositories 6. VM 會 Composer 7. Satis/Toran Proxy 有
  4. 4. 話11 1Composer
  5. 5. Composer 要
  6. 6. 2015 Modern Web Conference Composer • Composer 種 (這 只 ) • ( Bug ) • Composer ( "^") • Composer (樣 ) 間 PHP ⽂文 多 在
  7. 7. $1[sudo]1composer1self7update
  8. 8. $1[sudo]1composer1self7update177rollback ( 沒 好 ) …
  9. 9. #1 1VM1provision1 1Composer1 config.vm.provision1"shell"1do1|s|1 11s.inline1=1"/usr/local/bin/composer1self7update"1 end ( 1Vagrantfile1 ) $1vagrant1provision ( 1VM1Host1 ) 間 你能 https://github.com/laravel/homestead/blob/master/scripts/homestead.rb#L144-L147
  10. 10. $1vagrant1plugin1install1vagrant7triggers ( 1VM1Host1 ) 間 https://github.com/emyl/vagrant-triggers 1vagrant7triggers1 什
  11. 11. #1 1VM1up1 1Composer1 config.trigger.after1:up1do1 11run1"vagrant1ssh17c1'sudo1/usr/local/bin/composer1 self7update'"1 end ( 1Vagrantfile1 ) 間 http://docs.vagrantup.com/v2/cli/ssh.html $1vagrant1up ( 1VM1Host1 )
  12. 12. d(`・ ・)b ( )
  13. 13. 2015 Modern Web Conference Composer • Composer (!) • 沒 ⽂文 想 • 還 地⽂文好天起第現出 • •
  14. 14. composer 有 php 5.3.4 + openssl git + + 1Composer1
  15. 15. 間 wagon 上 https://www.youtube.com/watch?v=O7ynMSd0Tlo
  16. 16. 話12 1Skeleton
  17. 17. $1composer1create7project1laravel/laravel177prefer7dist ( composer laravel skeleton)
  18. 18. 2015 Modern Web Conference Skeleton • 經三 skeleton 三⼜又 • packages第scripts • github第 tag • Packagist package • composer package create-project 間 你能他 然⽽而 https://packagist.org/packages/jaceju/b5 $1composer1create7project1jaceju/b51[project7name]17s1dev
  19. 19. $1laravel1new1[project7name] (會 ++) 間 來 http://laravel.com/docs/5.0#install-laravel laravel-installer laravel skeleton
  20. 20. 2015 Modern Web Conference laravel-installer • laravel/laravel ⽂文 composer1install • 事 vendor 中 回 每 zip ⽂文 • 裡 laravel7installer ⼈人⽤用 ⽂文 new - http://cabinet.laravel.com/latest.zip 啊 zip - 每 post7create7project7cmd
  21. 21. 間 來 zipper https://github.com/laravel/installer/blob/master/zipper.sh wget1https://github.com/laravel/laravel/archive/master.zip1 unzip1master.zip17d1working1 cd1working/laravel7master1 composer1install1 zip17ry1../../laravel7craft.zip1.1 cd1../..1 mv1laravel7craft.zip1public/laravel7craft.zip1 rm17rf1working1 rm1master.zip (laravel-installer zipper)
  22. 22. 話13 起⽅方
  23. 23. "vendor/package":1"dev7master" (composer.json)
  24. 24. ( 1composer1show177installed1活 )
  25. 25. Composer ⽅方 dev-master
  26. 26. 2015 Modern Web Conference X Y Z Major Breaks Minor Features Patch Fixes . .
  27. 27. 2015 Modern Web Conference 0.1.0 0.2.0 1.0.1 1.1.0 0.1.1 1.0.0 1.0.2 2.0.0 1 1 1 動 1 1 動 1 動 動 1 動 1
  28. 28. 2015 Modern Web Conference Version Constraints Exact Match 1.2.3 1.2.3 Wildcard Range 1.0.* >=1.0 發 <1.1 Hyphen Range 1.0 - 2.0 >=1.0.0 發 <2.1 Tilde Operator ~1.2 >=1.2 發<2.0 Caret Operator ^1.2.3 ^0.3 >=1.2.3 發 <2.0 >=0.3.0 發 <0.4.0 Stability Flags @stable @dev dev > alpha > beta > RC > stable 開看啊 stable⽂文 @ ⼈人
  29. 29. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^明^ Composer 裡 ⽂文 地之 ( AWS ElasticBeanstalk Composer 1.0.0-alpha9)⽂文 明~ ⽂文 X < 0 package
  30. 30. 2015 Modern Web Conference ⽅方個 • 時 機 SemVer 後然 • 麼 dev-master 動 • 多 在 Packagist ⽂文真 ⽅方 ( Package 機 SemVer ⽂文 Caret Operator) • ⽅方個 ⽂文 Packagist Semver Checker 很 個 • composer.json ⽂文 composer validate 活
  31. 31. 話14 1composer.lock1 ( 個1application1 )
  32. 32. /bootstrap/compiled.php1 /vendor1 composer.phar1 composer.lock1 .env.*.php1 .env.php1 .DS_Store1 Thumbs.db (laravel/laravel14.1.*1 1.gitignore)
  33. 33. (lock1 ) After1installing1the1dependencies,1Composer1writes1 the1list1of1the1exact1versions1it1installed1into1a1 composer.lock1file. This1locks1the1project1to1those1specific1versions. 間 來 https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
  34. 34. 1. 活 1composer.lock1 可 1 2. 可 ⽂文 ⾃自1composer1update1 到 1 3. 可 ⽂文 1lock1 1package1 $1composer1install 間 你能 https://blog.engineyard.com/2014/composer-its-all-about-the-lock-file
  35. 35. $1composer1update 間 你能 https://blog.engineyard.com/2014/composer-its-all-about-the-lock-file 1. 活 1composer.json1 1 2. 看 ⽂文 1 3. 1packages1 4. 1composer.lock
  36. 36. {1 11"require7dev":1{1 1111"guidovanbiemen/laravel7whoops":1"1.0.1",1 1111"fzaninotto/faker":1"v1.4.0",1 1111"phpunit/phpunit":1"~4.0",1 1111"phpspec/phpspec":1"~2.1"1 11}1 } composer.json (require7dev1 主 1Production1 )
  37. 37. $1composer1install177prefer7dist11 77no7dev177optimize7autoloader ( 主 1install1 1lock1 ) 間 Composer 開看 dev 就⽂文 --no-dev 無 require-dev 間 --prefer-dist 啊 package archives clone source 間 --optimize-autoloader 到 autoloader
  38. 38. (Jordi1 1lock1 ) 間 https://www.youtube.com/watch?v=mNFKZeYRdto 間 http://slides.seld.be/?file=2015-02-19+Composer+Best+Practices.html#1
  39. 39. /vendor1 /node_modules1 .env (laravel/laravel15.0.*1 1.gitignore)
  40. 40. 話15 的 1repositories
  41. 41. 2015 Modern Web Conference • forked package - package⽂文 package patch ⽂文 hot-fix • 們 private package - 們 才 package⽂文 ⼀一 Packagist Composer 有
  42. 42. {1 1111"repositories":1[1 11111111{1 111111111111"type":1"vcs",1 111111111111"url":1"{url}"1 11111111}1 1111],1 1111"require":1{1 11111111"vendor/package":1"{version}"1 1111}1 } 間1version:1x.y.z1 間1version:1dev7master1as1x.y.z composer.json 間 看 forked https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository 間 private package https://getcomposer.org/doc/05-repositories.md#using-private-repositories 間1url:1https://github.com/vendor/package1 間1url:1https://account@bitbucket.org/account/repo.git
  43. 43. (要然 forked hot-fix )
  44. 44. (要然 forked hot-fix )
  45. 45. (要然 private package)
  46. 46. (要然 private package)
  47. 47. {1 1111"http7basic":1{1 11111111"bitbucket.org":1{1 111111111111"username":1"my7bitbucket7account",1 111111111111"password":1"my7bitbucket7password"1 11111111}1 1111}1 } (看 1Private1Repository1 很) auth.json 間 auth.json gitignore 最 間 auth.json COMPOSER_HOME composer 啊
  48. 48. 話17 1VM1 會1Composer
  49. 49. 2015 Modern Web Conference間 也 @pborreli 間 也 @n_chaulet
  50. 50. sudo1apt7get1install1software7properties7common1 sudo1apt7key1adv177recv7keys177keyserver11 hkp://keyserver.ubuntu.com:8010x5a16e7281be7a4491 sudo1add7apt7repository111 'deb1http://dl.hhvm.com/ubuntu1trusty1main'1 sudo1apt7get1update1 sudo1apt7get1install1hhvm ( ) install1HHVM1on1Ubuntu114.04 間 來 https://github.com/facebook/hhvm/wiki/Prebuilt-packages-on-Ubuntu-14.04
  51. 51. alias1homposer="hhvm17v1 ResourceLimit.SocketDefaultTimeout=3017v1 Http.SlowQueryThreshold=3000017v1 Eval.Jit=false1/usr/local/bin/composer" (看 1alias1 ⼀一 ) 1.bashrc1 間 https://blog.engineyard.com/2014/hhvm-hack-part-2
  52. 52. 間 https://twitter.com/Elroubio/status/583414360350949376 ( 1PHP171 )
  53. 53. 間 你能中 http://talks.php.net/fluent15#/php_contribute2 Thanks!1Dad $1git1clone1https://github.com/rlerdorf/php7dev.git1 $1cd1php7dev1 $1vagrant1up1 $1vagrant1ssh $1makephp171 $1newphp171 Activating1PHP17.0.01and1restarting1php7fpm1 $1composer ( 1VM1Host1 ) ( 1VM1Guest1 )
  54. 54. 話18 1Satis/Toran1Proxy1有
  55. 55. 2015 Modern Web Conference 會 Composer • Composer 會 • ⽂文 會 • Composer Packagist • Composer repositories • 快 Composer 開
  56. 56. 間 你能中 https://github.com/composer/satis
  57. 57. 2015 Modern Web Conference Satis Satis Composer Packagist Satis 知 Satis Packagist 著 Satis 間 三⼜又 你能 http://goo.gl/sxLQEn
  58. 58. 間 你能中 https://toranproxy.com/
  59. 59. 2015 Modern Web Conference Toran Proxy Toran Proxy Composer Packagist Toran Proxy Toran Proxy Packagist 著 Toran Proxy
  60. 60. 2015 Modern Web Conference Toran Proxy • Proxy • ( ) Web UI 做 • Git 看 • Event Hook 看 • Satis Migrate • … 間 都 ⽂文 能 等 ⼤大⽣生 Composer
  61. 61. 2015 Modern Web Conference • 話 - skeleton repositories - 無 Composer 看 - 不 Composer ⼈人⽤用 - composer.lock 主 會 感 - VM 會 Composer - Satis/Toran Proxy 有 會
  62. 62. ( 增 3增)y 意 話 Composer
  63. 63. 2015 Modern Web Conference Composer ⼈人我 Laravel Composer 話更 https://goo.gl/OfJK3C email⽂文 就 ⼼心 Composer 話 • vagrant 感 • global • 讓去給 要然…
  64. 64. Laravel 台灣 致力在台灣推廣 Laravel Framework 並 建立專屬的正體中文社群,目前已完成 官方文件的翻譯,每月有三次固定的聚 會活動。 https://goo.gl/h2m5Tq1 Guys!1We1did1a1great1job!
  65. 65. PHP 也有 Day 台北的 PHP 開發者聚會,每月固定會有 一次的分享講座,邀請有經驗的開發者 前來分享開發經驗。 https://goo.gl/rzEFuE1 Ricky!1We1love1you~
  66. 66. Laradiner PHP/Laravel 的讀書會,目前每月固定 舉辦兩次,歡迎對 PHP/Laravel 有興趣 的朋友參與。目前正在進行的是 Modern PHP 的導讀活動! https://goo.gl/AmiWG7
  67. 67. Sam,1you1are1awesome!
  68. 68. 2015 Modern Web Conference Modern PHP (Laradiner ) https://goo.gl/LUc2IG1 ⽂文 好得 是 說 新 Facebook Events
  69. 69. 2015 Modern Web Conference Q & A

×