Laravel Application Container App

Source: Internet
Author: User
<span id="Label3"></p><p><p>vendor/laravel/framework/src/illuminate/foundation/application.php</p></p>Application is the core container of laravel, which is needed for almost everything, with the main features:<p><p>1. The app first inherits the container, as a container class exists</p></p><p><p>2. The underlying class that is required for the Laravel run process is registered, and the instance that is required for the run is Generated. Assumed the initialization Function.</p></p><p><p>Here you need to say, the app says the so-called registration, not refers to the binding, should be directly instantiated directly, and injected into the Container. however, for provider, the provider is instantiated and run, and the actual class is not generated, but the class is bound.</p></p><p><p>3. Additional features that are more convenient, mainly related to the environment of the program, such as: provider processing run is here, config app inside the configuration is read and processed in this class.</p></p>The specific functions are as Follows: 1. Container's function is not said, the previous microblog has described This. 2. The most basic classes required to register a program in operation<p><p><strong>In the <span style="color: #ffc66d;">__construct</span>: constructor, handle:</strong></p></p><p><p>If ($basePath) {<br>$this->setbasepath ($basePath);<br>}<br>$this->registerbasebindings ();<br>$this->registerbaseserviceproviders ();<br>$this->registercorecontaineraliases ();</p></p><p><p></p></p>Setbasepath The basic path is added to the container instance, which is also the majority of the framework needs to do all things, to prevent the relative absolute, such as the use of the various paths of confusion, total added so many:<p><p>$this->instance (' path ', $this->path ());<br>$this->instance (' path.base ', $this->basepath ());<br>$this->instance (' Path.lang ', $this->langpath ());<br>$this->instance (' path.config ', $this->configpath ());<br>$this->instance (' path.public ', $this->publicpath ());<br>$this->instance (' path.storage ', $this->storagepath ());<br>$this->instance (' path.database ', $this->databasepath ());<br>$this->instance (' path.resources ', $this->resourcepath ());<br>$this->instance (' path.bootstrap ', $this->bootstrappath ());</p></p><p><p></p></p>Registerbasebindings<p><p>Register the basic binding, add the app itself into the container instance, and then, packagemanifest add to the container instance, This function can handle some default provider and aliases, This function follow up to expand the Description.</p></p>Registerbaseserviceproviders<p><p>Register the basic providers, including the three parts of Event/log/router</p></p><p><p>event:vendor/laravel/framework/src/illuminate/events/eventserviceprovider.php</p></p><p><p>log:vendor/laravel/framework/src/illuminate/log/logserviceprovider.php</p></p><p><p>router:vendor/laravel/framework/src/illuminate/routing/routingserviceprovider.php</p></p><p><p>Router's provider, Unlike anything else, provides several related bindings: router URL redirect Psr\http\message\serverrequestinterface psr\http\message\ Responseinterface illuminate\contracts\routing\responsefactory Illuminate\routing\contracts\controllerdispatcher</p></p>Registercorecontaineraliases register some of the core aliases, including:<p>' App ' = [\illuminate\foundation\application::class, \illuminate\contracts\container\container::class, \illuminate\contracts\foundation\application::class, \psr\container\containerinterface::class],<br>' Auth ' = [\illuminate\auth\authmanager::class, \illuminate\contracts\auth\factory::class],<br>' Auth.driver ' = [\illuminate\contracts\auth\guard::class],<br>' Blade.compiler ' = [\illuminate\view\compilers\bladecompiler::class],<br>' Cache ' = [\illuminate\cache\cachemanager::class, \illuminate\contracts\cache\factory::class],<br>' Cache.store ' = [\illuminate\cache\repository::class, \illuminate\contracts\cache\repository::class],<br>' Config ' = [\illuminate\config\repository::class, \illuminate\contracts\config\repository::class],<br>' Cookie ' = [\illuminate\cookie\cookiejar::class, \illuminate\contracts\cookie\factory::class, \Illuminat e\contracts\cookie\queueingfactory::class],<br>' Encrypter ' = [\illuminate\encryption\encrypter::class, \illuminate\contracts\encryption\encrypter::class],<br>' db ' = [\illuminate\database\databasemanager::class],<br>' Db.connection ' = [\illuminate\database\connection::class, \illuminate\database\connectioninterface::class],<br>' Events ' = [\illuminate\events\dispatcher::class, \illuminate\contracts\events\dispatcher::class],<br>' Files ' = [\illuminate\filesystem\filesystem::class],<br>' FileSystem ' = [\illuminate\filesystem\filesystemmanager::class, \illuminate\contracts\filesystem\factory::c lass],<br>' Filesystem.disk ' = [\illuminate\contracts\filesystem\filesystem::class],<br>' Filesystem.cloud ' = [\illuminate\contracts\filesystem\cloud::class],<br>' Hash ' = [\illuminate\contracts\hashing\hasher::class],<br>' Translator ' = [\illuminate\translation\translator::class, \illuminate\contracts\translation\translator::cla ss],<br>' Log ' = [\illuminate\log\writer::class, \illuminate\contracts\logging\log::class, \psr\log\loggerinte rface::class],<br>' Mailer ' = [\illuminate\mail\mailer::class, \illuminate\contracts\mail\mailer::class, \illuminate\contra cts\mail\mailqueue::class],<br>' Auth.password ' = [\illuminate\auth\passwords\passwordbrokermanager::class, \illuminate\contracts\auth\ passwordbrokerfactory::class],<br>' Auth.password.broker ' = [\illuminate\auth\passwords\passwordbroker::class, \illuminate\contracts\auth\ passwordbroker::class],<br>' Queue ' = [\illuminate\queue\queuemanager::class, \illuminate\contracts\queue\factory::class, \Illumina te\contracts\queue\monitor::class],<br>' Queue.connection ' = [\illuminate\contracts\queue\queue::class],<br>' Queue.failer ' = [\illuminate\queue\failed\failedjobproviderinterface::class],<br>' Redirect ' = [\illuminate\routing\redirector::class],<br>' Redis ' = [\illuminate\redis\redismanager::class, \illuminate\contracts\redis\factory::class],<br>' Request ' = [\illuminate\http\request::class, \symfony\component\httpfoundation\request::class],<br>' Router ' = [\illuminate\routing\router::class, \illuminate\contracts\routing\registrar::class, \Illumina te\contracts\routing\bindingregistrar::class],<br>' Session ' = [\illuminate\session\sessionmanager::class],<br>' Session.store ' = [\illuminate\session\store::class, \illuminate\contracts\session\session::class],<br>' url ' = = [\illuminate\routing\urlgenerator::class, \illuminate\contracts\routing\urlgenerator::class],<br>' Validator ' = [\illuminate\validation\factory::class, \illuminate\contracts\validation\factory::class],<br>' View ' = [\illuminate\view\factory::class, \illuminate\contracts\view\factory::class],</p>so, the contents of the app after the initialization are as Follows: bindings contains the following content:<p><p>Events</p></p><p><p>Log<br>Router<br>Url<br>redirect<br>Psr\http\message\serverrequestinterface<br>Psr\http\message\responseinterface<br>Illuminate\contracts\routing\responsefactory<br>Illuminate\routing\contracts\controllerdispatcher</p></p><p><p></p></p><p><p>To sum up, when application is initialized, it is done with a few things:</p></p><p><p>1. Locate yourself and determine the directory in which the file is run</p></p><p><p>2. Throw yourself into the container and instantiate the package class that is used to reference other code into the Container.</p></p><p><p>3. Log/event/router three basic functions to improve provider</p></p><p><p>4. Binding aliases, of course, many aliases, this time, is actually INVALID. Because it is not bound to the actual class at all, it is estimated to be Empty.</p></p><p><p></p></p>Features extended outside of container:<p><p>1. The additional initialization function is provided at startup, and the registration of related events is added, the main function bootstrapwith.</p></p><p><p>Add Event bootstrapping bootstrapped and register all the initialization features provided by the outer class. Prepares the program to run parameters and inject the Environment.</p></p><p><p>2. registerconfiguredproviders function, read <span style="color: #6a8759;">app.providers</span> inside the definition of provider, and Register.</p></p><p><p>3. Provider processing, main functions, register (registration provider), boot, etc.</p></p><p><p>4. Delay Loading deferredservices, delay loading of the provider, just registered into the container, but does not instantiate provider, only when the related class is called, will run provider to Register.</p></p><p><p>5.handle calls kernel directly to handle the request and is also an egress function for network access.</p></p><p><p></p></p><p><p>Outside of container, The app adds the concept of provider and adds the concept of request related processing, wrapping container as a new container for handling network Requests.</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p>Instances has the following contents:<p>Path::/users/yuxuezhong/git/webservice/api/app<br>Path.base::/users/yuxuezhong/git/webservice/api<br>Path.lang::/users/yuxuezhong/git/webservice/api/resources/lang<br>Path.config::/users/yuxuezhong/git/webservice/api/config<br>Path.public::/users/yuxuezhong/git/webservice/api/public<br>Path.storage::/users/yuxuezhong/git/webservice/api/storage<br>Path.database::/users/yuxuezhong/git/webservice/api/database<br>Path.resources::/users/yuxuezhong/git/webservice/api/resources<br>Path.bootstrap::/users/yuxuezhong/git/webservice/api/bootstrap<br>App::illuminate\foundation\application<br>Illuminate\container\container::illuminate\foundation\application<br>Illuminate\foundation\packagemanifest::illuminate\foundation\packagemanifest</p><p><p></p></p><p><p></p></p><p><p></p></p><p><p><br></p></p><p><p></p></p><p><p>Laravel Application Container App</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.