Browse Source

add build_url for Test transport

pull/1/head 0.1.4
Aaron Parecki 7 years ago
parent
commit
136aac6f7e
No known key found for this signature in database GPG Key ID: 276C2817346D6056
1 changed files with 15 additions and 2 deletions
  1. +15
    -2
      src/p3k/HTTP/Test.php

+ 15
- 2
src/p3k/HTTP/Test.php View File

@ -33,7 +33,7 @@ class Test implements Transport {
$this->_redirects_remaining = $this->_max_redirects; $this->_redirects_remaining = $this->_max_redirects;
$parts = parse_url($url); $parts = parse_url($url);
unset($parts['fragment']); unset($parts['fragment']);
$url = \build_url($parts);
$url = self::_build_url($parts);
return $this->_read_file($url); return $this->_read_file($url);
} }
@ -57,7 +57,7 @@ class Test implements Transport {
$parts = parse_url($url); $parts = parse_url($url);
if($parts['path']) { if($parts['path']) {
$parts['path'] = '/'.str_replace('/','_',substr($parts['path'],1)); $parts['path'] = '/'.str_replace('/','_',substr($parts['path'],1));
$url = \build_url($parts);
$url = self::_build_url($parts);
} }
$filename = $this->_testDataPath.preg_replace('/https?:\/\//', '', $url); $filename = $this->_testDataPath.preg_replace('/https?:\/\//', '', $url);
@ -135,4 +135,17 @@ class Test implements Transport {
return $retVal; return $retVal;
} }
private static function _build_url($parsed_url) {
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
$pass = ($user || $pass) ? "$pass@" : '';
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
return "$scheme$user$pass$host$port$path$query$fragment";
}
} }

Loading…
Cancel
Save