mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
PHPDoc + coding conventions
This commit is contained in:
parent
d47b202697
commit
07b9bd8527
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class with HTTP-related helpers.
|
* A class with HTTP-related helpers.
|
||||||
* Like Debug, this is more a bundle of methods than a class ;-)
|
* Like Debug, this is more a bundle of methods than a class ;-)
|
||||||
@ -8,17 +9,30 @@
|
|||||||
*/
|
*/
|
||||||
class HTTP {
|
class HTTP {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int $cache_age
|
||||||
|
*/
|
||||||
protected static $cache_age = 0;
|
protected static $cache_age = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var timestamp $modification_date
|
||||||
|
*/
|
||||||
protected static $modification_date = null;
|
protected static $modification_date = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string $etag
|
||||||
|
*/
|
||||||
protected static $etag = null;
|
protected static $etag = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns a local system filename into a URL by comparing it to the script filename
|
* Turns a local system filename into a URL by comparing it to the script
|
||||||
|
* filename.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
*/
|
*/
|
||||||
public static function filename2url($filename) {
|
public static function filename2url($filename) {
|
||||||
$slashPos = -1;
|
$slashPos = -1;
|
||||||
|
|
||||||
while(($slashPos = strpos($filename, "/", $slashPos+1)) !== false) {
|
while(($slashPos = strpos($filename, "/", $slashPos+1)) !== false) {
|
||||||
if(substr($filename, 0, $slashPos) == substr($_SERVER['SCRIPT_FILENAME'],0,$slashPos)) {
|
if(substr($filename, 0, $slashPos) == substr($_SERVER['SCRIPT_FILENAME'],0,$slashPos)) {
|
||||||
$commonLength = $slashPos;
|
$commonLength = $slashPos;
|
||||||
@ -27,13 +41,19 @@ class HTTP {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$urlBase = substr($_SERVER['PHP_SELF'], 0, -(strlen($_SERVER['SCRIPT_FILENAME']) - $commonLength));
|
$urlBase = substr(
|
||||||
|
$_SERVER['PHP_SELF'],
|
||||||
|
0,
|
||||||
|
-(strlen($_SERVER['SCRIPT_FILENAME']) - $commonLength)
|
||||||
|
);
|
||||||
|
|
||||||
$url = $urlBase . substr($filename, $commonLength);
|
$url = $urlBase . substr($filename, $commonLength);
|
||||||
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? "https" : "http";
|
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? "https" : "http";
|
||||||
return "$protocol://". $_SERVER['HTTP_HOST'] . $url;
|
|
||||||
|
|
||||||
// Count the number of extra folders the script is in.
|
// Count the number of extra folders the script is in.
|
||||||
// $prefix = str_repeat("../", substr_count(substr($_SERVER[SCRIPT_FILENAME],$commonBaseLength)));
|
// $prefix = str_repeat("../", substr_count(substr($_SERVER[SCRIPT_FILENAME],$commonBaseLength)));
|
||||||
|
|
||||||
|
return "$protocol://". $_SERVER['HTTP_HOST'] . $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user