{"id":768,"date":"2014-10-07T10:33:40","date_gmt":"2014-10-07T02:33:40","guid":{"rendered":"http:\/\/blog.turn.tw\/?page_id=768"},"modified":"2014-10-07T11:09:45","modified_gmt":"2014-10-07T03:09:45","slug":"%e8%87%aa%e5%8b%95%e8%bc%89%e5%85%a5%e9%a1%9e%e5%88%a5%ef%bc%9abootstrapautoload-php","status":"publish","type":"page","link":"https:\/\/blog.turn.tw\/?page_id=768","title":{"rendered":"\u81ea\u52d5\u8f09\u5165\u985e\u5225\uff1abootstrap\/autoload.php"},"content":{"rendered":"<pre>\r\n<?php\r\n\r\ndefine('LARAVEL_START', microtime(true));\r\n<\/pre>\n<p>\u5b9a\u7fa9\u4e00\u500b\u5e38\u6578\uff0c\u7d00\u9304Laravel\u6846\u67b6\u958b\u59cb\u57f7\u884c\u7684\u6642\u9593\u3002<br \/>\n\u9019\u6a23\u7684\u5e38\u6578\u901a\u5e38\u662f\u7528\u4f86\u8861\u91cf\u6846\u67b6\u672c\u8eab\u7684\u6548\u80fd\u3002<\/p>\n<pre>\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Register The Composer 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__.'\/..\/vendor\/autoload.php';\r\n<\/pre>\n<p>\u771f\u6b63\u7684\u81ea\u52d5\u8f09\u5165\u985e\u5225\u7684\u529f\u80fd\uff0c\u662f\u7531PHP\u7684\u5957\u4ef6\u7ba1\u7406\u5de5\u5177Composer\u4f86\u9054\u6210\u3002<\/p>\n<pre>\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Include The Compiled Class File\r\n|--------------------------------------------------------------------------\r\n|\r\n| To dramatically increase your application's performance, you may use a\r\n| compiled class file which contains all of the classes commonly used\r\n| by a request. The Artisan \"optimize\" is used to create this file.\r\n|\r\n*\/\r\n\r\nif (file_exists($compiled = __DIR__.'\/compiled.php'))\r\n{\r\n\trequire $compiled;\r\n}\r\n<\/pre>\n<p>\u9ede\u958bcompiled.php\u4f86\u770b\uff0c\u4f60\u6703\u767c\u73fe\u5b83\u5167\u5bb9\u8d85\u904e1\u842c\u884c\u3002<br \/>\nLaravel\u7684command line\u5de5\u5177Artisan\u6709optimize\u529f\u80fd\uff0c\u80fd\u5c07\u5e38\u7528\u5230\u7684\u985e\u5225\u5168\u90e8\u653e\u9032\u9019\u652fcompiled.php\u6a94\u5167\u3002<br \/>\n\u4e0d\u77e5\u9053\u300c\u5e38\u7528\u5230\u300d\u662f\u6307\u54ea\u4e9b\u6a94\u6848\u5462\uff1f<\/p>\n<pre>\r\n\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Setup Patchwork UTF-8 Handling\r\n|--------------------------------------------------------------------------\r\n|\r\n| The Patchwork library provides solid handling of UTF-8 strings as well\r\n| as provides replacements for all mb_* and iconv type functions that\r\n| are not available by default in PHP. We'll setup this stuff here.\r\n|\r\n*\/\r\n\r\nPatchwork\\Utf8\\Bootup::initMbstring();\r\n<\/pre>\n<p>\u8f09\u5165\u5354\u52a9\u8655\u7406UTF-8\u5b57\u4e32\u7684\u51fd\u5f0f\u5eab\u3002<\/p>\n<pre>\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Register The Laravel Auto Loader\r\n|--------------------------------------------------------------------------\r\n|\r\n| We register an auto-loader \"behind\" the Composer loader that can load\r\n| model classes on the fly, even if the autoload files have not been\r\n| regenerated for the application. We'll add it to the stack here.\r\n|\r\n*\/\r\n\r\nIlluminate\\Support\\ClassLoader::register();\r\n<\/pre>\n<p>PHP\u57285.1.2\u7248\u4ee5\u5f8c\u63d0\u4f9bspl_autoload_register\u51fd\u5f0f\uff0c\u80fd\u5c07\u67d0\u4e9b\u985e\u5225\u5148\u300c\u767b\u8a18\u300d\u9032\u4e00\u500bqueue\u5167\uff0c\u4e4b\u5f8c\u4f7f\u7528\u8a72\u985e\u5225\u4fbf\u4e0d\u9700\u8981\u5148\u8f09\u5165\u3001PHP\u6703\u81ea\u52d5\u9032\u9019\u500bqueue\u5167\u5c0b\u627e\u8f09\u5165\u8a72\u985e\u5225\u7684\u65b9\u6cd5\u3002<br \/>\n\u4e0a\u9762\u5df2\u7d93\u7531Composer\u8ca0\u8cac\u300c\u767b\u8a18\u300d\u5927\u90e8\u4efd\u9700\u8981\u7684\u7cfb\u7d71\u985e\u5225\u4e86\uff0c\u800c\u4f7f\u7528\u8005\u81ea\u5b9a\u7fa9\u7684\u985e\u5225(\u8b6c\u5982\u8aaaMVC\u7684model\u6a94\u6848)\uff0c\u5247\u5728\u6b64\u8655\u300c\u767b\u8a18\u300d\u3002<\/p>\n<pre>\r\n\/*\r\n|--------------------------------------------------------------------------\r\n| Register The Workbench Loaders\r\n|--------------------------------------------------------------------------\r\n|\r\n| The Laravel workbench provides a convenient place to develop packages\r\n| when working locally. However we will need to load in the Composer\r\n| auto-load files for the packages so that these can be used here.\r\n|\r\n*\/\r\n\r\nif (is_dir($workbench = __DIR__.'\/..\/workbench'))\r\n{\r\n\tIlluminate\\Workbench\\Starter::start($workbench);\r\n}\r\n<\/pre>\n<p>Laravel\u63d0\u4f9b\u4e86\u4e00\u500bworkbench\u985e\u5225\uff0c\u5354\u52a9\u4f7f\u7528\u8005\u5728\u672c\u6a5f\u958b\u767cpackage\u3002<br \/>\n\u4e0d\u662f\u8aaa\u7cfb\u7d71\u985e\u5225\u7d71\u4e00\u7531\u4e00\u958b\u59cb\u7684Composer\u8ca0\u8cac\u8f09\u5165\u55ce\uff1f\u600e\u9ebcworkbench\u6703\u5728\u9019\u908a\u8f09\u5165\uff1f<br \/>\n\u8a3b\u89e3\u8aaa\u660e\u662f\u56e0\u70baworkbench\u8207Composer\u6709\u76f8\u4f9d\u6027\u3002<\/p>\n<p>\u8a2d\u8a08\u6846\u67b6\u6709\u4e00\u9805\u56f0\u96e3\u4e4b\u8655\u5c31\u5728\u9019\u88e1\uff1a\u6846\u67b6\u7528\u5230\u7684\u985e\u5225\u6709\u4e00\u5927\u5806\uff0c\u6709\u81ea\u884c\u958b\u767c\u7684\u3001\u6709\u4f7f\u7528\u7b2c3\u65b9\u51fd\u5f0f\u5eab\u7684\uff0c\u8a72\u600e\u9ebc\u8f09\u5165\u4ed6\u5011\u624d\u6f02\u4eae\uff1f\u5982\u4f55\u8b93\u6846\u67b6source code\u770b\u8d77\u4f86\u4e0d\u6703\u4e82\u4e03\u516b\u7cdf\uff1f\u8981\u5168\u90e8\u5728\u4e00\u500b\u5730\u65b9\u8f09\u5165\u55ce\uff1f\u5206\u6563\u5728\u4e0d\u540c\u5730\u65b9\u6703\u4e0d\u6703\u6bd4\u8f03\u597d\uff1f<\/p>\n<p>\u9644\u4e0aPHP\u53e6\u4e00\u77e5\u540d\u6846\u67b6CodeIgniter\u8ca0\u8cac\u6838\u5fc3\u8f09\u5165\u7684\u7a0b\u5f0f\u78bc\uff0c\u4f9b\u5927\u5bb6\u53c3\u8003\u6bd4\u8f03\uff1a<\/p>\n<p><a href=\"https:\/\/github.com\/bcit-ci\/CodeIgniter\/blob\/develop\/system\/core\/CodeIgniter.php\">https:\/\/github.com\/bcit-ci\/CodeIgniter\/blob\/develop\/system\/core\/CodeIgniter.php<\/a><\/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\/768"}],"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=768"}],"version-history":[{"count":11,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages\/768\/revisions"}],"predecessor-version":[{"id":779,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages\/768\/revisions\/779"}],"wp:attachment":[{"href":"https:\/\/blog.turn.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}