ป้ายกำกับ: Package Manager

สร้าง project ใหม่โดยใช้ composerสร้าง project ใหม่โดยใช้ composer

เดี่ยวนี้ framework ต่าง ๆ ก็ใช้ package manager อย่าง composer ติดตั้ง library ต่าง ๆ รวมทั้งติดตั้ง framework อื่น ๆ อย่าง jQuery ถ้าต้องการที่จะสร้างโครงการของเราเองก็ทำได้ง่าย ๆ

  1. สร้าง folder ใหม่ขึ้นมา เช่น C:\xampp\htdocs\snippets
  2. พิมพ์

    PHP

    composer init
    
  3. ตอบคำถามไปตามละดับ เช่น

    PHP

    D:\>cd D:\xampp\htdocs\snippets D:\xampp\htdocs\snippets>composer init Welcome to the Composer config generator This command will guide you through creating your composer.json config. Package name (<vendor>/<name>) &#x5B;pitt.p/snippets]: pitt/snippets
    Description &#x5B;]: code snippets
    Author &#x5B;, n to skip]: Pitt Phunsanit <[email protected]>
    Minimum Stability &#x5B;]: stable
    Package Type (e.g. library, project, metapackage, composer-plugin) &#x5B;]: project
    License &#x5B;]: mit Define your dependencies. Would you like to define your dependencies (require) interactively &#x5B;yes]? yes
    Search for a package: jquery Found 15 packages matching jquery &#x5B;0] components/jquery &#x5B;1] frameworks/jquery &#x5B;2] contao-components/jquery &#x5B;3] yiisoft/jquery &#x5B;4] etdsolutions/jquery &#x5B;5] ovidentia/jquery &#x5B;6] mygento/jquery &#x5B;7] quickapps-plugins/jquery &#x5B;8] intelogie/jquery &#x5B;9] apnet/jquery &#x5B;10] jquery/jquery &#x5B;11] yepsua/jquery4php &#x5B;12] venne/jquery2.0-module &#x5B;13] sonata-project/jquery-bundle &#x5B;14] blueimp/jquery-file-upload Enter package # to add, or the complete package name if it is not listed: 0
    Enter the version constraint to require (or leave blank to use the latest version) :
    
  4. ตอบคำถามไปเรื่อย ๆ รูปแบบ packages จะสัมพันกับ url ใน github เช่น https://github.com/jquery/jquery ถ้าไม่ทราบหาได้ขากเว้บ packagist.org จนสุดท้ายจะสร้างไฟล์ composer.json ขึ้นมา
    { "authors": [{ "email": "[email protected]", "homepage": "https://pitt.plusmagi.com/", "name": "pitt phunsanit", "role": "Developer" }], "description": "snippet", "homepage": "https://pitt.plusmagi.com/", "license": "mit", "minimum-stability": "stable", "name": "pitt/snippet", "require": { "ckeditor/ckeditor": "*", "components/jquery": "*", "components/jquery-migrate": "*", "components/jqueryui": "*", "phpoffice/phpexcel": "^1.8", "twbs/bootstrap": "*" }, "type": "project"
    }
  5. โหลด library โดยคำสั่ง

    PHP

    composer update
    

ไฟล์จุถูกเก็บในโฟลเดอร์ vendor/xxx/yyy อย่างเรียบร้อยและเหมือนกันทุกเครื่องถ้าลง package เดียวกัน version เดียวกัน