{"id":813,"date":"2014-10-07T21:08:03","date_gmt":"2014-10-07T13:08:03","guid":{"rendered":"http:\/\/blog.turn.tw\/?page_id=813"},"modified":"2014-10-14T12:13:45","modified_gmt":"2014-10-14T04:13:45","slug":"laravel%e6%a0%b8%e5%bf%83%e5%af%a6%e9%ab%94%ef%bc%9avendorlaravelframeworksrcilluminatefoundationapplication-php","status":"publish","type":"page","link":"https:\/\/blog.turn.tw\/?page_id=813","title":{"rendered":"Laravel\u6838\u5fc3\u5be6\u9ad4\uff1aFoundation\/Application.php"},"content":{"rendered":"<p>Laravel\u6846\u67b6\u4e2d\uff0crouting\u3001\u63a5\u6536request\u3001\u767c\u9001response\u5e7e\u4ef6\u4e8b\u662f\u7531Symphony\u7684\u5143\u4ef6HttpKernel Component\u4f86\u5354\u52a9\u5b8c\u6210\u7684\u3002<br \/>\n\u77ad\u89e3\u9019\u500b\u5143\u4ef6\uff0c\u5c0d\u65bc\u77ad\u89e3Laravel\u539f\u59cb\u78bc\u6709\u6975\u5927\u7684\u5e6b\u52a9\uff1a<a href=\"http:\/\/symfony.com\/doc\/current\/components\/http_kernel\/introduction.html\" title=\"The HttpKernel Component\">The HttpKernel Component<\/a><br \/>\n\u4e0d\u904e\uff0c\u4ee5\u4e0a\u6587\u4ef6\u5167\u5bb9\u751f\u786c\u7121\u6bd4\u3002\u9019\u908a\u63a8\u85a6\u4e00\u500b\u6975\u5ea6\u512a\u8cea\u7684\u6559\u5b78\u6587\u7ae0\uff1a<br \/>\n<a href=\"http:\/\/fabien.potencier.org\/article\/50\/create-your-own-framework-on-top-of-the-symfony2-components-part-1\" title=\"Create your own framework... on top of the Symfony2 Components\">Create your own framework&#8230; on top of the Symfony2 Components<\/a><br \/>\n\u793a\u7bc4\u5982\u4f55\u7528Symphony\u5143\u4ef6\u5beb\u51fa\u81ea\u5df1\u7684\u6846\u67b6\u3002\u8b80\u904e\u4e4b\u5f8c\uff0c\u4e0d\u4f46\u53ef\u4ee5\u81ea\u5df1\u5beb\u51fa\u7c21\u6613\u7684\u6846\u67b6\uff0c\u5c0d\u65bc\u77ad\u89e3Laravel\u539f\u59cb\u78bc\u4e5f\u5f88\u6709\u5e6b\u52a9\u3002<\/p>\n<pre>\r\n<?php namespace Illuminate\\Foundation;\r\n\r\nuse Closure;\r\nuse Stack\\Builder;\r\nuse Illuminate\\Http\\Request;\r\nuse Illuminate\\Http\\Response;\r\nuse Illuminate\\Config\\FileLoader;\r\nuse Illuminate\\Container\\Container;\r\nuse Illuminate\\Filesystem\\Filesystem;\r\nuse Illuminate\\Support\\Facades\\Facade;\r\nuse Illuminate\\Events\\EventServiceProvider;\r\nuse Illuminate\\Routing\\RoutingServiceProvider;\r\nuse Illuminate\\Exception\\ExceptionServiceProvider;\r\nuse Illuminate\\Config\\FileEnvironmentVariablesLoader;\r\nuse Symfony\\Component\\HttpKernel\\HttpKernelInterface;\r\nuse Symfony\\Component\\HttpKernel\\TerminableInterface;\r\nuse Symfony\\Component\\HttpKernel\\Exception\\HttpException;\r\nuse Symfony\\Component\\Debug\\Exception\\FatalErrorException;\r\nuse Illuminate\\Support\\Contracts\\ResponsePreparerInterface;\r\nuse Symfony\\Component\\HttpFoundation\\Request as SymfonyRequest;\r\nuse Symfony\\Component\\HttpFoundation\\Response as SymfonyResponse;\r\nuse Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException;\r\n\r\nclass Application extends Container implements HttpKernelInterface, TerminableInterface, ResponsePreparerInterface {\r\n<\/pre>\n<p>\u7e7c\u627fContainer\u985e\u5225\uff1a\u4f7f\u5f97\u80fd\u5920\u7528\u9663\u5217\u65b9\u5f0f\u64cd\u4f5c\u3002<br \/>\n\u5be6\u4f5cHttpKernelInterface\u4ecb\u9762\uff1a\u898f\u5b9a\u5be6\u4f5chandle\u51fd\u5f0f\u3001\u50b3\u5165request\u5be6\u9ad4\u4e26\u56de\u50b3response\u5be6\u9ad4\u3002<br \/>\n\u5be6\u4f5cTerminableInterface\u4ecb\u9762\uff1a\u898f\u5b9a\u5be6\u4f5cterminate\u51fd\u5f0f\u3001\u5b8c\u6210\u4e00\u500brequest\/response\u5468\u671f\u3002<br \/>\n\u5be6\u4f5cResponsePreparerInterface\u4ecb\u9762\uff1a\u898f\u5b9a\u5be6\u4f5cprepareResponse\u3001readyForResponses\u51fd\u5f0f\u3001\u7528\u4ee5\u5354\u52a9\u56de\u50b3response\u3002<\/p>\n<pre>\r\n\t\/**\r\n\t * The Laravel framework version.\r\n\t *\r\n\t * @var string\r\n\t *\/\r\n\tconst VERSION = '4.2.10';\r\n\r\n\t\/**\r\n\t * Indicates if the application has \"booted\".\r\n\t *\r\n\t * @var bool\r\n\t *\/\r\n\tprotected $booted = false;\r\n\r\n\t\/**\r\n\t * The array of booting callbacks.\r\n\t *\r\n\t * @var array\r\n\t *\/\r\n\tprotected $bootingCallbacks = array();\r\n\r\n\t\/**\r\n\t * The array of booted callbacks.\r\n\t *\r\n\t * @var array\r\n\t *\/\r\n\tprotected $bootedCallbacks = array();\r\n\r\n\t\/**\r\n\t * The array of finish callbacks.\r\n\t *\r\n\t * @var array\r\n\t *\/\r\n\tprotected $finishCallbacks = array();\r\n\r\n\t\/**\r\n\t * The array of shutdown callbacks.\r\n\t *\r\n\t * @var array\r\n\t *\/\r\n\tprotected $shutdownCallbacks = array();\r\n<\/pre>\n<p>4\u500b\u9663\u5217\u7d00\u93044\u500b\u6642\u9593\u9ede\u8981\u57f7\u884c\u7684callback\uff1a<br \/>\n\u521d\u59cb\u5316\u6838\u5fc3\u7a0b\u5e8f\u524d\u3001\u521d\u59cb\u5316\u6838\u5fc3\u7a0b\u5e8f\u5f8c\u3001\u57f7\u884c\u5b8c\u6838\u5fc3\u7a0b\u5e8f\u5f8c\u3001\u4e2d\u6b62\u6838\u5fc3\u7a0b\u5e8f\u5f8c\u3002<br \/>\n\u9019\u908a\u7684\u300c\u6838\u5fc3\u7a0b\u5e8f\u300d\u662f\u6307\u4ec0\u9ebc\uff1f\u8acb\u7e7c\u7e8c\u5f80\u4e0b\u770b\u3002<\/p>\n<pre>\r\n\t\/**\r\n\t * All of the developer defined middlewares.\r\n\t *\r\n\t * @var array\r\n\t *\/\r\n\tprotected $middlewares = array();\r\n\r\n\t\/**\r\n\t * All of the registered service providers.\r\n\t *\r\n\t * @var array\r\n\t *\/\r\n\tprotected $serviceProviders = array();\r\n\r\n\t\/**\r\n\t * The names of the loaded service providers.\r\n\t *\r\n\t * @var array\r\n\t *\/\r\n\tprotected $loadedProviders = array();\r\n\r\n\t\/**\r\n\t * The deferred services and their providers.\r\n\t *\r\n\t * @var array\r\n\t *\/\r\n\tprotected $deferredServices = array();\r\n\r\n\t\/**\r\n\t * The request class used by the application.\r\n\t *\r\n\t * @var string\r\n\t *\/\r\n\tprotected static $requestClass = 'Illuminate\\Http\\Request';\r\n\r\n\t\/**\r\n\t * Create a new Illuminate application instance.\r\n\t *\r\n\t * @param  \\Illuminate\\Http\\Request  $request\r\n\t * @return void\r\n\t *\/\r\n\tpublic function __construct(Request $request = null)\r\n\t{\r\n\t\t$this->registerBaseBindings($request ?: $this->createNewRequest());\r\n\r\n\t\t$this->registerBaseServiceProviders();\r\n\r\n\t\t$this->registerBaseMiddlewares();\r\n\t}\r\n<\/pre>\n<p>\u7522\u751frequest\u5be6\u9ad4\u4e26\u7d81\u5b9a\u3002<br \/>\n\u7d81\u5b9a\u5e7e\u9805service provider\u5be6\u9ad4\u3002<br \/>\n\u7d81\u5b9a\u4e2d\u4ecb\u7a0b\u5e8f(\u5f80\u4e0b\u770b\uff0c\u767c\u73fe\u51fd\u5f0f\u5167\u5bb9\u5176\u5be6\u662f\u7a7a\u7684)\u3002<br \/>\n<red><br \/>\n\u5efa\u69cb\u5f0f\u5141\u8a31\u50b3\u5165Request\u5be6\u9ad4\u7576\u53c3\u6578\uff0c\u4f46\u5be6\u969b\u4e0a\u5728bootstrap\/start.php\u88e1\uff0c\u4e26\u6c92\u6709\u5728\u5efa\u69cb\u6642\u50b3\u5165\u4efb\u4f55\u6771\u897f\u3002<br \/>\n\u6240\u4ee5registerBaseBindings\u6c38\u9060\u662f\u7528createNewRequest\u51fd\u5f0f\u7684\u56de\u50b3\u503c\u7576\u4f5c\u53c3\u6578\u3002<br \/>\n\u9019\u908a\u5beb\u6210\u9019\u6a23\u662f...\u7559\u7d66\u9032\u968e\u4f7f\u7528\u8005\u64f4\u5145\u7a7a\u9593\u5427\uff1f<br \/>\n<\/red><\/p>\n<pre>\r\n\r\n\t\/**\r\n\t * Create a new request instance from the request class.\r\n\t *\r\n\t * @return \\Illuminate\\Http\\Request\r\n\t *\/\r\n\tprotected function createNewRequest()\r\n\t{\r\n\t\treturn forward_static_call(array(static::$requestClass, 'createFromGlobals'));\r\n\t}\r\n<\/pre>\n<p>\u958b\u767c\u6642\u6703\u7528\u5230\u7684Input\u985e\u5225\u3001\u547c\u53eb\u5b83\u7684\u975c\u614b\u51fd\u5f0f\uff0c\u80cc\u5f8c\u5c0d\u61c9\u5230\u7684\u5be6\u9ad4\u5c31\u662f\u5728\u9019\u88e1\u7522\u751f\u7684\u3002<br \/>\n\u95dc\u65bc\u9019\u500b\u5be6\u9ad4\u6240\u5c6c\u7684\u985e\u5225\uff0c\u53c3\u898b\uff1a<a href=\"https:\/\/blog.turn.tw\/?page_id=909\" title=\"\u63a5\u53d7\u8acb\u6c42\uff1aHttp\/Request.php\">\u63a5\u53d7\u8acb\u6c42\uff1aHttp\/Request.php<\/a><\/p>\n<pre>\r\n\r\n\t\/**\r\n\t * Register the basic bindings into the container.\r\n\t *\r\n\t * @param  \\Illuminate\\Http\\Request  $request\r\n\t * @return void\r\n\t *\/\r\n\tprotected function registerBaseBindings($request)\r\n\t{\r\n\t\t$this->instance('request', $request);\r\n\r\n\t\t$this->instance('Illuminate\\Container\\Container', $this);\r\n\t}\r\n\r\n\t\/**\r\n\t * Register all of the base service providers.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tprotected function registerBaseServiceProviders()\r\n\t{\r\n\t\tforeach (array('Event', 'Exception', 'Routing') as $name)\r\n\t\t{\r\n\t\t\t$this->{\"register{$name}Provider\"}();\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * Register the exception service provider.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tprotected function registerExceptionProvider()\r\n\t{\r\n\t\t$this->register(new ExceptionServiceProvider($this));\r\n\t}\r\n\r\n\t\/**\r\n\t * Register the routing service provider.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tprotected function registerRoutingProvider()\r\n\t{\r\n\t\t$this->register(new RoutingServiceProvider($this));\r\n\t}\r\n\r\n\t\/**\r\n\t * Register the event service provider.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tprotected function registerEventProvider()\r\n\t{\r\n\t\t$this->register(new EventServiceProvider($this));\r\n\t}\r\n<\/pre>\n<p>\u4e0a\u9762\u5e7e\u500b\u51fd\u5f0f\u5167\u5bb9\u5c31\u662f\u5be6\u969b\u5728\u5efa\u69cb\u5f0f\u5167\u57f7\u884c\u7684\u5167\u5bb9\u3002<\/p>\n<p><red><br \/>\n\u5f9e\u5efa\u69cb\u5f0f\u4e00\u76f4\u5230\u4e0a\u9762\u70ba\u6b62\u7684\u5beb\u6cd5\u78ba\u5be6\u5f88OOP\uff0c\u53ef\u8b80\u6027\u4e5f\u5f88\u9ad8\uff0c\u4f46\u6211\u89ba\u5f97\u597d\u5927\u4e00\u4e32...\u3002<br \/>\n<\/red><\/p>\n<pre>\r\n\t\/**\r\n\t * Bind the installation paths to the application.\r\n\t *\r\n\t * @param  array  $paths\r\n\t * @return void\r\n\t *\/\r\n\tpublic function bindInstallPaths(array $paths)\r\n\t{\r\n\t\t$this->instance('path', realpath($paths['app']));\r\n\r\n\t\t\/\/ Here we will bind the install paths into the container as strings that can be\r\n\t\t\/\/ accessed from any point in the system. Each path key is prefixed with path\r\n\t\t\/\/ so that they have the consistent naming convention inside the container.\r\n\t\tforeach (array_except($paths, array('app')) as $key => $value)\r\n\t\t{\r\n\t\t\t$this->instance(\"path.{$key}\", realpath($value));\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * Get the application bootstrap file.\r\n\t *\r\n\t * @return string\r\n\t *\/\r\n\tpublic static function getBootstrapFile()\r\n\t{\r\n\t\treturn __DIR__.'\/start.php';\r\n\t}\r\n\r\n\t\/**\r\n\t * Start the exception handling for the request.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tpublic function startExceptionHandling()\r\n\t{\r\n\t\t$this['exception']->register($this->environment());\r\n\r\n\t\t$this['exception']->setDebug($this['config']['app.debug']);\r\n\t}\r\n\r\n\t\/**\r\n\t * Get or check the current application environment.\r\n\t *\r\n\t * @param  mixed\r\n\t * @return string\r\n\t *\/\r\n\tpublic function environment()\r\n\t{\r\n\t\tif (count(func_get_args()) > 0)\r\n\t\t{\r\n\t\t\treturn in_array($this['env'], func_get_args());\r\n\t\t}\r\n\r\n\t\treturn $this['env'];\r\n\t}\r\n\r\n\t\/**\r\n\t * Determine if application is in local environment.\r\n\t *\r\n\t * @return bool\r\n\t *\/\r\n\tpublic function isLocal()\r\n\t{\r\n\t\treturn $this['env'] == 'local';\r\n\t}\r\n\r\n\t\/**\r\n\t * Detect the application's current environment.\r\n\t *\r\n\t * @param  array|string  $envs\r\n\t * @return string\r\n\t *\/\r\n\tpublic function detectEnvironment($envs)\r\n\t{\r\n\t\t$args = isset($_SERVER['argv']) ? $_SERVER['argv'] : null;\r\n\r\n\t\treturn $this['env'] = (new EnvironmentDetector())->detect($envs, $args);\r\n\t}\r\n\r\n\t\/**\r\n\t * Determine if we are running in the console.\r\n\t *\r\n\t * @return bool\r\n\t *\/\r\n\tpublic function runningInConsole()\r\n\t{\r\n\t\treturn php_sapi_name() == 'cli';\r\n\t}\r\n\r\n\t\/**\r\n\t * Determine if we are running unit tests.\r\n\t *\r\n\t * @return bool\r\n\t *\/\r\n\tpublic function runningUnitTests()\r\n\t{\r\n\t\treturn $this['env'] == 'testing';\r\n\t}\r\n\r\n\t\/**\r\n\t * Force register a service provider with the application.\r\n\t *\r\n\t * @param  \\Illuminate\\Support\\ServiceProvider|string  $provider\r\n\t * @param  array  $options\r\n\t * @return \\Illuminate\\Support\\ServiceProvider\r\n\t *\/\r\n\tpublic function forceRegister($provider, $options = array())\r\n\t{\r\n\t\treturn $this->register($provider, $options, true);\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a service provider with the application.\r\n\t *\r\n\t * @param  \\Illuminate\\Support\\ServiceProvider|string  $provider\r\n\t * @param  array  $options\r\n\t * @param  bool   $force\r\n\t * @return \\Illuminate\\Support\\ServiceProvider\r\n\t *\/\r\n\tpublic function register($provider, $options = array(), $force = false)\r\n\t{\r\n\t\tif ($registered = $this->getRegistered($provider) && ! $force)\r\n                                     return $registered;\r\n\r\n\t\t\/\/ If the given \"provider\" is a string, we will resolve it, passing in the\r\n\t\t\/\/ application instance automatically for the developer. This is simply\r\n\t\t\/\/ a more convenient way of specifying your service provider classes.\r\n\t\tif (is_string($provider))\r\n\t\t{\r\n\t\t\t$provider = $this->resolveProviderClass($provider);\r\n\t\t}\r\n\r\n\t\t$provider->register();\r\n\r\n\t\t\/\/ Once we have registered the service we will iterate through the options\r\n\t\t\/\/ and set each of them on the application so they will be available on\r\n\t\t\/\/ the actual loading of the service objects and for developer usage.\r\n\t\tforeach ($options as $key => $value)\r\n\t\t{\r\n\t\t\t$this[$key] = $value;\r\n\t\t}\r\n\r\n\t\t$this->markAsRegistered($provider);\r\n\r\n\t\t\/\/ If the application has already booted, we will call this boot method on\r\n\t\t\/\/ the provider class so it has an opportunity to do its boot logic and\r\n\t\t\/\/ will be ready for any usage by the developer's application logics.\r\n\t\tif ($this->booted) $provider->boot();\r\n\r\n\t\treturn $provider;\r\n\t}\r\n\r\n\t\/**\r\n\t * Get the registered service provider instance if it exists.\r\n\t *\r\n\t * @param  \\Illuminate\\Support\\ServiceProvider|string  $provider\r\n\t * @return \\Illuminate\\Support\\ServiceProvider|null\r\n\t *\/\r\n\tpublic function getRegistered($provider)\r\n\t{\r\n\t\t$name = is_string($provider) ? $provider : get_class($provider);\r\n\r\n\t\tif (array_key_exists($name, $this->loadedProviders))\r\n\t\t{\r\n\t\t\treturn array_first($this->serviceProviders, function($key, $value) use ($name)\r\n\t\t\t{\r\n\t\t\t\treturn get_class($value) == $name;\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * Resolve a service provider instance from the class name.\r\n\t *\r\n\t * @param  string  $provider\r\n\t * @return \\Illuminate\\Support\\ServiceProvider\r\n\t *\/\r\n\tpublic function resolveProviderClass($provider)\r\n\t{\r\n\t\treturn new $provider($this);\r\n\t}\r\n\r\n\t\/**\r\n\t * Mark the given provider as registered.\r\n\t *\r\n\t * @param  \\Illuminate\\Support\\ServiceProvider\r\n\t * @return void\r\n\t *\/\r\n\tprotected function markAsRegistered($provider)\r\n\t{\r\n\t\t$this['events']->fire($class = get_class($provider), array($provider));\r\n\r\n\t\t$this->serviceProviders[] = $provider;\r\n\r\n\t\t$this->loadedProviders[$class] = true;\r\n\t}\r\n\r\n\t\/**\r\n\t * Load and boot all of the remaining deferred providers.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tpublic function loadDeferredProviders()\r\n\t{\r\n\t\t\/\/ We will simply spin through each of the deferred providers and register each\r\n\t\t\/\/ one and boot them if the application has booted. This should make each of\r\n\t\t\/\/ the remaining services available to this application for immediate use.\r\n\t\tforeach ($this->deferredServices as $service => $provider)\r\n\t\t{\r\n\t\t\t$this->loadDeferredProvider($service);\r\n\t\t}\r\n\r\n\t\t$this->deferredServices = array();\r\n\t}\r\n\r\n\t\/**\r\n\t * Load the provider for a deferred service.\r\n\t *\r\n\t * @param  string  $service\r\n\t * @return void\r\n\t *\/\r\n\tprotected function loadDeferredProvider($service)\r\n\t{\r\n\t\t$provider = $this->deferredServices[$service];\r\n\r\n\t\t\/\/ If the service provider has not already been loaded and registered we can\r\n\t\t\/\/ register it with the application and remove the service from this list\r\n\t\t\/\/ of deferred services, since it will already be loaded on subsequent.\r\n\t\tif ( ! isset($this->loadedProviders[$provider]))\r\n\t\t{\r\n\t\t\t$this->registerDeferredProvider($provider, $service);\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a deferred provider and service.\r\n\t *\r\n\t * @param  string  $provider\r\n\t * @param  string  $service\r\n\t * @return void\r\n\t *\/\r\n\tpublic function registerDeferredProvider($provider, $service = null)\r\n\t{\r\n\t\t\/\/ Once the provider that provides the deferred service has been registered we\r\n\t\t\/\/ will remove it from our local list of the deferred services with related\r\n\t\t\/\/ providers so that this container does not try to resolve it out again.\r\n\t\tif ($service) unset($this->deferredServices[$service]);\r\n\r\n\t\t$this->register($instance = new $provider($this));\r\n\r\n\t\tif ( ! $this->booted)\r\n\t\t{\r\n\t\t\t$this->booting(function() use ($instance)\r\n\t\t\t{\r\n\t\t\t\t$instance->boot();\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * Resolve the given type from the container.\r\n\t *\r\n\t * (Overriding Container::make)\r\n\t *\r\n\t * @param  string  $abstract\r\n\t * @param  array   $parameters\r\n\t * @return mixed\r\n\t *\/\r\n\tpublic function make($abstract, $parameters = array())\r\n\t{\r\n\t\t$abstract = $this->getAlias($abstract);\r\n\r\n\t\tif (isset($this->deferredServices[$abstract]))\r\n\t\t{\r\n\t\t\t$this->loadDeferredProvider($abstract);\r\n\t\t}\r\n\r\n\t\treturn parent::make($abstract, $parameters);\r\n\t}\r\n\r\n\t\/**\r\n\t * Determine if the given abstract type has been bound.\r\n\t *\r\n\t * (Overriding Container::bound)\r\n\t *\r\n\t * @param  string  $abstract\r\n\t * @return bool\r\n\t *\/\r\n\tpublic function bound($abstract)\r\n\t{\r\n\t\treturn isset($this->deferredServices[$abstract]) || parent::bound($abstract);\r\n\t}\r\n\r\n\t\/**\r\n\t * \"Extend\" an abstract type in the container.\r\n\t *\r\n\t * (Overriding Container::extend)\r\n\t *\r\n\t * @param  string   $abstract\r\n\t * @param  \\Closure  $closure\r\n\t * @return void\r\n\t *\r\n\t * @throws \\InvalidArgumentException\r\n\t *\/\r\n\tpublic function extend($abstract, Closure $closure)\r\n\t{\r\n\t\t$abstract = $this->getAlias($abstract);\r\n\r\n\t\tif (isset($this->deferredServices[$abstract]))\r\n\t\t{\r\n\t\t\t$this->loadDeferredProvider($abstract);\r\n\t\t}\r\n\r\n\t\treturn parent::extend($abstract, $closure);\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a \"before\" application filter.\r\n\t *\r\n\t * @param  \\Closure|string  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function before($callback)\r\n\t{\r\n\t\treturn $this['router']->before($callback);\r\n\t}\r\n\r\n\t\/**\r\n\t * Register an \"after\" application filter.\r\n\t *\r\n\t * @param  \\Closure|string  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function after($callback)\r\n\t{\r\n\t\treturn $this['router']->after($callback);\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a \"finish\" application filter.\r\n\t *\r\n\t * @param  \\Closure|string  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function finish($callback)\r\n\t{\r\n\t\t$this->finishCallbacks[] = $callback;\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a \"shutdown\" callback.\r\n\t *\r\n\t * @param  callable  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function shutdown(callable $callback = null)\r\n\t{\r\n\t\tif (is_null($callback))\r\n\t\t{\r\n\t\t\t$this->fireAppCallbacks($this->shutdownCallbacks);\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\t$this->shutdownCallbacks[] = $callback;\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a function for determining when to use array sessions.\r\n\t *\r\n\t * @param  \\Closure  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function useArraySessions(Closure $callback)\r\n\t{\r\n\t\t$this->bind('session.reject', function() use ($callback)\r\n\t\t{\r\n\t\t\treturn $callback;\r\n\t\t});\r\n\t}\r\n\r\n\t\/**\r\n\t * Determine if the application has booted.\r\n\t *\r\n\t * @return bool\r\n\t *\/\r\n\tpublic function isBooted()\r\n\t{\r\n\t\treturn $this->booted;\r\n\t}\r\n\r\n\t\/**\r\n\t * Boot the application's service providers.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tpublic function boot()\r\n\t{\r\n\t\tif ($this->booted) return;\r\n\r\n\t\tarray_walk($this->serviceProviders, function($p) { $p->boot(); });\r\n\r\n\t\t$this->bootApplication();\r\n\t}\r\n\r\n\t\/**\r\n\t * Boot the application and fire app callbacks.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tprotected function bootApplication()\r\n\t{\r\n\t\t\/\/ Once the application has booted we will also fire some \"booted\" callbacks\r\n\t\t\/\/ for any listeners that need to do work after this initial booting gets\r\n\t\t\/\/ finished. This is useful when ordering the boot-up processes we run.\r\n\t\t$this->fireAppCallbacks($this->bootingCallbacks);\r\n\r\n\t\t$this->booted = true;\r\n\r\n\t\t$this->fireAppCallbacks($this->bootedCallbacks);\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a new boot listener.\r\n\t *\r\n\t * @param  mixed  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function booting($callback)\r\n\t{\r\n\t\t$this->bootingCallbacks[] = $callback;\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a new \"booted\" listener.\r\n\t *\r\n\t * @param  mixed  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function booted($callback)\r\n\t{\r\n\t\t$this->bootedCallbacks[] = $callback;\r\n\r\n\t\tif ($this->isBooted()) $this->fireAppCallbacks(array($callback));\r\n\t}\r\n\r\n\t\/**\r\n\t * Run the application and send the response.\r\n\t *\r\n\t * @param  \\Symfony\\Component\\HttpFoundation\\Request  $request\r\n\t * @return void\r\n\t *\/\r\n\tpublic function run(SymfonyRequest $request = null)\r\n\t{\r\n\t\t$request = $request ?: $this['request'];\r\n\r\n\t\t$response = with($stack = $this->getStackedClient())->handle($request);\r\n\r\n\t\t$response->send();\r\n\r\n\t\t$stack->terminate($request, $response);\r\n\t}\r\n<\/pre>\n<p>\u9019\u662f\u5165\u53e3\u6a94\u6848(public\/index.php)\u521d\u59cb\u5316Laravel\u5be6\u9ad4\u4e4b\u5f8c\uff0c\u552f\u4e00\u547c\u53eb\u7684\u51fd\u5f0f\u3002<br \/>\n\u300c\u57f7\u884c\u672c\u6b21\u61c9\u7528\u7136\u5f8c\u9001\u51faresponse\u7d66client\u7aef\u3002\u300d<\/p>\n<p>wich\u51fd\u6578\u662fLaravel\u81ea\u5b9a\u7fa9\u7684\u8f14\u52a9\u51fd\u6578\uff1a<br \/>\nReturn the given object. Useful for method chaining constructors in PHP 5.3.x.<\/p>\n<p>\u800cgetStackedClient\u5247\u662f\u56de\u50b3stacked HTTP kernel\uff0c\u5c07\u52a0\u5bc6\u8655\u7406\u3001cookie\u8655\u7406\u3001session\u8655\u7406\u653e\u9032\u4e00\u500bstack\u5167\u6e96\u5099\u7d66handle\u4f9d\u5e8f\u8655\u7406\u3002\u95dc\u65bc\u9019\u90e8\u4efd\u8acb\u53c3\u898bSymphony\u6846\u67b6\uff1a<br \/>\n<a href=\"http:\/\/symfony.com\/doc\/current\/components\/http_kernel\/introduction.html\" title=\"The HttpKernel Component\">The HttpKernel Component<\/a><br \/>\nLaravel\u7684request\u8207response\u7a0b\u5e8f\u5c31\u662f\u5229\u7528Symphony\u7684\u51fd\u5f0f\u5eab\uff0c\u5b8c\u6210\u4e00\u500b\u6309\u7167\u6b65\u9a5f\u5c07request\u8f49\u6210response\u7684\u904e\u7a0b\u3002<\/p>\n<p>\u6700\u5f8c\u6309\u7167Symphony\u51fd\u5f0f\u5eab\u7684\u898f\u7bc4\uff0csend\u7d50\u679c\u4e4b\u5f8c\uff0c\u5c07stack\u7d66terminate\u6389\u3002<\/p>\n<p>Symphony\u9019\u6a23\u8a2d\u8a08\u662f\u8b93\u7cfb\u7d71\u80fd\u5920\u5118\u5feb\u5148send\u7d50\u679c\u7d66\u4f7f\u7528\u8005\u7684\u700f\u89bd\u5668\uff0c\u7136\u5f8c\u518d\u57f7\u884c\u4e00\u4e9b\u50cf\u662f\u767c\u9001email\u7684\u7de9\u6162\u7a0b\u5e8f\u3002<br \/>\n<red><br \/>\n\u5165\u53e3\u6a94\u6848\u4e26\u6c92\u6709\u50b3\u5165\u4efb\u4f55request\u5be6\u9ad4\u7576\u53c3\u6578\u3002\u539f\u4f5c\u5728\u6b64\u8655\u4fdd\u7559\u4e86\u64f4\u5145\u6027\u7d66\u9032\u968e\u4f7f\u7528\u8005\u3002<br \/>\n<\/red><\/p>\n<pre>\r\n\r\n\t\/**\r\n\t * Get the stacked HTTP kernel for the application.\r\n\t *\r\n\t * @return  \\Symfony\\Component\\HttpKernel\\HttpKernelInterface\r\n\t *\/\r\n\tprotected function getStackedClient()\r\n\t{\r\n\t\t$sessionReject = $this->bound('session.reject') ? $this['session.reject'] : null;\r\n\r\n\t\t$client = (new Builder)\r\n                    ->push('Illuminate\\Cookie\\Guard', $this['encrypter'])\r\n                    ->push('Illuminate\\Cookie\\Queue', $this['cookie'])\r\n                    ->push('Illuminate\\Session\\Middleware', $this['session'], $sessionReject);\r\n\r\n\t\t$this->mergeCustomMiddlewares($client);\r\n\r\n\t\treturn $client->resolve($this);\r\n\t}\r\n\r\n\t\/**\r\n\t * Merge the developer defined middlewares onto the stack.\r\n\t *\r\n\t * @param  \\Stack\\Builder\r\n\t * @return void\r\n\t *\/\r\n\tprotected function mergeCustomMiddlewares(Builder $stack)\r\n\t{\r\n\t\tforeach ($this->middlewares as $middleware)\r\n\t\t{\r\n\t\t\tlist($class, $parameters) = array_values($middleware);\r\n\r\n\t\t\tarray_unshift($parameters, $class);\r\n\r\n\t\t\tcall_user_func_array(array($stack, 'push'), $parameters);\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * Register the default, but optional middlewares.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tprotected function registerBaseMiddlewares()\r\n\t{\r\n\t\t\/\/\r\n\t}\r\n\r\n\t\/**\r\n\t * Add a HttpKernel middleware onto the stack.\r\n\t *\r\n\t * @param  string  $class\r\n\t * @param  array  $parameters\r\n\t * @return $this\r\n\t *\/\r\n\tpublic function middleware($class, array $parameters = array())\r\n\t{\r\n\t\t$this->middlewares[] = compact('class', 'parameters');\r\n\r\n\t\treturn $this;\r\n\t}\r\n\r\n\t\/**\r\n\t * Remove a custom middleware from the application.\r\n\t *\r\n\t * @param  string  $class\r\n\t * @return void\r\n\t *\/\r\n\tpublic function forgetMiddleware($class)\r\n\t{\r\n\t\t$this->middlewares = array_filter($this->middlewares, function($m) use ($class)\r\n\t\t{\r\n\t\t\treturn $m['class'] != $class;\r\n\t\t});\r\n\t}\r\n\r\n\t\/**\r\n\t * Handle the given request and get the response.\r\n\t *\r\n\t * Provides compatibility with BrowserKit functional testing.\r\n\t *\r\n\t * @implements HttpKernelInterface::handle\r\n\t *\r\n\t * @param  \\Symfony\\Component\\HttpFoundation\\Request  $request\r\n\t * @param  int   $type\r\n\t * @param  bool  $catch\r\n\t * @return \\Symfony\\Component\\HttpFoundation\\Response\r\n\t *\r\n\t * @throws \\Exception\r\n\t *\/\r\n\tpublic function handle(SymfonyRequest $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)\r\n\t{\r\n\t\ttry\r\n\t\t{\r\n\t\t\t$this->refreshRequest($request = Request::createFromBase($request));\r\n\r\n\t\t\t$this->boot();\r\n\r\n\t\t\treturn $this->dispatch($request);\r\n\t\t}\r\n\t\tcatch (\\Exception $e)\r\n\t\t{\r\n\t\t\tif ($this->runningUnitTests()) throw $e;\r\n\r\n\t\t\treturn $this['exception']->handleException($e);\r\n\t\t}\r\n\t}\r\n<\/pre>\n<p>\u5728run\u51fd\u5f0f\u4e2d\u88ab\u547c\u53eb\u3002<br \/>\n\u7531HttpKernelInterface\u6240\u898f\u7bc4\u3001\u5be6\u4f5crequest\u8f49\u6210response\u7684\u51fd\u5f0f\u3002<br \/>\n\u5148refreshRequest\u5c07request\u6d17\u4e7e\u6de8(\uff1f\uff1f\uff1f)<br \/>\n\u7136\u5f8c\u57f7\u884cboot\u5c07\u6574\u500b\u61c9\u7528\u7a0b\u5e8f\u300c\u958b\u6a5f\u300d\u3002\u5be6\u969b\u7684\u8f49\u63db\u5de5\u4f5c\u7531dispatch\u8ca0\u8cac\u3002<br \/>\n\u524d\u9762\u63d0\u5230\u7684<a href=\"http:\/\/symfony.com\/doc\/current\/components\/http_kernel\/introduction.html\" title=\"The HttpKernel Component\">The HttpKernel Component<\/a>\uff0c\u5982\u679c\u6c92\u5f04\u61c2\uff0c\u6703\u5f88\u96e3\u641e\u61c2\u9019\u908a\u70ba\u4f55\u8981\u4e00\u5c64\u5305\u4e00\u5c64\u3002<\/p>\n<pre>\r\n\t\/**\r\n\t * Handle the given request and get the response.\r\n\t *\r\n\t * @param  \\Illuminate\\Http\\Request  $request\r\n\t * @return \\Symfony\\Component\\HttpFoundation\\Response\r\n\t *\/\r\n\tpublic function dispatch(Request $request)\r\n\t{\r\n\t\tif ($this->isDownForMaintenance())\r\n\t\t{\r\n\t\t\t$response = $this['events']->until('illuminate.app.down');\r\n\r\n\t\t\tif ( ! is_null($response)) return $this->prepareResponse($response, $request);\r\n\t\t}\r\n\r\n\t\tif ($this->runningUnitTests() && ! $this['session']->isStarted())\r\n\t\t{\r\n\t\t\t$this['session']->start();\r\n\t\t}\r\n\r\n\t\treturn $this['router']->dispatch($this->prepareRequest($request));\r\n\t}\r\n<\/pre>\n<p>\u88abhandle\u547c\u53eb\u3001\u5be6\u969b\u9032\u884crequest\u8f49\u6210response\u7684\u51fd\u5f0f\u3002<br \/>\n\u5148\u9632\u885b\u6027\u6aa2\u67e5\u4e3b\u61c9\u7528\u662f\u5426\u6b63\u5728\u300c\u4e0b\u7dda\u7dad\u8b77\u300d\u72c0\u614b\uff0c\u7136\u5f8c\u6c7a\u5b9a\u662f\u5426\u555f\u52d5session(\uff1f\uff1f\uff1f)\u3002<br \/>\n\u6700\u5f8c\u7531router\u6c7a\u5b9a\u5c07request\u4e1f\u5f80\u54ea\u908a\u8655\u7406\u3001\u4e26\u4e14\u56de\u50b3response\u3002<br \/>\n\u53c3\u8003\uff1a<a href=\"https:\/\/blog.turn.tw\/?page_id=838\" title=\"\u5206\u914d\u5de5\u4f5c\uff1aRouting\/Router.php\">\u5206\u914d\u5de5\u4f5c\uff1aRouting\/Router.php<\/a><\/p>\n<pre>\r\n\t\/**\r\n\t * Terminate the request and send the response to the browser.\r\n\t *\r\n\t * @param  \\Symfony\\Component\\HttpFoundation\\Request  $request\r\n\t * @param  \\Symfony\\Component\\HttpFoundation\\Response  $response\r\n\t * @return void\r\n\t *\/\r\n\tpublic function terminate(SymfonyRequest $request, SymfonyResponse $response)\r\n\t{\r\n\t\t$this->callFinishCallbacks($request, $response);\r\n\r\n\t\t$this->shutdown();\r\n\t}\r\n<\/pre>\n<p>terminate\u51fd\u5f0f\u53ea\u662f\u70ba\u4e86\u57f7\u884c'finish callback'\u800c\u5b58\u5728(\u5982\u679c\u6709\u7684\u8a71)\u3002<br \/>\n\u7136\u5f8c\u518d\u547c\u53ebshutdown\u53bb\u57f7\u884c'shutdown callback'\u3002\u81f3\u65bc\u5169\u7a2ecallback\u7684\u4f7f\u7528\u6642\u6a5f...\u5927\u90e8\u4efd\u60c5\u6cc1\u4e0b\u662f\u4e0d\u6703\u7528\u5230\u7684\u3002<br \/>\n\u53ef\u4ee5\u53c3\u8003\uff1a<br \/>\n<a href=\"http:\/\/laravel.com\/docs\/4.2\/lifecycle\" title=\"Request Lifecycle\">Request Lifecycle<\/a><br \/>\n<a href=\"http:\/\/laravel-recipes.com\/recipes\/52\/understanding-the-request-lifecycle\" title=\"Understanding the Request Lifecycle\">Understanding the Request Lifecycle<br \/>\n<\/a><br \/>\n\u5f97\u5230\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n<pre>\r\n\t\/**\r\n\t * Refresh the bound request instance in the container.\r\n\t *\r\n\t * @param  \\Illuminate\\Http\\Request  $request\r\n\t * @return void\r\n\t *\/\r\n\tprotected function refreshRequest(Request $request)\r\n\t{\r\n\t\t$this->instance('request', $request);\r\n\r\n\t\tFacade::clearResolvedInstance('request');\r\n\t}\r\n\r\n\t\/**\r\n\t * Call the \"finish\" callbacks assigned to the application.\r\n\t *\r\n\t * @param  \\Symfony\\Component\\HttpFoundation\\Request  $request\r\n\t * @param  \\Symfony\\Component\\HttpFoundation\\Response  $response\r\n\t * @return void\r\n\t *\/\r\n\tpublic function callFinishCallbacks(SymfonyRequest $request, SymfonyResponse $response)\r\n\t{\r\n\t\tforeach ($this->finishCallbacks as $callback)\r\n\t\t{\r\n\t\t\tcall_user_func($callback, $request, $response);\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * Call the booting callbacks for the application.\r\n\t *\r\n\t * @param  array  $callbacks\r\n\t * @return void\r\n\t *\/\r\n\tprotected function fireAppCallbacks(array $callbacks)\r\n\t{\r\n\t\tforeach ($callbacks as $callback)\r\n\t\t{\r\n\t\t\tcall_user_func($callback, $this);\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * Prepare the request by injecting any services.\r\n\t *\r\n\t * @param  \\Illuminate\\Http\\Request  $request\r\n\t * @return \\Illuminate\\Http\\Request\r\n\t *\/\r\n\tpublic function prepareRequest(Request $request)\r\n\t{\r\n\t\tif ( ! is_null($this['config']['session.driver']) && ! $request->hasSession())\r\n\t\t{\r\n\t\t\t$request->setSession($this['session']->driver());\r\n\t\t}\r\n\r\n\t\treturn $request;\r\n\t}\r\n\r\n\t\/**\r\n\t * Prepare the given value as a Response object.\r\n\t *\r\n\t * @param  mixed  $value\r\n\t * @return \\Symfony\\Component\\HttpFoundation\\Response\r\n\t *\/\r\n\tpublic function prepareResponse($value)\r\n\t{\r\n\t\tif ( ! $value instanceof SymfonyResponse) $value = new Response($value);\r\n\r\n\t\treturn $value->prepare($this['request']);\r\n\t}\r\n\r\n\t\/**\r\n\t * Determine if the application is ready for responses.\r\n\t *\r\n\t * @return bool\r\n\t *\/\r\n\tpublic function readyForResponses()\r\n\t{\r\n\t\treturn $this->booted;\r\n\t}\r\n\r\n\t\/**\r\n\t * Determine if the application is currently down for maintenance.\r\n\t *\r\n\t * @return bool\r\n\t *\/\r\n\tpublic function isDownForMaintenance()\r\n\t{\r\n\t\treturn file_exists($this['config']['app.manifest'].'\/down');\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a maintenance mode event listener.\r\n\t *\r\n\t * @param  \\Closure  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function down(Closure $callback)\r\n\t{\r\n\t\t$this['events']->listen('illuminate.app.down', $callback);\r\n\t}\r\n\r\n\t\/**\r\n\t * Throw an HttpException with the given data.\r\n\t *\r\n\t * @param  int     $code\r\n\t * @param  string  $message\r\n\t * @param  array   $headers\r\n\t * @return void\r\n\t *\r\n\t * @throws \\Symfony\\Component\\HttpKernel\\Exception\\HttpException\r\n\t * @throws \\Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException\r\n\t *\/\r\n\tpublic function abort($code, $message = '', array $headers = array())\r\n\t{\r\n\t\tif ($code == 404)\r\n\t\t{\r\n\t\t\tthrow new NotFoundHttpException($message);\r\n\t\t}\r\n\r\n\t\tthrow new HttpException($code, $message, null, $headers);\r\n\t}\r\n\r\n\t\/**\r\n\t * Register a 404 error handler.\r\n\t *\r\n\t * @param  \\Closure  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function missing(Closure $callback)\r\n\t{\r\n\t\t$this->error(function(NotFoundHttpException $e) use ($callback)\r\n\t\t{\r\n\t\t\treturn call_user_func($callback, $e);\r\n\t\t});\r\n\t}\r\n\r\n\t\/**\r\n\t * Register an application error handler.\r\n\t *\r\n\t * @param  \\Closure  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function error(Closure $callback)\r\n\t{\r\n\t\t$this['exception']->error($callback);\r\n\t}\r\n\r\n\t\/**\r\n\t * Register an error handler at the bottom of the stack.\r\n\t *\r\n\t * @param  \\Closure  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function pushError(Closure $callback)\r\n\t{\r\n\t\t$this['exception']->pushError($callback);\r\n\t}\r\n\r\n\t\/**\r\n\t * Register an error handler for fatal errors.\r\n\t *\r\n\t * @param  \\Closure  $callback\r\n\t * @return void\r\n\t *\/\r\n\tpublic function fatal(Closure $callback)\r\n\t{\r\n\t\t$this->error(function(FatalErrorException $e) use ($callback)\r\n\t\t{\r\n\t\t\treturn call_user_func($callback, $e);\r\n\t\t});\r\n\t}\r\n\r\n\t\/**\r\n\t * Get the configuration loader instance.\r\n\t *\r\n\t * @return \\Illuminate\\Config\\LoaderInterface\r\n\t *\/\r\n\tpublic function getConfigLoader()\r\n\t{\r\n\t\treturn new FileLoader(new Filesystem, $this['path'].'\/config');\r\n\t}\r\n\r\n\t\/**\r\n\t * Get the environment variables loader instance.\r\n\t *\r\n\t * @return \\Illuminate\\Config\\EnvironmentVariablesLoaderInterface\r\n\t *\/\r\n\tpublic function getEnvironmentVariablesLoader()\r\n\t{\r\n\t\treturn new FileEnvironmentVariablesLoader(new Filesystem, $this['path.base']);\r\n\t}\r\n\r\n\t\/**\r\n\t * Get the service provider repository instance.\r\n\t *\r\n\t * @return \\Illuminate\\Foundation\\ProviderRepository\r\n\t *\/\r\n\tpublic function getProviderRepository()\r\n\t{\r\n\t\t$manifest = $this['config']['app.manifest'];\r\n\r\n\t\treturn new ProviderRepository(new Filesystem, $manifest);\r\n\t}\r\n\r\n\t\/**\r\n\t * Get the service providers that have been loaded.\r\n\t *\r\n\t * @return array\r\n\t *\/\r\n\tpublic function getLoadedProviders()\r\n\t{\r\n\t\treturn $this->loadedProviders;\r\n\t}\r\n\r\n\t\/**\r\n\t * Set the application's deferred services.\r\n\t *\r\n\t * @param  array  $services\r\n\t * @return void\r\n\t *\/\r\n\tpublic function setDeferredServices(array $services)\r\n\t{\r\n\t\t$this->deferredServices = $services;\r\n\t}\r\n\r\n\t\/**\r\n\t * Determine if the given service is a deferred service.\r\n\t *\r\n\t * @param  string  $service\r\n\t * @return bool\r\n\t *\/\r\n\tpublic function isDeferredService($service)\r\n\t{\r\n\t\treturn isset($this->deferredServices[$service]);\r\n\t}\r\n\r\n\t\/**\r\n\t * Get or set the request class for the application.\r\n\t *\r\n\t * @param  string  $class\r\n\t * @return string\r\n\t *\/\r\n\tpublic static function requestClass($class = null)\r\n\t{\r\n\t\tif ( ! is_null($class)) static::$requestClass = $class;\r\n\r\n\t\treturn static::$requestClass;\r\n\t}\r\n\r\n\t\/**\r\n\t * Set the application request for the console environment.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tpublic function setRequestForConsoleEnvironment()\r\n\t{\r\n\t\t$url = $this['config']->get('app.url', 'http:\/\/localhost');\r\n\r\n\t\t$parameters = array($url, 'GET', array(), array(), array(), $_SERVER);\r\n\r\n\t\t$this->refreshRequest(static::onRequest('create', $parameters));\r\n\t}\r\n\r\n\t\/**\r\n\t * Call a method on the default request class.\r\n\t *\r\n\t * @param  string  $method\r\n\t * @param  array  $parameters\r\n\t * @return mixed\r\n\t *\/\r\n\tpublic static function onRequest($method, $parameters = array())\r\n\t{\r\n\t\treturn forward_static_call_array(array(static::requestClass(), $method), $parameters);\r\n\t}\r\n\r\n\t\/**\r\n\t * Get the current application locale.\r\n\t *\r\n\t * @return string\r\n\t *\/\r\n\tpublic function getLocale()\r\n\t{\r\n\t\treturn $this['config']->get('app.locale');\r\n\t}\r\n\r\n\t\/**\r\n\t * Set the current application locale.\r\n\t *\r\n\t * @param  string  $locale\r\n\t * @return void\r\n\t *\/\r\n\tpublic function setLocale($locale)\r\n\t{\r\n\t\t$this['config']->set('app.locale', $locale);\r\n\r\n\t\t$this['translator']->setLocale($locale);\r\n\r\n\t\t$this['events']->fire('locale.changed', array($locale));\r\n\t}\r\n\r\n\t\/**\r\n\t * Register the core class aliases in the container.\r\n\t *\r\n\t * @return void\r\n\t *\/\r\n\tpublic function registerCoreContainerAliases()\r\n\t{\r\n\t\t$aliases = array(\r\n\t\t\t'app'            => 'Illuminate\\Foundation\\Application',\r\n\t\t\t'artisan'        => 'Illuminate\\Console\\Application',\r\n\t\t\t'auth'           => 'Illuminate\\Auth\\AuthManager',\r\n\t\t\t'auth.reminder.repository' => 'Illuminate\\Auth\\Reminders\\ReminderRepositoryInterface',\r\n\t\t\t'blade.compiler' => 'Illuminate\\View\\Compilers\\BladeCompiler',\r\n\t\t\t'cache'          => 'Illuminate\\Cache\\CacheManager',\r\n\t\t\t'cache.store'    => 'Illuminate\\Cache\\Repository',\r\n\t\t\t'config'         => 'Illuminate\\Config\\Repository',\r\n\t\t\t'cookie'         => 'Illuminate\\Cookie\\CookieJar',\r\n\t\t\t'encrypter'      => 'Illuminate\\Encryption\\Encrypter',\r\n\t\t\t'db'             => 'Illuminate\\Database\\DatabaseManager',\r\n\t\t\t'events'         => 'Illuminate\\Events\\Dispatcher',\r\n\t\t\t'files'          => 'Illuminate\\Filesystem\\Filesystem',\r\n\t\t\t'form'           => 'Illuminate\\Html\\FormBuilder',\r\n\t\t\t'hash'           => 'Illuminate\\Hashing\\HasherInterface',\r\n\t\t\t'html'           => 'Illuminate\\Html\\HtmlBuilder',\r\n\t\t\t'translator'     => 'Illuminate\\Translation\\Translator',\r\n\t\t\t'log'            => 'Illuminate\\Log\\Writer',\r\n\t\t\t'mailer'         => 'Illuminate\\Mail\\Mailer',\r\n\t\t\t'paginator'      => 'Illuminate\\Pagination\\Factory',\r\n\t\t\t'auth.reminder'  => 'Illuminate\\Auth\\Reminders\\PasswordBroker',\r\n\t\t\t'queue'          => 'Illuminate\\Queue\\QueueManager',\r\n\t\t\t'redirect'       => 'Illuminate\\Routing\\Redirector',\r\n\t\t\t'redis'          => 'Illuminate\\Redis\\Database',\r\n\t\t\t'request'        => 'Illuminate\\Http\\Request',\r\n\t\t\t'router'         => 'Illuminate\\Routing\\Router',\r\n\t\t\t'session'        => 'Illuminate\\Session\\SessionManager',\r\n\t\t\t'session.store'  => 'Illuminate\\Session\\Store',\r\n\t\t\t'remote'         => 'Illuminate\\Remote\\RemoteManager',\r\n\t\t\t'url'            => 'Illuminate\\Routing\\UrlGenerator',\r\n\t\t\t'validator'      => 'Illuminate\\Validation\\Factory',\r\n\t\t\t'view'           => 'Illuminate\\View\\Factory',\r\n\t\t);\r\n\r\n\t\tforeach ($aliases as $key => $alias)\r\n\t\t{\r\n\t\t\t$this->alias($key, $alias);\r\n\t\t}\r\n\t}\r\n\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Laravel\u6846\u67b6\u4e2d\uff0crouting\u3001\u63a5\u6536request\u3001\u767c\u9001response\u5e7e\u4ef6\u4e8b\u662f\u7531Symphony\u7684\u5143\u4ef6 &hellip; <a href=\"https:\/\/blog.turn.tw\/?page_id=813\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">Laravel\u6838\u5fc3\u5be6\u9ad4\uff1aFoundation\/Application.php<\/span> <span class=\"meta-nav\">&rarr;<\/span> <\/a><\/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\/813"}],"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=813"}],"version-history":[{"count":28,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages\/813\/revisions"}],"predecessor-version":[{"id":914,"href":"https:\/\/blog.turn.tw\/index.php?rest_route=\/wp\/v2\/pages\/813\/revisions\/914"}],"wp:attachment":[{"href":"https:\/\/blog.turn.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}