本文整理汇总了PHP中GuzzleHttp\Psr7\Uri::withFragment方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::withFragment方法的具体用法?PHP Uri::withFragment怎么用?PHP Uri::withFragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Psr7\Uri
的用法示例。
在下文中一共展示了Uri::withFragment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createResponse
/**
* Taken from Mink\BrowserKitDriver
*
* @param Response $response
*
* @return \Symfony\Component\BrowserKit\Response
*/
protected function createResponse(Psr7Response $response)
{
$body = (string) $response->getBody();
$headers = $response->getHeaders();
$contentType = null;
if (isset($headers['Content-Type'])) {
$contentType = reset($headers['Content-Type']);
}
if (!$contentType) {
$contentType = 'text/html';
}
if (strpos($contentType, 'charset=') === false) {
if (preg_match('/\\<meta[^\\>]+charset *= *["\']?([a-zA-Z\\-0-9]+)/i', $body, $matches)) {
$contentType .= ';charset=' . $matches[1];
}
$headers['Content-Type'] = [$contentType];
}
$status = $response->getStatusCode();
if ($status < 300 || $status >= 400) {
$matches = [];
$matchesMeta = preg_match('/\\<meta[^\\>]+http-equiv="refresh" content="(\\d*)\\s*;?\\s*url=(.*?)"/i', $body, $matches);
if (!$matchesMeta && isset($headers['Refresh'])) {
// match by header
preg_match('~(\\d*);?url=(.*)~', (string) reset($headers['Refresh']), $matches);
}
if (!empty($matches) && (empty($matches[1]) || $matches[1] < $this->refreshMaxInterval)) {
$uri = new Psr7Uri($this->getAbsoluteUri($matches[2]));
$currentUri = new Psr7Uri($this->getHistory()->current()->getUri());
if ($uri->withFragment('') != $currentUri->withFragment('')) {
$status = 302;
$headers['Location'] = $matchesMeta ? htmlspecialchars_decode($uri) : (string) $uri;
}
}
}
return new BrowserKitResponse($body, $status, $headers);
}