📄 http.php
字号:
return $this; } // If using mod_rewrite or ISAPI_Rewrite strip the script filename // out of baseUrl. $pos !== 0 makes sure it is not matching a value // from PATH_INFO or QUERY_STRING if ((strlen($requestUri) >= strlen($baseUrl)) && ((false !== ($pos = strpos($requestUri, $baseUrl))) && ($pos !== 0))) { $baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl)); } } $this->_baseUrl = rtrim($baseUrl, '/'); return $this; } /** * Everything in REQUEST_URI before PATH_INFO * <form action="<?=$baseUrl?>/news/submit" method="POST"/> * * @return string */ public function getBaseUrl() { if (null === $this->_baseUrl) { $this->setBaseUrl(); } return $this->_baseUrl; } /** * Set the base path for the URL * * @param string|null $basePath * @return Zend_Controller_Request_Http */ public function setBasePath($basePath = null) { if ($basePath === null) { $filename = basename($_SERVER['SCRIPT_FILENAME']); $baseUrl = $this->getBaseUrl(); if (empty($baseUrl)) { $this->_basePath = ''; return $this; } if (basename($baseUrl) === $filename) { $basePath = dirname($baseUrl); } else { $basePath = $baseUrl; } } $this->_basePath = rtrim($basePath, '/'); return $this; } /** * Everything in REQUEST_URI before PATH_INFO not including the filename * <img src="<?=$basePath?>/images/zend.png"/> * * @return string */ public function getBasePath() { if (null === $this->_basePath) { $this->setBasePath(); } return $this->_basePath; } /** * Set the PATH_INFO string * * @param string|null $pathInfo * @return Zend_Controller_Request_Http */ public function setPathInfo($pathInfo = null) { if ($pathInfo === null) { $baseUrl = $this->getBaseUrl(); if (null === ($requestUri = $this->getRequestUri())) { return $this; } // Remove the query string from REQUEST_URI if ($pos = strpos($requestUri, '?')) { $requestUri = substr($requestUri, 0, $pos); } if ((null !== $baseUrl) && (false === ($pathInfo = substr($requestUri, strlen($baseUrl))))) { // If substr() returns false then PATH_INFO is set to an empty string $pathInfo = ''; } elseif (null === $baseUrl) { $pathInfo = $requestUri; } } $this->_pathInfo = (string) $pathInfo; return $this; } /** * Returns everything between the BaseUrl and QueryString. * This value is calculated instead of reading PATH_INFO * directly from $_SERVER due to cross-platform differences. * * @return string */ public function getPathInfo() { if (empty($this->_pathInfo)) { $this->setPathInfo(); } return $this->_pathInfo; } /** * Set allowed parameter sources * * Can be empty array, or contain one or more of '_GET' or '_POST'. * * @param array $paramSoures * @return Zend_Controller_Request_Http */ public function setParamSources(array $paramSources = array()) { $this->_paramSources = $paramSources; return $this; } /** * Get list of allowed parameter sources * * @return array */ public function getParamSources() { return $this->_paramSources; } /** * Set a userland parameter * * Uses $key to set a userland parameter. If $key is an alias, the actual * key will be retrieved and used to set the parameter. * * @param mixed $key * @param mixed $value * @return Zend_Controller_Request_Http */ public function setParam($key, $value) { $key = (null !== ($alias = $this->getAlias($key))) ? $alias : $key; parent::setParam($key, $value); return $this; } /** * Retrieve a parameter * * Retrieves a parameter from the instance. Priority is in the order of * userland parameters (see {@link setParam()}), $_GET, $_POST. If a * parameter matching the $key is not found, null is returned. * * If the $key is an alias, the actual key aliased will be used. * * @param mixed $key * @param mixed $default Default value to use if key not found * @return mixed */ public function getParam($key, $default = null) { $keyName = (null !== ($alias = $this->getAlias($key))) ? $alias : $key; $paramSources = $this->getParamSources(); if (isset($this->_params[$keyName])) { return $this->_params[$keyName]; } elseif (in_array('_GET', $paramSources) && (isset($_GET[$keyName]))) { return $_GET[$keyName]; } elseif (in_array('_POST', $paramSources) && (isset($_POST[$keyName]))) { return $_POST[$keyName]; } return $default; } /** * Retrieve an array of parameters * * Retrieves a merged array of parameters, with precedence of userland * params (see {@link setParam()}), $_GET, $POST (i.e., values in the * userland params will take precedence over all others). * * @return array */ public function getParams() { $return = $this->_params; if (isset($_GET) && is_array($_GET)) { $return += $_GET; } if (isset($_POST) && is_array($_POST)) { $return += $_POST; } return $return; } /** * Set parameters * * Set one or more parameters. Parameters are set as userland parameters, * using the keys specified in the array. * * @param array $params * @return Zend_Controller_Request_Http */ public function setParams(array $params) { foreach ($params as $key => $value) { $this->setParam($key, $value); } return $this; } /** * Set a key alias * * Set an alias used for key lookups. $name specifies the alias, $target * specifies the actual key to use. * * @param string $name * @param string $target * @return Zend_Controller_Request_Http */ public function setAlias($name, $target) { $this->_aliases[$name] = $target; return $this; } /** * Retrieve an alias * * Retrieve the actual key represented by the alias $name. * * @param string $name * @return string|null Returns null when no alias exists */ public function getAlias($name) { if (isset($this->_aliases[$name])) { return $this->_aliases[$name]; } return null; } /** * Retrieve the list of all aliases * * @return array */ public function getAliases() { return $this->_aliases; } /** * Return the method by which the request was made * * @return string */ public function getMethod() { return $this->getServer('REQUEST_METHOD'); } /** * Was the request made by POST? * * @return boolean */ public function isPost() { if ('POST' == $this->getMethod()) { return true; } return false; } /** * Was the request made by GET? * * @return boolean */ public function isGet() { if ('GET' == $this->getMethod()) { return true; } return false; } /** * Was the request made by PUT? * * @return boolean */ public function isPut() { if ('PUT' == $this->getMethod()) { return true; } return false; } /** * Was the request made by DELETE? * * @return boolean */ public function isDelete() { if ('DELETE' == $this->getMethod()) { return true; } return false; } /** * Was the request made by HEAD? * * @return boolean */ public function isHead() { if ('HEAD' == $this->getMethod()) { return true; } return false; } /** * Was the request made by OPTIONS? * * @return boolean */ public function isOptions() { if ('OPTIONS' == $this->getMethod()) { return true; } return false; } /** * Return the raw body of the request, if present * * @return string|false Raw body, or false if not present */ public function getRawBody() { $body = file_get_contents('php://input'); if (strlen(trim($body)) > 0) { return $body; } return false; } /** * Return the value of the given HTTP header. Pass the header name as the * plain, HTTP-specified header name. Ex.: Ask for 'Accept' to get the * Accept header, 'Accept-Encoding' to get the Accept-Encoding header. * * @param string $header HTTP header name * @return string|false HTTP header value, or false if not found * @throws Zend_Controller_Request_Exception */ public function getHeader($header) { if (empty($header)) { require_once 'Zend/Controller/Request/Exception.php'; throw new Zend_Controller_Request_Exception('An HTTP header name is required'); } // Try to get it from the $_SERVER array first $temp = 'HTTP_' . strtoupper(str_replace('-', '_', $header)); if (!empty($_SERVER[$temp])) { return $_SERVER[$temp]; } // This seems to be the only way to get the Authorization header on // Apache if (function_exists('apache_request_headers')) { $headers = apache_request_headers(); if (!empty($headers[$header])) { return $headers[$header]; } } return false; } /** * Is the request a Javascript XMLHttpRequest? * * Should work with Prototype/Script.aculo.us, possibly others. * * @return boolean */ public function isXmlHttpRequest() { return ($this->getHeader('X_REQUESTED_WITH') == 'XMLHttpRequest'); } /** * Is this a Flash request? * * @return bool */ public function isFlashRequest() { return ($this->getHeader('USER_AGENT') == 'Shockwave Flash'); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -