{"id":798,"date":"2014-10-07T17:54:43","date_gmt":"2014-10-07T09:54:43","guid":{"rendered":"http:\/\/blog.turn.tw\/?page_id=798"},"modified":"2014-10-11T15:01:51","modified_gmt":"2014-10-11T07:01:51","slug":"%e9%a0%90%e5%82%99%e6%a0%b8%e5%bf%83%e7%a8%8b%e5%ba%8f%ef%bc%9abootstrapstart-php","status":"publish","type":"page","link":"https:\/\/blog.turn.tw\/?page_id=798","title":{"rendered":"\u9810\u5099\u6838\u5fc3\u7a0b\u5e8f\uff1abootstrap\/start.php"},"content":{"rendered":"<pre>\r\n<?php\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Create The Application\r\n|--------------------------------------------------------------------------\r\n|\r\n| The first thing we will do is create a new Laravel application instance\r\n| which serves as the \"glue\" for all the components of Laravel, and is\r\n| the IoC container for the system binding all of the various parts.\r\n|\r\n*\/\r\n\r\n$app = new Illuminate\\Foundation\\Application;\r\n\r\n<\/pre>\n<p>\u6700\u91cd\u8981\u7684\u6838\u5fc3\u5be6\u9ad4\u5728\u9019\u5152\u3002<\/p>\n<pre>\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Detect The Application Environment\r\n|--------------------------------------------------------------------------\r\n|\r\n| Laravel takes a dead simple approach to your application environments\r\n| so you can just specify a machine name for the host that matches a\r\n| given environment, then we will automatically detect it for you.\r\n|\r\n*\/\r\n\r\n$env = $app->detectEnvironment(array(\r\n\r\n\t'local' => array('homestead'),\r\n\r\n));\r\n<\/pre>\n<p>\u8fa8\u8a8d\u8655\u65bc\u958b\u767c\u74b0\u5883\u3001\u6e2c\u8a66\u74b0\u5883\u3001\u4e0a\u7dda\u74b0\u5883\u7684\u7a0b\u5f0f\u78bc\u3002<br \/>\n\u6709\u4e9bframework\u7684\u4f5c\u6cd5\u662f\u5728index.php\u6216\u662fconfig.php\u4e4b\u985e\u7684\u5730\u65b9\u5b9a\u7fa9\u95dc\u65bc\u74b0\u5883\u7684\u5e38\u6578\u3002<br \/>\n<green><br \/>\n\u90a3\u500b$env\u8b8a\u6578\u6c92\u6709\u5728\u9019\u500b\u6a94\u6848\u7528\u5230\u3002\u4f46\u662f\u5728\u7368\u7acb\u51fa\u4f86\u7684\u53e6\u4e00\u652fstart.php\u6a94\u7528\u5230\uff0c\u898b\u4e0b\u6587\u3002<br \/>\n<\/green><\/p>\n<pre>\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Bind Paths\r\n|--------------------------------------------------------------------------\r\n|\r\n| Here we are binding the paths configured in paths.php to the app. You\r\n| should not be changing these here. If you need to change these you\r\n| may do so within the paths.php file and they will be bound here.\r\n|\r\n*\/\r\n\r\n$app->bindInstallPaths(require __DIR__.'\/paths.php');\r\n\r\n<\/pre>\n<p>\u9700\u8981\u7528\u5230\u7684\u8def\u5f91\u5b57\u4e32\uff0c\u6709\u4e9b\u6846\u67b6\u6703\u76f4\u63a5\u5b9a\u7fa9\u6210\u5168\u57df\u5e38\u6578\uff0c\u4e26\u5728\u6bcf\u500b\u9700\u8981\u7684\u6a94\u6848\u4e2d\u4f7f\u7528\u9019\u4e9b\u5168\u57df\u5e38\u6578\u3002<br \/>\nLaravel\u7684\u4f5c\u6cd5\u662f\u5b9a\u7fa9\u5728paths.php\u5167\uff0c\u7136\u5f8c\u5728\u6b64\u8655\u8a2d\u5b9a\u9032\u6838\u5fc3\u5be6\u9ad4\u3002<br \/>\npaths.php\u5167\u7684\u7a0b\u5f0f\u78bc\u6839\u672c\u6c92\u5e7e\u884c\u3002\u539f\u4f5c\u8005\u537b\u9023\u9019\u90fd\u8981\u7368\u7acb\u51fa\u4f86\uff0c\u53ef\u898b\u5c0d\u65bcseparation of concerns\u7684\u56b4\u683c\u8981\u6c42\u3002<br \/>\n\u9019\u7a2e\u5148\u7522\u751f\u5be6\u9ad4\u3001\u518d\u5c07\u67d0\u4e9b\u529f\u80fd\u300c\u8a2d\u5b9a\u9032\u53bb\u300d(\u7528\u300c\u6ce8\u5c04\u9032\u53bb\u300d\u63cf\u8ff0\u4e5f\u8a31\u66f4\u7cbe\u6e96)\u7684\u4f5c\u6cd5\uff0c\u7a31\u70baInversion of Control(IoC)\u3002<br \/>\nIoC\u5728Laravel\u5167\u88ab\u975e\u5e38\u983b\u7e41\u7684\u4f7f\u7528\uff0c\u5927\u5e45\u964d\u4f4e\u4e86\u5404\u5143\u4ef6\u7684\u76f8\u4f9d\u6027\u3001\u63d0\u9ad8\u4e86\u7a0b\u5f0f\u78bc\u7684\u53ef\u8b80\u6027\u3002<\/p>\n<pre>\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Load The Application\r\n|--------------------------------------------------------------------------\r\n|\r\n| Here we will load this Illuminate application. We will keep this in a\r\n| separate location so we can isolate the creation of an application\r\n| from the actual running of the application with a given request.\r\n|\r\n*\/\r\n\r\n$framework = $app['path.base'].\r\n                 '\/vendor\/laravel\/framework\/src';\r\n\r\nrequire $framework.'\/Illuminate\/Foundation\/start.php';\r\n\r\n<\/pre>\n<p>\u6700\u91cd\u8981\u7684\u6838\u5fc3\u5be6\u9ad4$app\u5728\u524d\u9762\u521d\u59cb\u5316\u4e86\u3002\u6b64\u8655\u8f09\u5165\u95dc\u65bc\u6b64$app\u5be6\u9ad4\u7684\u4e00\u4e9b\u8a2d\u5b9a\u8207\u52d5\u4f5c\u3002<br \/>\n\u9019\u652fFoundation\/start.php\u7684\u5167\u5bb9\u4e5f\u53ef\u4ee5\u5168\u5beb\u5728bootstrap\/start.php\u88cf\u9762\u3002<br \/>\n\u7368\u7acb\u51fa\u4f86\u662f\u70ba\u4e86\uff1f\uff1f\uff1f<\/p>\n<pre>\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Return The Application\r\n|--------------------------------------------------------------------------\r\n|\r\n| This script returns the application instance. The instance is given to\r\n| the calling script so we can separate the building of the instances\r\n| from the actual running of the application and sending responses.\r\n|\r\n*\/\r\n\r\nreturn $app;\r\n\r\n<\/pre>\n<p>\u6709\u4e9b\u6846\u67b6\u6703\u5c07framework\u7684\u6838\u5fc3\u51fd\u5f0f\u5eab\u653e\u5728\u6839\u76ee\u9304system\u8cc7\u6599\u593e\u5167\u7684core\u8cc7\u6599\u593e\uff0c\u800cvendor\u8cc7\u6599\u593e\u5c08\u653e\u7b2c3\u65b9\u51fd\u5f0f\u5eab\u3002<br \/>\nLaravel\u7684\u6838\u5fc3\u51fd\u5f0f\u5eab\u537b\u662f\u653e\u5728vendor\u8cc7\u6599\u593e\u5167\u7684laravel\u8cc7\u6599\u593e\u3002<br \/>\n\u9019\u6a23\u7684\u6a94\u6848\u7d50\u69cb\u53cd\u6620\u4e86\u4f5c\u8005\u60f3\u5c07laravel\u8a2d\u8a08\u5f97\u975e\u5e38\u5f48\u6027\u7684\u91ce\u5fc3\uff1a\u6c92\u6709\u6240\u8b02\u300ccore\u300d\u7b49\u7d1a\u7684\u51fd\u5f0f\u5eab\uff0c\u6240\u6709\u51fd\u5f0f\u5eab\u5730\u4f4d\u4e00\u6a23\u3001\u5404\u81ea\u7368\u7acb\u3001laravel\u9019\u500b\u6846\u67b6\u53ea\u662f\u4e00\u7a2e\u5c07\u5b83\u5011\u515c\u5728\u4e00\u8d77\u4f7f\u7528\u7684\u65b9\u5f0f\u800c\u5df2\u3002<br \/>\n\u9019\u500b\u91ce\u5fc3\u672c\u8eab\u5c0e\u81f4\u4e86Laravel\u7684\u53ef\u64f4\u5145\u6027\u3001\u4f7f\u7528\u4e0a\u7684\u5f48\u6027\u3001\u4ee5\u53calaravel\u672c\u8eab\u5143\u4ef6(\u8b6c\u5982Eloquent ORM)\u7368\u7acb\u51fa\u53bb\u4f7f\u7528\u7684\u53ef\u80fd\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"","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\/798"}],"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=798"}],"version-history":[{"count":9,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages\/798\/revisions"}],"predecessor-version":[{"id":874,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages\/798\/revisions\/874"}],"wp:attachment":[{"href":"https:\/\/blog.turn.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}