

This object is unique in the whole life cycle of laravel, because it is singleton. Who is the app here? It is the object of the application class. Back to the bootstrap method, it calls the app > bootstrap with method. Its contents are as follows:įor the above, we only need to care about the registerffacades class. The return value of this method is an array.

Here, the bootstrappers method is called first. The bootstrap method is simple as follows: There is only one line in this function that we care about, as follows: It has nothing to do with our analysis of the current target. We don’t have to care about its parameter $request. Let’s take a look at this method, sendrequestthroughrouter.
#Facade signage serial number code
For us to analyze facade, only one line of code is critical, which is as follows: Through the above analysis, we know that this handle method belongs to the illuminate / foundation / HTTP / kernel class. Let’s go back to it index.php In the file, laravel calls: This kernel class is inherited from the illuminate / foundation / HTTP / kernel class. Who is the target of illuminate / contracts / HTTP / kernel:: class? The location of this file is as follows: Go back to index.php File, continue to look at the following line of code: I hope you must remember that this will be used later. The above code adds a singleton to the container, so when we create an object of illuminate, contracts, HTTP, kernel:: class, we actually create an object of app, HTTP, kernel:: class. Note that the application class inherits from the container class (this class is the core of the laravel container), so we can use the This is why I remind you at the beginning of this blog that you need some knowledge about containers. This class represents our current application and is the core class of the whole laravel.

So what does this document do? Now we only care about the following two lines:Īn application class object is created above. As you all know, the entry file of laravel is public/ index.php The following line of code is critical. In order to talk about facade to my brothers, I’d like to give you a general introduction to the boot process of laravel (only focusing on the parts related to facade). If I just say these things, maybe my brothers will say, I know, what else do you say? Indeed, I’m sorry to say that, but the following content is not so easy. There is nothing to say about these things. If you are interested, you can see the official documents that clearly describe them, Developing third party laravel packages。 Of course, there is more than one way to register facades and serviceproviders.

If you have used a third-party composer package, it will remind you to write its serviceprovider and facade to config/ app.php In the document, it is as follows: I hope I can gain something by digesting it carefully. Once again, I would like to remind you that this blog post has a large capacity. If you are not familiar with it, please read it Laravel containerThis knowledge is very necessary for us to understand what I’m going to talk about today. Before reading this article, I hope you have a certain understanding of the container of laravel.
