minor codestyle stuff

This commit is contained in:
Peter Thaleikis 2015-07-27 19:17:37 +12:00
parent 7b9bbe17dc
commit bd4fc4afcb
3 changed files with 21 additions and 21 deletions

View File

@ -25,9 +25,9 @@ class HTTP {
protected static $etag = null; protected static $etag = null;
/** /**
* @config * @config
*/ */
private static $cache_ajax_requests = true; private static $cache_ajax_requests = true;
/** /**
* Turns a local system filename into a URL by comparing it to the script * Turns a local system filename into a URL by comparing it to the script
@ -39,7 +39,7 @@ class HTTP {
$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;
} else { } else {
break; break;
@ -56,7 +56,7 @@ class HTTP {
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? "https" : "http"; $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? "https" : "http";
// 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; return "$protocol://". $_SERVER['HTTP_HOST'] . $url;
} }
@ -68,7 +68,7 @@ class HTTP {
$html = str_replace('$CurrentPageURL', $_SERVER['REQUEST_URI'], $html); $html = str_replace('$CurrentPageURL', $_SERVER['REQUEST_URI'], $html);
return HTTP::urlRewriter($html, function($url) { return HTTP::urlRewriter($html, function($url) {
//no need to rewrite, if uri has a protocol (determined here by existence of reserved URI character ":") //no need to rewrite, if uri has a protocol (determined here by existence of reserved URI character ":")
if(preg_match('/^\w+:/', $url)){ if(preg_match('/^\w+:/', $url)) {
return $url; return $url;
} }
return Director::absoluteURL($url, true); return Director::absoluteURL($url, true);
@ -83,7 +83,7 @@ class HTTP {
* <ul> * <ul>
* <li><code>'"../../" . $URL'</code></li> * <li><code>'"../../" . $URL'</code></li>
* <li><code>'myRewriter($URL)'</code></li> * <li><code>'myRewriter($URL)'</code></li>
* <li><code>'(substr($URL,0,1)=="/") ? "../" . substr($URL,1) : $URL'</code></li> * <li><code>'(substr($URL, 0, 1)=="/") ? "../" . substr($URL, 1) : $URL'</code></li>
* </ul> * </ul>
* *
* As of 3.2 $code should be a callable which takes a single parameter and returns * As of 3.2 $code should be a callable which takes a single parameter and returns
@ -107,7 +107,7 @@ class HTTP {
} }
// Replace attributes // Replace attributes
$attribs = array("src","background","a" => "href","link" => "href", "base" => "href"); $attribs = array("src", "background", "a" => "href", "link" => "href", "base" => "href");
foreach($attribs as $tag => $attrib) { foreach($attribs as $tag => $attrib) {
if(!is_numeric($tag)) $tagPrefix = "$tag "; if(!is_numeric($tag)) $tagPrefix = "$tag ";
else $tagPrefix = ""; else $tagPrefix = "";

View File

@ -109,8 +109,8 @@ class SS_HTTPRequest implements ArrayAccess {
$this->httpMethod = strtoupper(self::detect_method($httpMethod, $postVars)); $this->httpMethod = strtoupper(self::detect_method($httpMethod, $postVars));
$this->setUrl($url); $this->setUrl($url);
$this->getVars = (array)$getVars; $this->getVars = (array) $getVars;
$this->postVars = (array)$postVars; $this->postVars = (array) $postVars;
$this->body = $body; $this->body = $body;
} }
@ -129,7 +129,7 @@ class SS_HTTPRequest implements ArrayAccess {
// Normalize URL if its relative (strictly speaking), or has leading slashes // Normalize URL if its relative (strictly speaking), or has leading slashes
if(Director::is_relative_url($url) || preg_match('/^\//', $url)) { if(Director::is_relative_url($url) || preg_match('/^\//', $url)) {
$this->url = preg_replace(array('/\/+/','/^\//', '/\/$/'),array('/','',''), $this->url); $this->url = preg_replace(array('/\/+/', '/^\//', '/\/$/'),array('/', '', ''), $this->url);
} }
if(preg_match('/^(.*)\.([A-Za-z][A-Za-z0-9]*)$/', $this->url, $matches)) { if(preg_match('/^(.*)\.([A-Za-z][A-Za-z0-9]*)$/', $this->url, $matches)) {
$this->url = $matches[1]; $this->url = $matches[1];
@ -440,7 +440,7 @@ class SS_HTTPRequest implements ArrayAccess {
// Check for the '//' marker that represents the "shifting point" // Check for the '//' marker that represents the "shifting point"
$doubleSlashPoint = strpos($pattern, '//'); $doubleSlashPoint = strpos($pattern, '//');
if($doubleSlashPoint !== false) { if($doubleSlashPoint !== false) {
$shiftCount = substr_count(substr($pattern,0,$doubleSlashPoint), '/') + 1; $shiftCount = substr_count(substr($pattern, 0, $doubleSlashPoint), '/') + 1;
$pattern = str_replace('//', '/', $pattern); $pattern = str_replace('//', '/', $pattern);
$patternParts = explode('/', $pattern); $patternParts = explode('/', $pattern);
@ -462,10 +462,10 @@ class SS_HTTPRequest implements ArrayAccess {
// A variable ending in ! is required // A variable ending in ! is required
if(substr($part,-1) == '!') { if(substr($part,-1) == '!') {
$varRequired = true; $varRequired = true;
$varName = substr($part,1,-1); $varName = substr($part, 1, -1);
} else { } else {
$varRequired = false; $varRequired = false;
$varName = substr($part,1); $varName = substr($part, 1);
} }
// Fail if a required variable isn't populated // Fail if a required variable isn't populated
@ -681,7 +681,7 @@ class SS_HTTPRequest implements ArrayAccess {
*/ */
public function getAcceptMimetypes($includeQuality = false) { public function getAcceptMimetypes($includeQuality = false) {
$mimetypes = array(); $mimetypes = array();
$mimetypesWithQuality = explode(',',$this->getHeader('Accept')); $mimetypesWithQuality = explode(', ', $this->getHeader('Accept'));
foreach($mimetypesWithQuality as $mimetypeWithQuality) { foreach($mimetypesWithQuality as $mimetypeWithQuality) {
$mimetypes[] = ($includeQuality) ? $mimetypeWithQuality : preg_replace('/;.*/', '', $mimetypeWithQuality); $mimetypes[] = ($includeQuality) ? $mimetypeWithQuality : preg_replace('/;.*/', '', $mimetypeWithQuality);
} }
@ -713,7 +713,7 @@ class SS_HTTPRequest implements ArrayAccess {
*/ */
public static function detect_method($origMethod, $postVars) { public static function detect_method($origMethod, $postVars) {
if(isset($postVars['_method'])) { if(isset($postVars['_method'])) {
if(!in_array(strtoupper($postVars['_method']), array('GET','POST','PUT','DELETE','HEAD'))) { if(!in_array(strtoupper($postVars['_method']), array('GET', 'POST', 'PUT', 'DELETE', 'HEAD'))) {
user_error('Director::direct(): Invalid "_method" parameter', E_USER_ERROR); user_error('Director::direct(): Invalid "_method" parameter', E_USER_ERROR);
} }
return strtoupper($postVars['_method']); return strtoupper($postVars['_method']);

View File

@ -30,7 +30,7 @@
* Session::set('MyVar', $var); * Session::set('MyVar', $var);
* *
* // saves an array * // saves an array
* Session::set('MyArrayOfValues', array('1','2','3')); * Session::set('MyArrayOfValues', array('1', '2', '3'));
* *
* // saves an object (you'll have to unserialize it back) * // saves an object (you'll have to unserialize it back)
* $object = new Object(); * $object = new Object();
@ -411,7 +411,7 @@ class Session {
public function inst_set($name, $val) { public function inst_set($name, $val) {
// Quicker execution path for "."-free names // Quicker execution path for "."-free names
if(strpos($name,'.') === false) { if(strpos($name, '.') === false) {
$this->data[$name] = $val; $this->data[$name] = $val;
$this->changedData[$name] = $val; $this->changedData[$name] = $val;
@ -459,7 +459,7 @@ class Session {
public function inst_get($name) { public function inst_get($name) {
// Quicker execution path for "."-free names // Quicker execution path for "."-free names
if(strpos($name,'.') === false) { if(strpos($name, '.') === false) {
if(isset($this->data[$name])) return $this->data[$name]; if(isset($this->data[$name])) return $this->data[$name];
} else { } else {
@ -569,7 +569,7 @@ class Session {
* @param string $message the message you wish to add to it * @param string $message the message you wish to add to it
* @param string $type the type of message * @param string $type the type of message
*/ */
public static function setFormMessage($formname, $message, $type){ public static function setFormMessage($formname, $message, $type) {
Session::set("FormInfo.$formname.formError.message", $message); Session::set("FormInfo.$formname.formError.message", $message);
Session::set("FormInfo.$formname.formError.type", $type); Session::set("FormInfo.$formname.formError.type", $type);
} }
@ -611,7 +611,7 @@ class Session {
*/ */
public static function set_timeout($timeout) { public static function set_timeout($timeout) {
Deprecation::notice('3.2', 'Use the "Session.timeout" config setting instead'); Deprecation::notice('3.2', 'Use the "Session.timeout" config setting instead');
Config::inst()->update('Session', 'timeout', (int)$timeout); Config::inst()->update('Session', 'timeout', (int) $timeout);
} }
/** /**