{"id":44605,"date":"2025-04-19T14:25:45","date_gmt":"2025-04-19T06:25:45","guid":{"rendered":"https:\/\/www.gwlin.com\/blog\/?p=44605"},"modified":"2025-04-19T14:28:57","modified_gmt":"2025-04-19T06:28:57","slug":"php-composer-%e5%ae%89%e8%a3%85%e7%a7%81%e6%9c%89%e5%ba%93%e7%9a%84%e7%ae%80%e4%be%bf%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.gwlin.com\/blog\/posts\/44605","title":{"rendered":"php composer \u5b89\u88c5\u79c1\u6709\u5e93\u7684\u7b80\u4fbf\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u4e3a\u81ea\u5df1\u7684\u79c1\u6709\u63a5\u53e3\u5c01\u88c5\u4e86\u4e00\u4e2a\u79c1\u6709\u5e93\uff0c\u60f3\u8981\u80fd\u591f composer \u5b89\u88c5\uff0c\u65b9\u4fbf\u5728\u591a\u4e2a\u9879\u76ee\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u76f4\u63a5\u53d1\u5e03\u5230 packagist \u4e0d\u5408\u9002\u3002\u4e00\u4e2a\u65b9\u6848\u662f\u642d\u5efa\u79c1\u6709\u7684 packagist\uff0c\u53c2\u8003 packagist.com\u3002\u4f46\u8fd9\u6837\u53c8\u592a\u5927\u5de5\u7a0b\u4e86\uff0c\u6740\u9e21\u7528\u725b\u5200\u3002<\/p>\n\n\n\n<p>\u6211\u5728\u4e4b\u524d\u5c31\u5df2\u7ecf\u7528 gitea \u642d\u5efa\u4e86\u81ea\u5df1\u7684\u79c1\u6709 git \u4ed3\u5e93\uff0c\u6240\u4ee5\u6211\u7684\u60f3\u6cd5\u662f composer require\/install\/update \u80fd\u591f\u4ece\u6211\u7684\u79c1\u6709\u4ed3\u5e93\u62c9\u53d6\u6700\u65b0\u7248\u672c\uff0c\u7136\u540e\u5b89\u88c5\u3002<\/p>\n\n\n\n<p>google \u4e86\u4e00\u4e0b\uff0ccomposer \u672c\u8eab\u662f\u652f\u6301\u672c\u5730\u5b89\u88c5\u7684\uff0c\u53c2\u8003\uff1a<a href=\"https:\/\/getcomposer.org\/doc\/05-repositories.md#path\">https:\/\/getcomposer.org\/doc\/05-repositories.md#path<\/a><\/p>\n\n\n\n<p>\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >...\n\u251c\u2500\u2500 apps\n\u2502   \u2514\u2500\u2500 my-app\n\u2502       \u2514\u2500\u2500 composer.json\n\u251c\u2500\u2500 packages\n\u2502   \u2514\u2500\u2500 my-package\n\u2502       \u2514\u2500\u2500 composer.json\n...<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >{\n    &quot;repositories&quot;: &#091;\n        {\n            &quot;type&quot;: &quot;path&quot;,\n            &quot;url&quot;: &quot;..\/..\/packages\/my-package&quot;\n        }\n    ],\n    &quot;require&quot;: {\n        &quot;my\/package&quot;: &quot;*&quot;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u5bb9\u6613\u60f3\u5230\uff0c\u624b\u52a8\u4ece\u4ed3\u5e93\u4e0b\u8f7d\u5305\u4e0b\u6765\uff0c\u89e3\u538b\u5230\u4e00\u4e2a\u76ee\u5f55\uff0c\u914d\u7f6e\u4e00\u4e0b composer.json \u5c31\u597d\u4e86\u3002\u4f46\u80fd\u4e0d\u80fd\u66f4\u81ea\u52a8\u5316\u4e00\u70b9\u5462\uff1f\u628a\u8fd9\u4e2a\u64cd\u4f5c\u81ea\u52a8\u5b8c\u6210\u5462\uff1f<\/p>\n\n\n\n<p>\u8054\u60f3\u5230 composer \u6709\u4e00\u4e9b hook \uff0c\u53ef\u4ee5\u5728\u8fd0\u884c\u7684\u5404\u4e2a\u9636\u6bb5\u81ea\u5b9a\u4e49\u4e00\u4e9b\u547d\u4ee4\uff0c\u54c8\uff01\u4e8e\u662f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >{\n    &quot;require&quot;:{\n        &quot;xxx&quot;:&quot;*&quot; \/\/ xxx \u4f60\u81ea\u5df1\u7684\u5305\n    }\n    &quot;scripts&quot;: {\n        &quot;pre-install-cmd&quot;: &#091;\n            &quot;rm -rf .\/packages\/xxx &amp;&amp; git clone --depth=1 ssh:\/\/xxx.git .\/packages\/xxx &amp;&amp; rm -rf .\/packages\/xxx\/.git&quot;,\n            &quot;composer config repositories.xxx path .\/packages\/xxx&quot;\n        ],\n        &quot;pre-update-cmd&quot;: &#091;\n            &quot;rm -rf .\/packages\/xxx &amp;&amp; git clone --depth=1 ssh:\/\/xxx.git .\/packages\/xxx &amp;&amp; rm -rf .\/packages\/xxx\/.git&quot;,\n            &quot;composer config repositories.xxx path .\/packages\/xxx&quot;\n        ],\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u914d\u7f6e\u5728 composer.json \u7684 scripts \u91cc\u3002\u5176\u4f5c\u7528\u662f\uff1a<\/p>\n\n\n\n<p>\u5728\u5b89\u88c5\u4e4b\u524d\uff0c\u5220\u9664 packages \u4e0b\u5bf9\u5e94\u540d\u79f0\u7684\u79c1\u6709\u5305\uff08\u5426\u5219git\u62a5\u9519\uff1a\u76ee\u5f55\u4e0d\u4e3a\u7a7a\uff09\uff0cgit clone \u4e0b\u8f7d\u5305\uff0c\u5220\u6389 .git \u53bb\u6389\u7248\u672c\u7ba1\u7406\u3002\u7136\u540e composer config \u4ed3\u5e93\u4f7f\u7528\u4e0b\u8f7d\u4e0b\u6765\u7684\u5305\u7684\u8def\u5f84\u3002<\/p>\n\n\n\n<p>\u5b8c\u7f8e\uff01<\/p>\n\n\n\n<p>\ud83d\udc36<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u81ea\u5df1\u7684\u79c1\u6709\u63a5\u53e3\u5c01\u88c5\u4e86\u4e00\u4e2a\u79c1\u6709\u5e93\uff0c\u60f3\u8981\u80fd\u591f composer \u5b89\u88c5\uff0c\u65b9\u4fbf\u5728\u591a\u4e2a\u9879\u76ee\u4f7f\u7528\u3002 \u76f4\u63a5\u53d1\u5e03\u5230 pack [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[179],"tags":[186],"class_list":["post-44605","post","type-post","status-publish","format-standard","hentry","category-notes","tag-php"],"_links":{"self":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/44605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/comments?post=44605"}],"version-history":[{"count":4,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/44605\/revisions"}],"predecessor-version":[{"id":44609,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/posts\/44605\/revisions\/44609"}],"wp:attachment":[{"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/media?parent=44605"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/categories?post=44605"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gwlin.com\/blog\/wp-json\/wp\/v2\/tags?post=44605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}