{"id":47172,"date":"2024-12-02T13:57:07","date_gmt":"2024-12-02T05:57:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47172\/"},"modified":"2024-12-02T13:57:07","modified_gmt":"2024-12-02T05:57:07","slug":"%e4%bd%bf%e7%94%a8%e7%ac%ac%e4%b8%89%e6%96%b9-php-%e5%87%bd%e6%95%b0%e7%ae%a1%e7%90%86%e4%be%9d%e8%b5%96%e6%80%a7","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47172\/","title":{"rendered":"\u4f7f\u7528\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7ba1\u7406\u4f9d\u8d56\u6027"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u4f7f\u7528\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7ba1\u7406\u4f9d\u8d56\u6027<\/h1>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4f7f\u7528\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7ba1\u7406\u4f9d\u8d56\u6027\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>\u4f7f\u7528 Composer \u7ba1\u7406 PHP \u4f9d\u8d56\u6027\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u9879\u76ee\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u9760\u6027\u3002Composer \u901a\u8fc7\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u5173\u7cfb\u5e76\u5b89\u88c5\u6240\u9700\u7684\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002\u901a\u8fc7\u5b9a\u4e49 packages.json \u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u58f0\u660e\u4f9d\u8d56\u5173\u7cfb\uff0c\u7136\u540e\u4f7f\u7528 composer install \u547d\u4ee4\u5b89\u88c5\u5b83\u4eec\u3002Composer \u5c06\u89e3\u6790\u4f9d\u8d56\u5173\u7cfb\uff0c\u4e0b\u8f7d\u5e93\u5e76\u5c06\u5176\u5b89\u88c5\u5230 vendor \u6587\u4ef6\u5939\u4e2d\u3002\u81ea\u52a8\u52a0\u8f7d\u4f9d\u8d56\u5173\u7cfb\u540e\uff0c\u9879\u76ee\u5c31\u53ef\u4ee5\u5229\u7528\u5df2\u5b89\u88c5\u7684\u5e93\uff0c\u907f\u514d\u51b2\u7a81\u5e76\u4fdd\u6301\u6700\u65b0\u72b6\u6001\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729902504671c37a82e42b.jpg\" class=\"aligncenter\" title=\"\u4f7f\u7528\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7ba1\u7406\u4f9d\u8d56\u6027\u63d2\u56fe\" alt=\"\u4f7f\u7528\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7ba1\u7406\u4f9d\u8d56\u6027\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4f7f\u7528 Composer \u7ba1\u7406 PHP \u4f9d\u8d56\u6027<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u5728 PHP \u5f00\u53d1\u4e2d\uff0c\u7ba1\u7406\u4f9d\u8d56\u6027\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4f9d\u8d56\u6027\u662f\u6307\u4e00\u4e2a\u9879\u76ee\u4f9d\u8d56\u4e8e\u5176\u4ed6\u5e93\u6216\u8f6f\u4ef6\u5305\u624d\u80fd\u6b63\u5e38\u5de5\u4f5c\u7684\u5916\u90e8\u4ee3\u7801\u3002\u7b2c\u4e09\u65b9\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8f7b\u677e\u5730\u5904\u7406\u548c\u7ba1\u7406 PHP \u4e2d\u7684\u4f9d\u8d56\u6027\u3002<\/p>\n<p><strong>Composer<\/strong><\/p>\n<p>Composer \u662f\u4e00\u4e2a\u6d41\u884c\u7684 PHP \u4f9d\u8d56\u9879\u7ba1\u7406\u5668\uff0c\u7528\u4e8e\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u5173\u7cfb\u5e76\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u540d\u4e3a packages.json \u7684\u6587\u4ef6\uff0c\u7528\u4e8e\u5b9a\u4e49\u9879\u76ee\u7684\u4f9d\u8d56\u6027\u3002Composer \u4f7f\u7528\u8be5\u6587\u4ef6\u6765\u89e3\u6790\u3001\u4e0b\u8f7d\u548c\u5b89\u88c5\u6240\u6709\u5fc5\u9700\u7684\u5e93\u3002<\/p>\n<p><strong>\u5b89\u88c5 Composer<\/strong><\/p>\n<p>\u8981\u5b89\u88c5 Composer\uff0c\u8bf7\u8bbf\u95ee\u5176\u5b98\u65b9\u7f51\u7ad9 https:\/\/getcomposer.org\/\u5e76\u6309\u7167\u8bf4\u660e\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u521b\u5efa packages.json \u6587\u4ef6<\/strong><\/p>\n<p>\u5728\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\u540d\u4e3a packages.json \u7684\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>{\n  \"require\": {\n    \"guzzlehttp\/guzzle\": \"^7.0\",\n    \"phpunit\/phpunit\": \"~9.0\"\n  }\n}<\/pre>\n<p>\u5728\u4e0a\u9762\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u8981\u6c42 Composer \u5b89\u88c5 Guzzle HTTP \u5e93\u548c PHPUnit \u6d4b\u8bd5\u6846\u67b6\u3002<\/p>\n<p><strong>\u5b89\u88c5\u4f9d\u8d56\u9879<\/strong><\/p>\n<p>\u8981\u5b89\u88c5\u5b9a\u4e49\u7684\u4f9d\u8d56\u9879\uff0c\u8bf7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>composer install<\/pre>\n<p>Composer \u5c06\u89e3\u6790 packages.json \u6587\u4ef6\uff0c\u4e0b\u8f7d\u6240\u6709\u5fc5\u9700\u7684\u5e93\u5e76\u5c06\u5176\u5b89\u88c5\u5230 vendor \u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p><strong>\u8f7d\u5165\u4f9d\u8d56\u9879<\/strong><\/p>\n<p>\u5b89\u88c5\u4f9d\u8d56\u9879\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u7c7b\u4f3c\u4ee5\u4e0b\u7684autoload.php \u6587\u4ef6\u81ea\u52a8\u52a0\u8f7d\u5b83\u4eec\uff1a<\/p>\n<pre>require __DIR__ . '\/vendor\/autoload.php';<\/pre>\n<p>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u5df2\u5b89\u88c5\u7684\u5e93\uff1a<\/p>\n<pre>use GuzzleHttp\\Client;\n\n$client = new Client();\n$response = $client-&gt;get('https:\/\/example.com\/');<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4f7f\u7528 Composer \u7ba1\u7406\u4f9d\u8d56\u6027\u53ef\u663e\u7740\u63d0\u9ad8\u4f60\u7684 PHP \u9879\u76ee\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u9760\u6027\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><strong>\u81ea\u52a8\u66f4\u65b0\uff1a<\/strong> Composer \u53ef\u4ee5\u5b9a\u671f\u68c0\u67e5\u4f9d\u8d56\u9879\u66f4\u65b0\u5e76\u81ea\u52a8\u5b89\u88c5\u5b83\u4eec\uff0c\u786e\u4fdd\u4f60\u7684\u9879\u76ee\u59cb\u7ec8\u662f\u6700\u65b0\u7684\u3002<\/li>\n<li><strong>\u7248\u672c\u9501\u5b9a\uff1a<\/strong> packages.json \u6587\u4ef6\u9501\u5b9a\u4f9d\u8d56\u9879\u7684\u7279\u5b9a\u7248\u672c\uff0c\u9632\u6b62\u610f\u5916\u66f4\u65b0\u7834\u574f\u4f60\u7684\u9879\u76ee\u3002<\/li>\n<li><strong>\u51cf\u5c11\u51b2\u7a81\uff1a<\/strong> Composer \u786e\u4fdd\u5728\u4f60\u7684\u9879\u76ee\u4e2d\u4f7f\u7528\u4f9d\u8d56\u9879\u7684\u517c\u5bb9\u7248\u672c\uff0c\u9632\u6b62\u7248\u672c\u51b2\u7a81\u3002<\/li>\n<\/ul>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u4f7f\u7528\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\uff08\u5982 Composer\uff09\u7ba1\u7406\u4f9d\u8d56\u6027\u662f\u7b80\u5316 PHP \u5f00\u53d1\u6d41\u7a0b\u5e76\u786e\u4fdd\u9879\u76ee\u957f\u671f\u5065\u5eb7\u8fd0\u884c\u7684\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u4f7f\u7528\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7ba1\u7406\u4f9d\u8d56\u6027\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7ba1\u7406\u4f9d\u8d56\u6027 \u5b66\u4e60\u6587\u7ae0\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0\u300a\u4f7f\u7528\u7b2c\u4e09\u65b9 PHP \u51fd\u6570\u7ba1\u7406\u4f9d\u8d56\u6027\u300b\u5c06\u4f1a\u4ecb\u7ecd\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60\u6587\u7ae0\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01 \u4f7f\u7528 Composer \u7ba1\u7406 PHP \u4f9d\u8d56\u6027\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u9879\u76ee\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u9760\u6027\u3002Composer \u901a\u8fc7\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u5173\u7cfb\u5e76\u5b89\u88c5\u6240\u9700\u7684\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002\u901a\u8fc7\u5b9a\u4e49 packages.json \u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u58f0\u660e\u4f9d\u8d56\u5173\u7cfb\uff0c\u7136\u540e\u4f7f\u7528 composer install \u547d\u4ee4\u5b89\u88c5\u5b83\u4eec\u3002Composer \u5c06\u89e3\u6790\u4f9d\u8d56\u5173\u7cfb\uff0c\u4e0b\u8f7d\u5e93\u5e76\u5c06\u5176\u5b89\u88c5\u5230 vendor \u6587\u4ef6\u5939\u4e2d\u3002\u81ea\u52a8\u52a0\u8f7d\u4f9d\u8d56\u5173\u7cfb\u540e\uff0c\u9879\u76ee\u5c31\u53ef\u4ee5\u5229\u7528\u5df2\u5b89\u88c5\u7684\u5e93\uff0c\u907f\u514d\u51b2\u7a81\u5e76\u4fdd\u6301\u6700\u65b0\u72b6\u6001\u3002 \u4f7f\u7528 Composer \u7ba1\u7406 PHP \u4f9d\u8d56\u6027 \u7b80\u4ecb \u5728 PHP \u5f00\u53d1\u4e2d\uff0c\u7ba1\u7406\u4f9d\u8d56\u6027\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4f9d\u8d56\u6027\u662f\u6307\u4e00\u4e2a\u9879\u76ee\u4f9d\u8d56\u4e8e\u5176\u4ed6\u5e93\u6216\u8f6f\u4ef6\u5305\u624d\u80fd\u6b63\u5e38\u5de5\u4f5c\u7684\u5916\u90e8\u4ee3\u7801\u3002\u7b2c\u4e09\u65b9\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8f7b\u677e\u5730\u5904\u7406\u548c\u7ba1\u7406 PHP \u4e2d\u7684\u4f9d\u8d56\u6027\u3002 Composer Composer \u662f\u4e00\u4e2a\u6d41\u884c\u7684 PHP \u4f9d\u8d56\u9879\u7ba1\u7406\u5668\uff0c\u7528\u4e8e\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u5173\u7cfb\u5e76\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u540d\u4e3a packages.json \u7684\u6587\u4ef6\uff0c\u7528\u4e8e\u5b9a\u4e49\u9879\u76ee\u7684\u4f9d\u8d56\u6027\u3002Composer \u4f7f\u7528\u8be5\u6587\u4ef6\u6765\u89e3\u6790\u3001\u4e0b\u8f7d\u548c\u5b89\u88c5\u6240\u6709\u5fc5\u9700\u7684\u5e93\u3002 \u5b89\u88c5 Composer \u8981\u5b89\u88c5 Composer\uff0c\u8bf7\u8bbf\u95ee\u5176\u5b98\u65b9\u7f51\u7ad9 https:\/\/getcomposer.org\/\u5e76\u6309\u7167\u8bf4\u660e\u8fdb\u884c\u64cd\u4f5c\u3002 \u521b\u5efa packages.json \u6587\u4ef6 \u5728\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\u540d\u4e3a packages.json \u7684\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a { &#8220;require&#8221;: { &#8220;guzzlehttp\/guzzle&#8221;: &#8220;^7.0&#8221;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-47172","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=47172"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47172\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}