Skip to content

Commit

Permalink
avoid using magic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Nov 9, 2014
1 parent e0963e7 commit 0914fe9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/Http/Request.php
Expand Up @@ -67,7 +67,7 @@ public function __construct(UrlScript $url, $query = NULL, $post = NULL, $files
{
$this->url = $url;
if ($query === NULL) {
parse_str($url->query, $this->query);
parse_str($url->getQuery(), $this->query);
} else {
$this->query = (array) $query;
}
Expand Down Expand Up @@ -257,7 +257,7 @@ public function getReferer()
*/
public function isSecured()
{
return $this->url->scheme === 'https';
return $this->url->getScheme() === 'https';
}


Expand Down
24 changes: 12 additions & 12 deletions src/Http/RequestFactory.php
Expand Up @@ -64,19 +64,19 @@ public function createHttpRequest()
{
// DETECTS URI, base path and script path of the request.
$url = new UrlScript;
$url->scheme = !empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https' : 'http';
$url->user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
$url->password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';
$url->setScheme(!empty($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'], 'off') ? 'https' : 'http');
$url->setUser(isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '');
$url->setPassword(isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '');

// host & port
if ((isset($_SERVER[$tmp = 'HTTP_HOST']) || isset($_SERVER[$tmp = 'SERVER_NAME']))
&& preg_match('#^([a-z0-9_.-]+|\[[a-f0-9:]+\])(:\d+)?\z#i', $_SERVER[$tmp], $pair)
) {
$url->host = strtolower($pair[1]);
$url->setHost(strtolower($pair[1]));
if (isset($pair[2])) {
$url->port = (int) substr($pair[2], 1);
$url->setPort(substr($pair[2], 1));
} elseif (isset($_SERVER['SERVER_PORT'])) {
$url->port = (int) $_SERVER['SERVER_PORT'];
$url->setPort($_SERVER['SERVER_PORT']);
}
}

Expand All @@ -95,12 +95,12 @@ public function createHttpRequest()

$requestUrl = Strings::replace($requestUrl, $this->urlFilters['url']);
$tmp = explode('?', $requestUrl, 2);
$url->path = Strings::replace($tmp[0], $this->urlFilters['path']);
$url->query = isset($tmp[1]) ? $tmp[1] : '';
$url->setPath(Strings::replace($tmp[0], $this->urlFilters['path']));
$url->setQuery(isset($tmp[1]) ? $tmp[1] : '');

// normalized url
$url->canonicalize();
$url->path = Strings::fixEncoding($url->path);
$url->setPath(Strings::fixEncoding($url->getPath()));

// detect script path
if (isset($_SERVER['SCRIPT_NAME'])) {
Expand All @@ -113,21 +113,21 @@ public function createHttpRequest()
$script = '/';
}

$path = strtolower($url->path) . '/';
$path = strtolower($url->getPath()) . '/';
$script = strtolower($script) . '/';
$max = min(strlen($path), strlen($script));
for ($i = 0; $i < $max; $i++) {
if ($path[$i] !== $script[$i]) {
break;
} elseif ($path[$i] === '/') {
$url->scriptPath = substr($url->path, 0, $i + 1);
$url->setScriptPath(substr($url->getPath(), 0, $i + 1));
}
}

// GET, POST, COOKIE
$useFilter = (!in_array(ini_get('filter.default'), array('', 'unsafe_raw')) || ini_get('filter.default_flags'));

parse_str($url->query, $query);
parse_str($url->getQuery(), $query);
if (!$query) {
$query = $useFilter ? filter_input_array(INPUT_GET, FILTER_UNSAFE_RAW) : (empty($_GET) ? array() : $_GET);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Response.php
Expand Up @@ -50,7 +50,7 @@ public function __construct()
if (is_int(http_response_code())) {
$this->code = http_response_code();
}
header_register_callback($this->removeDuplicateCookies);
header_register_callback(array($this, 'removeDuplicateCookies'));
}
}

Expand Down

0 comments on commit 0914fe9

Please sign in to comment.