HTTP
class HTTP (View source)
A class with HTTP-related helpers. Like Debug, this is more a bundle of methods than a class.
Traits
Provides extensions to this object to integrate it with standard config API methods.
Config options
ignoreDeprecatedCaching | bool | Set to true to disable all deprecated HTTP Cache settings |
|
MimeTypes | array | Mapping of extension to mime types |
Properties
Methods
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
Gets the uninherited value for the given config option
Turns a local system filename into a URL by comparing it to the script filename.
Turn all relative URLs in the content to absolute URLs.
Rewrite all the URLs in the given content, evaluating the given string as PHP code.
Will try to include a GET parameter for an existing URL, preserving existing parameters and fragments. If no URL is given, falls back to $_SERVER['REQUEST_URI']. Uses parse_url() to dissect the URL, and http_build_query() to reconstruct it with the additional parameter.
No description
Search for all tags with a specific attribute, then return the value of that attribute in a flat array.
Get the MIME type based on a file's extension. If the finfo class exists in PHP, and the file exists relative to the project root, then use that extension, otherwise fallback to a list of commonly known MIME types.
Details
static Config_ForClass
config()
Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
mixed
uninherited(string $name)
Gets the uninherited value for the given config option
static string
filename2url(string $filename)
Turns a local system filename into a URL by comparing it to the script filename.
static string
absoluteURLs(string $html)
Turn all relative URLs in the content to absolute URLs.
static string
urlRewriter(string $content, callable $code)
Rewrite all the URLs in the given content, evaluating the given string as PHP code.
Put $URL where you want the URL to appear, however, you can't embed $URL in strings, for example:
- ```'"../../" . $URL'```
- ```'myRewriter($URL)'```
- ```'(substr($URL, 0, 1)=="/") ? "../" . substr($URL, 1) : $URL'```
As of 3.2 $code should be a callable which takes a single parameter and returns the rewritten, for example:
function(string $url) {
return Director::absoluteURL((string) $url, true);
}
static string
setGetVar(string $varname, string $varvalue, string|null $currentURL = null, string $separator = '&')
Will try to include a GET parameter for an existing URL, preserving existing parameters and fragments. If no URL is given, falls back to $_SERVER['REQUEST_URI']. Uses parse_url() to dissect the URL, and http_build_query() to reconstruct it with the additional parameter.
Converts any '&' (ampersand) URL parameter separators to the more XHTML compliant '&'.
CAUTION: If the URL is determined to be relative, it is prepended with Director::absoluteBaseURL(). This method will always return an absolute URL because Director::makeRelative() can lead to inconsistent results.
static string
RAW_setGetVar(string $varname, string $varvalue, null|string $currentURL = null)
No description
static array
findByTagAndAttribute(string $content, array $attributes)
Search for all tags with a specific attribute, then return the value of that attribute in a flat array.
static array
getLinksIn(string $content)
No description
static array
getImagesIn(string $content)
No description
static string
get_mime_type(string $filename)
Get the MIME type based on a file's extension. If the finfo class exists in PHP, and the file exists relative to the project root, then use that extension, otherwise fallback to a list of commonly known MIME types.