/*** 获取当前URL 不含QUERY_STRING* @access public* @param string $url URL地址* @return string*/
public function baseUrl($url = null)
{if (!is_null($url) && true !== $url) {$this->baseUrl = $url;return $this;} elseif (!$this->baseUrl) {$str           = $this->url();$this->baseUrl = strpos($str, '?') ? strstr($str, '?', true) : $str;}return true === $url ? $this->domain() . $this->baseUrl : $this->baseUrl;
}// 获取基础 地址/*** 获取当前执行的文件 SCRIPT_NAME* @access public* @param string $file 当前执行的文件* @return string*/
public function baseFile($file = null)
{if (!is_null($file) && true !== $file) {// 设置$this->baseFile = $file;return $this;} elseif (!$this->baseFile) {// 获取$url = '';if (!IS_CLI) {// 非命令行$script_name = basename($_SERVER['SCRIPT_FILENAME']);if (basename($_SERVER['SCRIPT_NAME']) === $script_name) {$url = $_SERVER['SCRIPT_NAME'];} elseif (basename($_SERVER['PHP_SELF']) === $script_name) {$url = $_SERVER['PHP_SELF'];} elseif (isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === $script_name) {$url = $_SERVER['ORIG_SCRIPT_NAME'];} elseif (($pos = strpos($_SERVER['PHP_SELF'], '/' . $script_name)) !== false) {$url = substr($_SERVER['SCRIPT_NAME'], 0, $pos) . '/' . $script_name;} elseif (isset($_SERVER['DOCUMENT_ROOT']) && strpos($_SERVER['SCRIPT_FILENAME'], $_SERVER['DOCUMENT_ROOT']) === 0) {$url = str_replace('\\', '/', str_replace($_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME']));}}$this->baseFile = $url;}return true === $file ? $this->domain() . $this->baseFile : $this->baseFile;
}// 获取基准 文件/*** 获取URL访问根地址* @access public* @param string $url URL地址* @return string*/
public function root($url = null)
{// 获取 URL 访问根地址if (!is_null($url) && true !== $url) {$this->root = $url;return $this;} elseif (!$this->root) {$file = $this->baseFile();// 首先获取 基础文件if ($file && 0 !== strpos($this->url(), $file)) {// 并且这个 什么 url 跟 这个$file = str_replace('\\', '/', dirname($file));// 替换路径}$this->root = rtrim($file, '/');// 去掉最后一个斜杠}return true === $url ? $this->domain() . $this->root : $this->root;// 组合出售
}/*** 获取当前请求URL的pathinfo信息(含URL后缀)* @access public* @return string*/
public function pathinfo()
{if (is_null($this->pathinfo)) {// 如果路径信息为空if (isset($_GET[Config::get('var_pathinfo')])) {// 判断URL里面是否有兼容模式参数$_SERVER['PATH_INFO'] = $_GET[Config::get('var_pathinfo')];unset($_GET[Config::get('var_pathinfo')]);// 获取完成 删除配置文件} elseif (IS_CLI) {// CLI模式下 index.php module/controller/action/params/...$_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '';}// 写法居然是这样的,安逸 index.php module/controller/action/params// 分析PATHINFO信息if (!isset($_SERVER['PATH_INFO'])) {// 分析 PATHINFO 信息foreach (Config::get('pathinfo_fetch') as $type) { // 遍历获取项目if (!empty($_SERVER[$type])) {// 如果不为空$_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type], $_SERVER['SCRIPT_NAME'])) ?substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type];break;}}}$this->pathinfo = empty($_SERVER['PATH_INFO']) ? '/' : ltrim($_SERVER['PATH_INFO'], '/');}return $this->pathinfo;
}// 获取完成/*** 获取当前请求URL的pathinfo信息(不含URL后缀)* @access public* @return string*/
public function path()
{// 获取路径信息if (is_null($this->path)) {$suffix   = Config::get('url_html_suffix');// 首先获取 默认设置的后缀$pathinfo = $this->pathinfo();// 获取 路径信息if (false === $suffix) {// 禁止伪静态// 禁止伪静态访问$this->path = $pathinfo;} elseif ($suffix) {// 去除正常的 URL 后缀// 去除正常的URL后缀$this->path = preg_replace('/\.(' . ltrim($suffix, '.') . ')$/i', '', $pathinfo);} else {// 允许任何后缀访问$this->path = preg_replace('/\.' . $this->ext() . '$/i', '', $pathinfo);}}return $this->path;
}/*** 当前URL的访问后缀* @access public* @return string*/
public function ext()// 当前访问 URL 后缀
{return pathinfo($this->pathinfo(), PATHINFO_EXTENSION);
}/*** 获取当前请求的时间* @access public* @param bool $float 是否使用浮点类型* @return integer|float*/
public function time($float = false)
{return $float ? $_SERVER['REQUEST_TIME_FLOAT'] : $_SERVER['REQUEST_TIME'];
}// 获取当前 请求的 系统时间/*** 当前请求的资源类型* @access public* @return false|string*/
public function type()// 请求资源类型
{$accept = isset($this->server['HTTP_ACCEPT']) ? $this->server['HTTP_ACCEPT'] : $_SERVER['HTTP_ACCEPT'];// 获取 accept 数据if (empty($accept)) {return false;}foreach ($this->mimeType as $key => $val) {// 遍历循环$array = explode(',', $val);//分开foreach ($array as $k => $v) {// 遍历if (stristr($accept, $v)) {return $key;}}}return false;
}/*** 设置资源类型* @access public* @param string|array  $type 资源类型名* @param string        $val 资源类型* @return void*/
public function mimeType($type, $val = '')// 设置资源类型
{if (is_array($type)) {// 如果是数组$this->mimeType = array_merge($this->mimeType, $type);// 合并数据类型} else {$this->mimeType[$type] = $val;}
}/*** 当前的请求类型* @access public* @param bool $method  true 获取原始请求类型* @return string*/
public function method($method = false)// 获取当前的请求类型
{if (true === $method) {// 获取原始 请求类型 ?// 获取原始请求类型return IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);} elseif (!$this->method) {// 如果 没有对应的请求类型if (isset($_POST[Config::get('var_method')])) {// 提交 里面设置 请求类型$this->method = strtoupper($_POST[Config::get('var_method')]);$this->{$this->method}($_POST);} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {//$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);} else {// 默认的 这个情况是有的$this->method = IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);}}return $this->method;
}/*** 是否为GET请求* @access public* @return bool*/
public function isGet()
{return $this->method() == 'GET';
}/*** 是否为POST请求* @access public* @return bool*/
public function isPost()
{return $this->method() == 'POST';
}/*** 是否为PUT请求* @access public* @return bool*/
public function isPut()
{return $this->method() == 'PUT';
}/*** 是否为DELTE请求* @access public* @return bool*/
public function isDelete()
{return $this->method() == 'DELETE';
}/*** 是否为HEAD请求* @access public* @return bool*/
public function isHead()
{return $this->method() == 'HEAD';
}/*** 是否为PATCH请求* @access public* @return bool*/
public function isPatch()
{return $this->method() == 'PATCH';
}/*** 是否为OPTIONS请求* @access public* @return bool*/
public function isOptions()
{return $this->method() == 'OPTIONS';
}/*** 是否为cli* @access public* @return bool*/
public function isCli()
{return PHP_SAPI == 'cli';
}/*** 是否为cgi* @access public* @return bool*/
public function isCgi()
{return strpos(PHP_SAPI, 'cgi') === 0;
}

转载于:https://blog.51cto.com/jingshanls/1889152

[李景山php]每天TP5-20170131|thinkphp5-Request.php-3相关推荐

  1. php tp5.3,[李景山php]每天TP5-20161226|thinkphp5-Console.php-3

    /** * 某个指令是否存在 * @param string $name 指令名称 * @return bool */ public function has($name) { return isse ...

  2. php tp5 parent,[李景山php]每天TP5-20161225|thinkphp5-Console.php-2

    /** * 执行指令 * @param Input  $input * @param Output $output * @return int */ public function doRun(Inp ...

  3. 【TP5】Thinkphp5初体验1

    听说thinkphp5要正式发布了,对于这个蛮不错的实用开发工具,我觉着还是有必要继续跟进学习使用使用的,翻了翻资料找到了这个还未完善的文档,不过,够了,先来个简单开始吧,本文用的是dev-maste ...

  4. tp5缺少start.php,【TP5】Thinkphp5初体验1

    听说thinkphp5要正式发布了,对于这个蛮不错的实用开发工具,我觉着还是有必要继续跟进学习使用使用的,翻了翻资料找到了这个还未完善的文档,不过,够了,先来个简单开始吧,本文用的是dev-maste ...

  5. [李景山php]每天TP5-20170111|thinkphp5-Model.php-4

    /*** 设置需要追加的输出属性* @access public* @param array $append 属性列表* @return $this*/ public function append( ...

  6. [李景山php]每天TP5-20161225|thinkphp5-Console.php-2

    /*** 执行指令* @param Input $input* @param Output $output* @return int*/ public function doRun(Input $in ...

  7. [李景山php]每天TP5-20170125|thinkphp5-Process.php-7

    /*** 获取输入* @return null|string*/public function getInput(){return $this->input;}// 获取输入信息/*** 设置输 ...

  8. [李景山php]每天TP5-20170114|thinkphp5-Model.php-7

    /*** 删除记录* @access public* @param mixed $data 主键列表 支持闭包查询条件* @return integer 成功删除的记录数*/ public stati ...

  9. [李景山php]每天TP5-20170110|thinkphp5-Model.php-3

    /*** 自动写入时间戳* @access public* @param string $name 时间戳字段* @return mixed*/ protected function autoWrit ...

最新文章

  1. Centos 7.0设置/etc/rc.local无效问题解决
  2. WPF使用Linq 一行代码搞定数据绑定
  3. 窗口迅速关闭的解决办法/scanf/if/for/break
  4. Android App 的主角:Activity
  5. tablayout 动态改变标题_TabLayout(动态添加自定义tab)+ViewPager
  6. Android 系统(67)---android apk 的root 权限和USB adb 权限的区别
  7. MySQL 8支持文档存储,并带来性能和安全方面的改进
  8. Pr 视频效果:过渡、透视、通道
  9. 【动画消消乐|CSS】调皮逃跑的小方块 077
  10. 下载SE78里面的图片
  11. 小叮当的2021年年终总结
  12. 线性代数(一)矩阵和方程组
  13. oracle文本类型字段,Oracle字符的5种类型的介绍
  14. 孝当先集团六周年庆典在深圳龙岗圆满举行
  15. Mac访达显示隐藏文件
  16. i78700k配什么显卡好_2K分辨率极致吃鸡 i7-8700K配GTX1070Ti吃鸡配置推荐 (全文)
  17. win7软件图标异常解决
  18. 激活后服务器无限重启,服务器无限重启
  19. 笔记-Java基础语法-二进制
  20. composer更换镜像源

热门文章

  1. 在IOS开发中根据(id)sender获取UIButton的信息
  2. Linux软件安装通用思路
  3. 禁止解析某目录的php,限制访问user_agent,php相关配置
  4. 服务器宽带性能如何?----internet性能测试站点汇集
  5. 正确使用 Android 性能分析工具——TraceView
  6. 手动挡应该这么换挡!这么多年都被驾校坑了!
  7. SQLSERVER执行计划详解
  8. piblog 0.2
  9. 日志切割清理工具 Log-Cutter
  10. 网络2011年:网络安全