½ÌÄãÐû²¼×Ô¼ºµÄcomposer°ü£¨°ì·¨Ïê½â£©
±¾ÆªÎÄÕ¸ø¸÷ÈË´øÀ´Á˹ØÓÚcomposerµÄÏà¹Ø֪ʶ£¬ÆäÖÐÖ÷Òª¸ú¸÷ÈËÁÄÒ»ÁÄ£¬ÔõôÐû²¼×Ô¼ºµÄcomposer°ü£¬°ì·¨ºÜÏêϸŶ~¸ÐÐËȤµÄÅóÙÏÂÃæÒ»ÆðÀ´¿´Ò»Ï°ɣ¬Ï£Íû¶Ô¸÷ÈËÓÐ×ÊÖú¡£
×¼±¸
GithubÕ˺Å
packagistÕ˺Å
×°ÖúÃgit
×°ÖúÃcomposer
°ì·¨
½¨Éè²¢ÀÈ¡Ò»¸ö¿ÍÕ»
GithubÓÒÉϽÇ+ºÅ£¬µã New repository¡£½¨ÉèÍê³ÉºóʹÓÃgitÀÈ¡µ½ÍâµØ¡£
composer³õʼ»¯
×Ô¶¯½¨Éè
ʹÓÃcomposer initÏÂÁî¾ÙÐгõʼ»¯
composer init
µÇ¼ºó¸´ÖÆ
¦Ë composer init Welcome to the Composer config generator ½Ó´ýÀ´µ½ComposerÉèÖÃÌìÉúÆ÷ This command will guide you through creating your composer.json config. Õâ¸öÏÂÁָµ¼Äú½¨Éè±àдÆ÷¡£jsonÉèÖᣠPackage name (<vendor>/<name>) [z/lattice-php]: // ÄãµÄ°üÃû£¬²»¿ÉÒÔÖظ´ Description []: // ÄãµÄÐÎò Author [Chenilove <2665468087@qq.com>, n to skip]: // ×÷Õß Minimum Stability []: // °æ±¾ÎȹÌÐÔ ÀýÈç dev stable µÈ Package Type (e.g. library, project, metapackage, composer-plugin) []: // °üÀàÐÍ License []: MIT // ÐÒé Define your dependencies. Would you like to define your dependencies (require) interactively [yes]? ÄãÏë½»»¥Ê½µØ½ç˵ÄãµÄÒÀÀµ¹ØϵÂð Search for a package: Would you like to define your dev dependencies (require-dev) interactively [yes]? ÄúÏë½»»¥Ê½µØ½ç˵ÄúµÄ¿ª·¢ÒÀÀµÏî(require-dev)Âð Search for a package: Add PSR-4 autoload mapping? Maps namespace "Z\LatticePhp" to the entered relative path. [src/, n to skip]: Ìí¼ÓPSR-4×Ô¶¯¼ÓÔØÓ³Éä?½«ÃüÃû¿Õ¼ä¡°Z\LatticePhp¡±Ó³Éäµ½ÊäÈëµÄÏà¶Ô·¾¶¡£ { "name": "z/lattice-php", "license": "MIT", "autoload": { "psr-4": { "Z\\LatticePhp\\": "src/" } }, "authors": [ { "name": "Chenilove", "email": "2665468087@qq.com" } ], "require": {} } Do you confirm generation [yes]? È·¶¨ÌìÉúÂ𣿠Generating autoload files Generated autoload files PSR-4 autoloading configured. Use "namespace Z\LatticePhp;" in src/ Include the Composer autoloader with: require 'vendor/autoload.php';
µÇ¼ºó¸´ÖÆ
ÊÖ¶¯½¨Éè
ʵÖÊÉÏcomposer initÏÂÁîÊÇÔÚ¸ùĿ¼½¨ÉèÒ»¸öcomposer.json£¬ÎÒÃÇÍêÈ«¿ÉÒÔ×Ô¼ºÊÖ¶¯½¨Éè
{ "name": "zmxy/lattice", "description": "PHPÌìÉúµãÕóͼ×é¼þ.½Ì³Ì£ºhttps://github.com/Chenilove/LatticePHP", "license": "MIT", "autoload": { "psr-4": { "Lattice\\": "src/" } }, "authors": [ { "name": "Chenilove", "email": "2665468087@qq.com" } ], "minimum-stability": "stable", "require": { "php": ">=7.1.0" } }
µÇ¼ºó¸´ÖÆ
autoload×Ô¶¯¼ÓÔØ
autoloadÕâ¸öÑ¡ÏîºÜÖ÷Òª£¬ÕâÀï»®¶¨ÁËÃüÃû¿Õ¼ä¡£¼ÙÉèÄãÏëÔÙ¼ÓÒ»¸öÃüÃû¿Õ¼ä£¬Äã¿ÉÒÔÕâÑù×ö
"autoload": { "psr-4": { "Lattice\\": "src/" Ú¹ÊÍ£º "ÃüÃû¿Õ¼ä\\": "°üµÄÏà¶Ô·¾¶", } },
µÇ¼ºó¸´ÖÆ
ÿ´ÎÐ޸ĵÃʹÓÃÏÂÁîË¢ÐÂ
composer dump-autoload
µÇ¼ºó¸´ÖÆ
½¨Éè´úÂë
ÕâÀï¶ÔÓ¦ÉÏÃæµÄautoload->psr-4ÄÚÀïµÄÉèÖã¬ÏȽ¨ÉèÒ»¸ösrcĿ¼£¬È»ºóÔÚÄÚÀïдÄãµÄ´úÂë¡£
namespace Lattice; /** * Class Lattice */ class Lattice { public function index() { echo "ºÙºÙºÙ"; } }
µÇ¼ºó¸´ÖÆ
Ìá½»½ÓÂëµ½Github
ʹÓÃgitÌá½»½ÓÂëµ½Github¿ÍÕ»
Ìá½»µ½packagist
Ïȸ´ÖÆGithub¿ÍÕ»µØµã£¨ÀýÈ磺github.com/Chenilove/LatticePHP.gi…)
·¿ªpackagist£¬µã»÷ÓÒÉϽǵÄSubmit
½«¿ÍÕ»µØµãÌîÈëRepository URL£¬È»ºóµã»÷Check
×îºó»Øµ½Github£¬ReleaseÒ»¸ö°æ±¾£¬packagist¾ÍÄÜ×Ô¶¯¸üÐÂ
µ½´ËÒѾÀÖ³ÉÐû²¼ÁËÒ»¸öcomposer°ü£¬Ã¿´ÎReleaseÒ»¸ö°æ±¾Ê±£¬packagist¶¼»á×Ô¶¯¸üС£
ÍƼöѧϰ£º¡¶composerʹÓý̡̳·
ÒÔÉϾÍÊǽÌÄãÐû²¼×Ô¼ºµÄcomposer°ü£¨°ì·¨Ïê½â£©µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡