{"id":787,"date":"2014-10-07T13:44:14","date_gmt":"2014-10-07T05:44:14","guid":{"rendered":"http:\/\/blog.turn.tw\/?page_id=787"},"modified":"2014-10-07T17:49:14","modified_gmt":"2014-10-07T09:49:14","slug":"%e6%8c%87%e4%bb%a4%e5%88%97%e5%b7%a5%e5%85%b7%ef%bc%9aartisan","status":"publish","type":"page","link":"https:\/\/blog.turn.tw\/?page_id=787","title":{"rendered":"\u6307\u4ee4\u5217\u5de5\u5177\uff1aartisan"},"content":{"rendered":"<pre>\r\n#!\/usr\/bin\/env php\r\n<?php\r\n<\/pre>\n<p>\u6ce8\u610f\u7b2c1\u884c\uff0c\u5728\u6307\u4ee4\u5217\u7684\u67d0\u4e9b\u60c5\u6cc1\u4e0b\u624d\u9700\u8981\u3002<br \/>\n\u53c3\u898b\uff1a<a href=\"http:\/\/stackoverflow.com\/questions\/8737898\/is-usr-bin-env-required-to-run-php-from-command-line\">Is #!\/usr\/bin\/env required to run PHP from command line?<\/a><\/p>\n<pre>\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Register The Auto Loader\r\n|--------------------------------------------------------------------------\r\n|\r\n| Composer provides a convenient, automatically generated class loader\r\n| for our application. We just need to utilize it! We'll require it\r\n| into the script here so that we do not have to worry about the\r\n| loading of any our classes \"manually\". Feels great to relax.\r\n|\r\n*\/\r\n\r\nrequire __DIR__.'\/bootstrap\/autoload.php';\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Turn On The Lights\r\n|--------------------------------------------------------------------------\r\n|\r\n| We need to illuminate PHP development, so let's turn on the lights.\r\n| This bootstraps the framework and gets it ready for and then it\r\n| will load up this application so that we can run it and send\r\n| the responses back to the browser and delight these users.\r\n|\r\n*\/\r\n\r\n$app = require_once __DIR__.'\/bootstrap\/start.php';\r\n\r\n<\/pre>\n<p>\u4e0a\u9762\u9019\u6bb5\u8b80\u53d6\u81ea\u52d5\u8f09\u5165\u6a94\u6848\u3001\u555f\u52d5Laravel\u6846\u67b6\u7684\u6a94\u6848\uff0c\u8ddf\u5165\u53e3\u6a94\u6848\u662f\u4e00\u6a23\u7684\u3002<br \/>\n\u53c3\u898b\uff1a<a href=\"https:\/\/blog.turn.tw\/?page_id=764\" title=\"\u8d77\u9ede\uff1apublic\/index.php\">\u8d77\u9ede\uff1apublic\/index.php<\/a><\/p>\n<pre>\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Load The Artisan Console Application\r\n|--------------------------------------------------------------------------\r\n|\r\n| We'll need to run the script to load and return the Artisan console\r\n| application. We keep this in its own script so that we will load\r\n| the console application independent of running commands which\r\n| will allow us to fire commands from Routes when we want to.\r\n|\r\n*\/\r\n\r\n$app->setRequestForConsoleEnvironment();\r\n\r\n$artisan = Illuminate\\Console\\Application::start($app);\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Run The Artisan Application\r\n|--------------------------------------------------------------------------\r\n|\r\n| When we run the console application, the current CLI command will be\r\n| executed in this console and the response sent back to a terminal\r\n| or another output device for the developers. Here goes nothing!\r\n|\r\n*\/\r\n\r\n$status = $artisan->run();\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Shutdown The Application\r\n|--------------------------------------------------------------------------\r\n|\r\n| Once Artisan has finished running. We will fire off the shutdown events\r\n| so that any final work may be done by the application before we shut\r\n| down the process. This is the last thing to happen to the request.\r\n|\r\n*\/\r\n\r\n$app->shutdown();\r\n\r\nexit($status);\r\n<\/pre>\n<p>\u5f8c\u9762\u9019\u6bb5code\u975e\u5e38\u5de7\u5999\u3002\u5728public\/index.php\u88cf\u9762\uff0c$app\u662f\u6846\u67b6\u985e\u5225\u521d\u59cb\u5316\u51fa\u4f86\u7684\u7269\u4ef6\uff0c\u63a5\u8457$app->run\u4f86\u8b93\u6574\u500b\u7a0b\u5e8f\u52d5\u8d77\u4f86\u3002<br \/>\n\u4f46\u5728\u9019\u88e1\u537b\u662f\u5148\u5c07$app\u8a2d\u5b9arequest\u4f86\u6e90\u70baconsole\uff0c\u63a5\u8457\u628a\u6574\u500b\u7269\u4ef6\u7576\u4f5c\u53c3\u6578\u4e1f\u7d66Illuminate\\Console\\Application\u985e\u5225\uff0c\u6700\u5f8c\u57f7\u884c$artisan->run\u4e26\u4e14\u5c07$app->shutdown\u95dc\u6a5f\u3002<br \/>\n\u70ba\u4ec0\u9ebc\u5728\u547d\u4ee4\u5217\u57f7\u884c\u672c\u8eab\u4e0d\u7b97\u662f$app\u7684\u4efb\u52d9\uff0c\u800c\u662f\u7531\u984d\u5916\u985e\u5225\u7684\u5be6\u9ad4$artisan\u4f86\u8ca0\u8cac\uff1f<br \/>\n\u70ba\u4ec0\u9ebc\u5be6\u9ad4$artisan\u9700\u8981$app\u7576\u4f5c\u53c3\u6578\uff0c\u800c\u4e0d\u662f\u81ea\u5df1\u5728\u5167\u90e8\u57f7\u884c\u4e00\u6b21\u521d\u59cb\u5316\u7a0b\u5e8f\uff1f<br \/>\n\u539f\u4f5c\u8005\u62bd\u8c61\u5316\u601d\u8003\u7684\u65b9\u5f0f\u975e\u5e38\u503c\u5f97\u6df1\u5165\u63e3\u6e2c\u3002<br \/>\n<red><br \/>\n\u6211\u4e0d\u559c\u6b61Application::start\u9019\u500b\u975c\u614b\u51fd\u5f0f\u7684\u547d\u540d\u3002<br \/>\n\u65e2\u7136\u56de\u50b3\u4e86\u5be6\u9ad4\uff0c\u61c9\u8a72\u53ebcreate\u6216\u662fmake\u4e4b\u985e\u7684\u3002<br \/>\n<\/red><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/env php<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"_mi_skip_tracking":false},"_links":{"self":[{"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages\/787"}],"collection":[{"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=787"}],"version-history":[{"count":8,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages\/787\/revisions"}],"predecessor-version":[{"id":795,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages\/787\/revisions\/795"}],"wp:attachment":[{"href":"https:\/\/blog.turn.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}