/** * get current url without query_string * @access public * @param string $url url address * @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;} Get basic address/** * get the file currently executing SCRIPT_NAME * @access public * @ param string $file Files currently executed * @return string */public function Basefile ($file = null) { if (!is_null ($file) && true !== $file) {// settings $this->basefile = $file; return $this; } elseif (! $this->basefile) {// get $url = '; if (!IS_CLI) {// non-command line $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 ===&nBSP, $file ? $this->domain () . $this->basefile : $this->basefile;} Get benchmark file/** * get URL access root address * @access public * @param string $url url address * @return string */public function root ($url = NULL) {// get URL Access root address if (!is_null ($url) && true !== $url) { $this->root = $url; return $this; } elseif ( ! $this->root) { $file = $this->basefile () ;// first get basic files if ($file && 0 !== strpos ($this->url (), $file)) {// and this what url and this $file = str_replace (' \ \ ', '/', dirname ($file));// Replace Path } $ This->root = rtrim ($file, '/');// remove the last slash } return true === $url ? $this->domain () . $this->root : $this->root;// Portfolio Sale}/** * get pathinfo information for the current request URL (with URL suffix) * @access public * @return string */public function pathinfo () { if ( Is_null ($this->pathinfo) {// If the path information is empty if ( Isset ($_get[config::get (' Var_pathinfo '))) { // determine if there is a compatibility mode parameter in the URL $_ server[' Path_info ']&nbsP;= $_get[config::get (' Var_pathinfo ')]; unset ($_get[config::get (' Var_pathinfo ')]);// get finished Delete profile } elseif (IS_CLI) { index.php module/controller/action/params/... under   // CLI mode $_server[' Path_info '] = isset ($_SERVER[' argv '][1]) ? $_server[' argv '][1] : '; }// It's like this, comfort index.php module/controller/action/params // Analysis PathInfo Information if (!isset ($_server[' Path_info ' ]) {// Analysis PATHINFO Information foreach (Config::get (' PAthinfo_fetch ') as $type) { // traverse get Items if (!empty ($_server[$type]) {// if not empty $_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;} Get finished/** * get the PathInfo information for the current request URL (without the URL suffix) * @access public * @return string */public function path () {// Get path information if (Is_null ($ This->path)) { $suffix = config:: Get (' Url_html_suffix ');// first get default suffix $pathinfo = $this->pathinfo ();// get path information if (false === $suffix) {// suppress pseudo-static // disable pseudo-static access  , $this->path = $pathinfo; } elseif ( $suffix) {// remove normal URL suffix // remove the normal URL suffix $this- >path = preg_replace ('/\. (' . ltrim ($suffix, '. ') . ') $/i ', ', $pathinfo); } else { // allow any suffix access $this->path = preg_replace ('/\. ' . $this->ext () . ' $/i ', ', $pathinfo); } } return $this->path;} /** * the access suffix of the current URL * @access public * @return String */public function ext ()// current access URL suffix { return pathinfo ($this->pathinfo (), pathinfo_extension);} /** * get current request time * @access public * @param bool $float Whether to use floating-point types * @return integer|float */public function time ($float = false ) { return $float ? $_server[' request_time_float '] : $_SERVER[' Request_time '];} Get current requested system time/** * current requested resource type * @access public * @return false|string */public function type ()// request resource type { $accept = isset ($this->server[' http_accept ') ? $this->server[' http_accept '] : $_server [' Http_accept ']; // get accept data if (Empty ($ Accept))  {      &NBsp; return false; } foreach ($this->mimetype as $key => $val) {// traversal loop $ Array = explode (', ', $val);//Separate foreach ($ array as $k => $v) {// traversal if (Stristr ($accept, $v)) { return $key; } } } return false;} /** * Set resource types * @access public * @param string|array $type Resource type name * @param string $val resource type * @return void */public function mimetype ($type, $val = ")// Set Resource type { if (Is_array ($type)) {// If it is an array $this->mimetype = array_merge ($this->mimetype, $type) ;// merge data type } else { $ this->mimetype[$type] = $val; }}/** * The current request type * @ access public * @param bool $method true Get the original request type * @return string */public function method ($method = false)// Gets the current request type { if (true === $method) {// get raw request type ? // get the original request type return IS_CLI ? ' GET ' : (iSset ($this->server[' Request_method ') ? $this->server[' request_method '] : $_server[' Request_method ']); } elseif (! $this->method) {// if No corresponding request type if (Isset ($_post[config::get (' Var_method '))) {// submit Inside Setup request type $ 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 {// default This is the case,    &N.bsp; $this->method = is_cli ? ' GET ' : (isset ($this->server[' Request_method ') ? $this->server[' Request_method '] : $_server[' Request_method '); } } return $this->method;} /** * is GET request * @access public * @return bool */public Function isget () { return $this->method () == ' GET ';} /** * is the POST request * @access public * @return bool */public Function ispost () { return $this->method () == ' POST ';} /** * is put request * @access public * @return bool */public Function isput () { return $this->method () == ' PUT ';} /** *&nBSP: Delte request * @access public * @return bool */public function Isdelete () { return $this->method () == ' DELETE ';} /** * is head request * @access public * @return bool */public Function ishead () { return $this->method () == ' HEAD ';} /** * is patch request * @access public * @return bool */public Function ispatch () { return $this->method () == ' PATCH ';} /** * is the options request * @access public * @return bool */public Function isoptions () { return $this->method () == ' OPTIONS ';} /** * is cli * @access public * @return bool */public Function iscli () { return php_sapi == ' CLI ';} /** * is cgi * @access public * @return bool */public function iscgi () { return strpos (php_sapi, ' CGI ') === 0;}
This article is from the "Focus on PHP Group number: 414194301" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1889152
[Li Jingshan php] every day tp5-20170131|thinkphp5-request.php-3