[SF] Symfony 标准 HttpFoundation\Request 实现分析
使用方式
/**
* 如果直接示例化 Request 默认是没有参数的,可以自己传入
* 本方法将 PHP 超全局变量作为参数然后实例化自身(Request)进行初始化。
*/
$request = Request::createFromGlobals();
表面的 Request 对象格式
+ 是公开属性,# 是受保护属性,- 是私有属性
源码中 Request 参数的初始化过程
/**
* Sets the parameters for this request.
*
* This method also re-initializes all properties.
*
* @param array $query The GET parameters
* @param array $request The POST parameters
* @param array $attributes The request attributes (parameters parsed from the PATH_INFO, ...)
* @param array $cookies The COOKIE parameters
* @param array $files The FILES parameters
* @param array $server The SERVER parameters
* @param string|resource $content The raw body data
*/
public function initialize(array $query = array(), array $request = array(), array $attributes = array(), array $cookies = array(), array $files = array(), array $server = array(), $content = null)
{
$this->request = new ParameterBag($request);
$this->query = new ParameterBag($query);
$this->attributes = new ParameterBag($attributes);
$this->cookies = new ParameterBag($cookies);
$this->files = new FileBag($files);
$this->server = new ServerBag($server);
$this->headers = new HeaderBag($this->server->getHeaders()); $this->content = $content;
$this->languages = null;
$this->charsets = null;
$this->encodings = null;
$this->acceptableContentTypes = null;
$this->pathInfo = null;
$this->requestUri = null;
$this->baseUrl = null;
$this->basePath = null;
$this->method = null;
$this->format = null;
}
源码中 ParameterBag 参数包装细节
class ParameterBag implements \IteratorAggregate, \Countable
{
/**
* Parameter storage.
*/
protected $parameters; /**
* @param array $parameters An array of parameters
*/
public function __construct(array $parameters = array())
{
$this->parameters = $parameters;
} /**
* Returns the parameters.
*
* @return array An array of parameters
*/
public function all()
{
return $this->parameters;
} // 其它实现的方法
// ...
}
小结
通过以上了解,完全透过 OOP 方式可以访问请求过程中的任何参数。
$request->attributes->get('q');
$request->server->get('SCRIPT_NAME');
$request->query->all( );
$request->request->keys();
$request->cookies->remove('sc');
$request->get('q'); # 依次从 attributes,query,request 检测是否有key的值,有就返回;兼容 get、post 方法时使用,否则建议访问对应公开属性上的方法,例如:$request->query->get('q');
并且 Request 提供了很多封装的便捷方法。
$request->getScriptName(); # 等同 $request->server->get('SCRIPT_NAME');
Link:https://www.cnblogs.com/farwish/p/9615790.html
[SF] Symfony 标准 HttpFoundation\Request 实现分析的更多相关文章
- sf中标准的分页功能介绍
世上本无事,庸人自扰之.我喜欢一个相对比较安静的环境去学习和工作,希望在一个掉一根针的声音都能够听到的环境中,但是有时候往往相反,一片嘈杂,我改变不了周围的环境,只能改变自己,其实这些都没有什么,也许 ...
- 序列化与反序列化、def的介绍与快速使用、cbv源码分析、APIView与request对象分析
今日内容概要 序列化与反序列化 def介绍和快速使用 cbv源码流程分析 drf之APIView和Request对象分析 内容详细 1.序列化和反序列化 # api接口开发 最核心最常见的一个过程就是 ...
- 《BI那点儿事》运用标准计分和离差——分析三国超一流统帅综合实力排名 绝对客观,数据说话
数据分析基础概念:标准计分: 1.无论作为变量的满分为几分,其标准计分的平均数势必为0,而其标准差势必为1.2.无论作为变量的单位是什么,其标准计分的平均数势必为0,而其标准差势必为1.公式为: 离差 ...
- [SF] Symfony 组件 BrowserKit 原理
直接看下面的注释中针对每一个文件的作用说明. <?php /** * BrowserKit - Make internal requests to your application. * * I ...
- [SF] Symfony 在 console 中结合 Workerman
在web框架的console中,命令不再是直接指定入口文件,如以往 php test.php start,而是类似 php app/console do 的形式. workerman 对命令的解析是 ...
- laravel中的$request对象构造及请求生命周期
laravel应用程序中index.php是所有请求的入口.当用户提交一个form或者访问一个网页时,首先由kernel捕捉到该session PHP运行环境下的用户数据, 生成一个request对象 ...
- symfony学习笔记1—简介
1.symfony快速入门还是先看代码结构把,这个是拿到代码的第一印象,app/:整个应用的配置,模版,translations,这个可能是多语言文件什么,src/:项目php文件,vendor/:第 ...
- 跟我一起用Symfony写一个博客网站;
我的微信公众号感兴趣的话可以扫一下, 或者加微信号 whenDreams 第一部分:基础设置,跑起一个页面-首页 第一步: composer create-project symfony/fram ...
- Symfony启动过程详细学习
想了解symfony的启动过程,必须从启动文件(这里就以开发者模式)开始. <?php /* * web/app_dev.php */ $loader = require_once __DIR_ ...
随机推荐
- R并行计算
# 参考文献: https://cosx.org/2016/09/r-and-parallel-computinghttps://blog.csdn.net/sinat_26917383/articl ...
- 我发起了一个 支持 ServerFul 架构 的 .Net 开源项目 ServerFulManager
大家好, 我发起了一个 支持 ServerFul 架构 的 .Net 开源项目 ServerFulManager . ServerFulManager 的 目标 是 实现一个 支持 ServerFu ...
- 【转】百度UEditor控件中的map组件不支持https使用的问题解决
原文地址:https://blog.csdn.net/stacy06/article/details/82626363 最近项目部署到了https环境下,使用的UEditor富文本编辑器中的map组件 ...
- Spring众多jar包的特点,及Spring jar包官网下载方法
下面给大家说说spring众多jar包的特点吧,无论对于初学spring的新手,还是spring高手,这篇文章都会给大家带来知识上的收获,如果你已经十分熟悉本文内容就当做一次温故知新吧.spring. ...
- *&p理解
要明白这个需明白两个基础: 运算符*优先级高于&, 两个运算符都是从右向左结合运算 所以,*&a 的意思就是先运算 *,得到 指针,再通过 &,获取指针的引用 如果不理解,继续 ...
- 1080P60视频源---verilog
1080P60视频源---verilog `timescale 1ns / 1ps ////////////////////////////////////////////////////////// ...
- 关于栈、队列、优先队列的应用——UVa11995
这本来是上一篇博客里的内容,但不知道什么原因breakdown了……我就简单放上一道题好了 题意:这道题的题目是“猜猜数据结构”,题意就是给你一些输入输出数据,让你根据这些数据判断是什么数据结构.要猜 ...
- Java读取Excel并与SqlServer库中的数据比较
先说说需求.在SQL server数据库中的表里存在一些数据,现在整理的Excel文档中也存在一些数据,现在需要通过根据比较某个字段值(唯一)来判断出,在库中有但excel中没有的数据. 大概的思路就 ...
- Oracle “CONNECT BY” (层级递归查询)
Oracle “CONNECT BY”是层次查询子句,一般用于树状或者层次结果集的查询.其语法是: ? 1 2 [ START WITH condition ] CONNECT BY [ NOCYCL ...
- Collection 和 Collections的区别。(转)
Collection 和 Collections的区别. Collections是个java.util下的类,它包含有各种有关集合操作的静态方法. Collection是个java.util下的接口, ...