Laravel5.1学习笔记9 系统架构1 请求生命周期 (待修)
Request Lifecycle
Introduction
When using any tool in the "real world", you feel more confident if you understand how that tool works. Application development is no different. When you understand how your development tools function, you feel more comfortable and confident using them.
The goal of this document is to give you a good, high-level overview of how the Laravel framework "works". By getting to know the overall framework better, everything feels less "magical" and you will be more confident building your applications.
If you don't understand all of the terms right away, don't lose heart! Just try to get a basic grasp of what is going on, and your knowledge will grow as you explore other sections of the documentation.
当你更明白整个框架,所有的东西就不会在神奇, 你不很理解也没有关系,随着使用深入,你的知识会不断增长。
#生命周期概览
首要之事
The entry point for all requests to a Laravel application is the public/index.php file. All requests are directed to this file by your web server (Apache / Nginx) configuration. Theindex.php file doesn't contain much code. Rather, it is simply a starting point for loading the rest of the framework.
public/index.php 文件是对Laravel应用所有请求的进入点,所有请求都通过你的网页服务器(Apache/ Nginx )配置导向这个文件. Index.php 这个文件没有多少代码,它只是个起始点,去加载框架其他部分
The index.php file loads the Composer generated autoloader definition, and then retrieves an instance of the Laravel application from bootstrap/app.php script. The first action taken by Laravel itself is to create an instance of the application / service container.
Index.php 加载的是Composer生成的自动加载器定义, 然后接收一个由bootstrap/app.php 脚本产生的Laravel应用实例。 Laravel自身的第一个动作就是创建一个应用程序容器,或者说是服务容器实例。
HTTP / 终端核心
Next, the incoming request is sent to either the HTTP kernel or the console kernel, depending on the type of request that is entering the application. These two kernels serve as the central location that all requests flow through. For now, let's just focus on the HTTP kernel, which is located in app/Http/Kernel.php.
接下来,进入应用程序的请求会被送往HTTP核心,终端核心, 视请求的种类而定, 这两种核心是所有请求流向的中心位置, 现在我们只将焦点放在HTTP核心, 它位于app/Http/Kernel.php
The HTTP kernel extends the Illuminate\Foundation\Http\Kernel class, which defines an array ofbootstrappers that will be run before the request is executed. These bootstrappers configure error handling, configure logging, detect the application environment, and perform other tasks that need to be done before the request is actually handled.
HTTP核心扩展了Illuminate\Foundation\Http\Kernel 类, 它定义了一个bootstrappers 数组, 在请求被执行前会执行,这些启动器(bootstrapper)会配置, 错误处理,日志记录, 检测应用环境, 和其他请求被真正处理前需要完成的工作。
The HTTP kernel also defines a list of HTTP middleware that all requests must pass through before being handled by the application. These middleware handle reading and writing theHTTP session, determine if the application is in maintenance mode, verifying the CSRF token, and more.
HTTP核心也定义了一份HTTP中间件清单, 所有的请求在被应用程序处理之前都必须经过它们。 这些中间件有负责处理HTTP session的读写, 决定应用程序是否处于维护模式, 验证跨站请求伪造(CSRF)标记, 以及其他更多的功能。
The method signature for the HTTP kernel's handle method is quite simple: receive aRequest and return a Response. Think of the Kernel as being a big black box that represents your entire application. Feed it HTTP requests and it will return HTTP responses.
HTTP核心 handle 方法的签名相当简单: 它接收一个Request并返回一个Response. 把核心想象成一个大黑盒子,用来代表你整个的应用程序。 对它输入的HTTP请求, 它将返回HTTP响应。
服务提供者
One of the most important Kernel bootstrapping actions is loading the service providersfor your application. All of the service providers for the application are configured in theconfig/app.php configuration file's providers array. First, the register method will be called on all providers, then, once all providers have been registered, the boot method will be called.
最重要的核心启动行为之一,是加载您的应用程序的服务提供者。 所有的服务提供者,都在config/app.php 配置文件的 providers 数组中被配置。 首先, 对所有的提供者调用register 方法, 一旦所有的提供者都被注册后,boot 方法也会被调用。
Service providers are responsible for bootstrapping all of the framework's various components, such as the database, queue, validation, and routing components. Since they bootstrap and configure every feature offered by the framework, service providers are the most important aspect of the entire Laravel bootstrap process.
服务提供者负责启动所有框架的不同组件, 像是数据库database, 队列queue, 验证, 路由组件。因为它们启动和配置所有和框架有关的特性。 服务提供者是整个Laravel启动过程中最重要的地方。
请求分派
Once the application has been bootstrapped and all service providers have been registered, the Request will be handed off to the router for dispatching. The router will dispatch the request to a route or controller, as well as run any route specific middleware.
一旦应用程序启动且所有的服务提供者都被注册后, Request会被移交给路由器进行分派。 路由器会将请求分派给路由或控制器, 并执行任何特定路由的中间件。
#聚焦于服务提供者
Service providers are truly the key to bootstrapping a Laravel application. The application instance is created, the service providers are registered, and the request is handed to the bootstrapped application. It's really that simple!
服务提供者是启动Laravel应用程序的真正关键。创建应用实例,注册服务提供者, 将请求转至已经启动的应用程序。 真的就这么简单。
Having a firm grasp of how a Laravel application is built and bootstrapped via service providers is very valuable. Of course, your application's default service providers are stored in the app/Providers directory.
能确实掌握Laravel应用程序是如何建立,并通过服务提供者启动是很有价值的。 应用程序的默认服务提供者在 app/Providers 这个目录内。
By default, the AppServiceProvider is fairly empty. This provider is a great place to add your application's own bootstrapping and service container bindings. Of course, for large applications, you may wish to create several service providers, each with a more granular type of bootstrapping.
AppServiceProviders默认几乎是空的,此提供者是一个很好的地方,可以让你加入应用程序自身的启动及对服务容器的绑定。 当然,对于大型应用,你可以希望创建若干个服务提供者,每个都具备更精细的启动类型。
Laravel5.1学习笔记9 系统架构1 请求生命周期 (待修)的更多相关文章
- Laravel5.1学习笔记i14 系统架构6 Facade
Facades 介绍 使用 Facades Facade 类参考 #介绍 Facades provide a "static" interface to classes th ...
- Laravel5.1学习笔记12 系统架构4 服务容器
Service Container 介绍 绑定的用法 绑定实例到接口 上下文绑定 标签 解析 容器事件 #介绍 The Laravel service container is a powerful ...
- Laravel5.1学习笔记13 系统架构5 Contract
Contract 简介 为什么要用 Contract? Contract 参考 如何使用 Contract 简介 Laravel 中的 Contract 是一组定义了框架核心服务的接口.例如,Illu ...
- Laravel5.1学习笔记11 系统架构3 服务提供者
服务提供者 简介 写一个服务提供者 Register注册方法 Boot 方法 注册提供者 缓载提供者 简介 Service providers are the central place of all ...
- Laravel5.1学习笔记10 系统架构2 应用程序结构
应用程序结构 简介 根目录 App 目录 为应用程序设置命名空间 简介 默认的 Laravel 应用程序结构是为了给无论构建大型还是小型应用程序都提供一个良好的开始.当然,你可以依照喜好自由地组织应用 ...
- Android学习笔记(五)——活动的生命周期
//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 为了能写出流畅连贯的程序,我们需要了解一下活动的生命周期. 一.返回栈 Android 中的活动是可以层叠的. ...
- 【React】学习笔记(二)——组件的生命周期、React脚手架使用
原教程视频:ttps://www.bilibili.com/video/BV1wy4y1D7JT?p=2&spm_id_from=pageDriver 目录 一.组件的生命周期 1.1.生命周 ...
- Laravel5.1 学习笔记1, 目录结构和命名空间(待修)
自从用 Laravel4做了个小网站,使用了数据库ORM Eloquent, 就放下了一段时间,想不到这个与Asp.net MVC 有着异曲同工之妙的框架已经出了下个版本,而且还有不小的改动,因此不得 ...
- Android学习笔记(十) Activity的生命周期
一.如何在一个应用程序中定义多个Activity -定义一个类,继承Activity -复写onCreate() setContentView(R.layout.secondLayout):设定该Ac ...
随机推荐
- 【XSY3413】Lambda - 造计算机初步——邱奇-图灵论题与lambda演算
题意: 关于邱奇-图灵论题的一点思考 这道题起源于计算机科学史上一个非常著名的问题——邱奇-图灵论题,这个论题是可计算性理论的基石,关于它的思考与证明几乎贯穿了整个计算机科学史,涵盖了数学.算法理论. ...
- const浅析
前言 c++中使用到const的地方有很多, 而且const 本身也针对不同的类型可能有不同的含义, 比如对指针就有顶层和底层. 本节就是探讨关于C++中const的在不同的地方不同表现或含义. co ...
- 基本数据类型:布尔型(bool)和空值None
一.布尔型(bool) 布尔类型很简单,就两个值 ,一个True(真),一个False(假), 主要用记逻辑判断: 一件事情成立就是True,不成立就是False,也可以将bool值归类为数字, 是因 ...
- 6.3.4 使用marshal 模块操作二进制文件
Python 标准库 marshal 也可以进行对象的序列化和反序列化,下面的代码进行了简单演示. import marshal x1 = 30 x2 = 5.0 x3 = [1,2,3] x4 = ...
- vim学习1-入门指令
使用vim命令进入vim界面 vim后面加上你要打开的已存在的文件名或者不存在(则作为新建文件)的文件名. 打开Xfce终端,输入以下命令 $ vim practice_1.txt 直接使用vim也可 ...
- JavaSE 学习笔记之StringBuilder(十六)
< java.lang >-- StringBuilder字符串缓冲区:★★★☆ JDK1.5出现StringBuiler:构造一个其中不带字符的字符串生成器,初始容量为 16 个字符.该 ...
- spring boot 中访问 REST 接口
RestTemplate restTemplate = new RestTemplate(); Object result = restTemplate.getForObject("http ...
- Hadoop2.2.0 注意事项
1.启动前必须把防火墙关了,要不然会导致nodemanager启动不了. 关闭防火墙:service iptables stop 永久关闭(重启后默认关闭):chkconfig iptables of ...
- Java 和JS Base64加密
项目在登录.注册等场景实现时,经常会用到用户信息前端加密,然后项目后端二次解密,避免信息直接在浏览器上以明文显示. 本文主要介绍了base64加密的方式处理代码,不支持中文 源码如下: base64. ...
- EPEL reporsitory
在centos 5上yum install git的时候报错说没有git这个package. 这是因为centos的软件策略非常保守,因为它基本就是redhat企业版的copy.所以想在centos5 ...