Browse Source

OpenId client "buildUrl()" method refactored.

tags/2.0.0-beta
Paul Klimov 11 years ago
parent
commit
d21c59bc3c
  1. 49
      extensions/yii/authclient/OpenId.php

49
extensions/yii/authclient/OpenId.php

@ -351,22 +351,33 @@ class OpenId extends BaseClient implements ClientInterface
return $this->sendStreamRequest($url, $method, $params); return $this->sendStreamRequest($url, $method, $params);
} }
protected function buildUrl($url, $parts) /**
* Combines given URLs into single one.
* @param string $baseUrl base URL.
* @param string|array $additionalUrl additional URL string or information array.
* @return string composed URL.
*/
protected function buildUrl($baseUrl, $additionalUrl)
{ {
if (isset($url['query'], $parts['query'])) { $baseUrl = parse_url($baseUrl);
$parts['query'] = $url['query'] . '&' . $parts['query']; if (!is_array($additionalUrl)) {
} $additionalUrl = parse_url($additionalUrl);
}
$url = $parts + $url;
$url = $url['scheme'] . '://' if (isset($baseUrl['query'], $additionalUrl['query'])) {
. (empty($url['username']) ? '' $additionalUrl['query'] = $baseUrl['query'] . '&' . $additionalUrl['query'];
:(empty($url['password']) ? "{$url['username']}@" }
:"{$url['username']}:{$url['password']}@"))
. $url['host'] $urlInfo = array_merge($baseUrl, $additionalUrl);
. (empty($url['port']) ? '' : ":{$url['port']}") $url = $urlInfo['scheme'] . '://'
. (empty($url['path']) ? '' : $url['path']) . (empty($urlInfo['username']) ? ''
. (empty($url['query']) ? '' : "?{$url['query']}") :(empty($urlInfo['password']) ? "{$urlInfo['username']}@"
. (empty($url['fragment']) ? '' : "#{$url['fragment']}"); :"{$urlInfo['username']}:{$urlInfo['password']}@"))
. $urlInfo['host']
. (empty($urlInfo['port']) ? '' : ":{$urlInfo['port']}")
. (empty($urlInfo['path']) ? '' : $urlInfo['path'])
. (empty($urlInfo['query']) ? '' : "?{$urlInfo['query']}")
. (empty($urlInfo['fragment']) ? '' : "#{$urlInfo['fragment']}");
return $url; return $url;
} }
@ -428,7 +439,7 @@ class OpenId extends BaseClient implements ClientInterface
$next = false; $next = false;
if (isset($headers['x-xrds-location'])) { if (isset($headers['x-xrds-location'])) {
$url = $this->buildUrl(parse_url($url), parse_url(trim($headers['x-xrds-location']))); $url = $this->buildUrl($url, trim($headers['x-xrds-location']));
$next = true; $next = true;
} }
@ -509,7 +520,7 @@ class OpenId extends BaseClient implements ClientInterface
$content = $this->sendRequest($url, 'GET'); $content = $this->sendRequest($url, 'GET');
$location = $this->extractHtmlTagValue($content, 'meta', 'http-equiv', 'X-XRDS-Location', 'content'); $location = $this->extractHtmlTagValue($content, 'meta', 'http-equiv', 'X-XRDS-Location', 'content');
if ($location) { if ($location) {
$url = $this->buildUrl(parse_url($url), parse_url($location)); $url = $this->buildUrl($url, $location);
continue; continue;
} }
} }
@ -654,7 +665,7 @@ class OpenId extends BaseClient implements ClientInterface
] ]
); );
return $this->buildUrl(parse_url($serverInfo['url']), ['query' => http_build_query($params, '', '&')]); return $this->buildUrl($serverInfo['url'], ['query' => http_build_query($params, '', '&')]);
} }
/** /**
@ -689,7 +700,7 @@ class OpenId extends BaseClient implements ClientInterface
$params['openid.identity'] = $serverInfo['identity']; $params['openid.identity'] = $serverInfo['identity'];
$params['openid.claimed_id'] = $this->getClaimedId(); $params['openid.claimed_id'] = $this->getClaimedId();
} }
return $this->buildUrl(parse_url($serverInfo['url']), ['query' => http_build_query($params, '', '&')]); return $this->buildUrl($serverInfo['url'], ['query' => http_build_query($params, '', '&')]);
} }
/** /**

Loading…
Cancel
Save