本文整理汇总了PHP中GuzzleHttp\Message\RequestInterface::getHost方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getHost方法的具体用法?PHP RequestInterface::getHost怎么用?PHP RequestInterface::getHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getHost方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: checkRequest
/**
* @param RequestInterface $actual
* @param RequestInterface $expected
* @throws FailedRequestExpectationException
*/
public static function checkRequest(RequestInterface $actual, RequestInterface $expected)
{
self::checkIsEqual($actual->getHost(), $expected->getHost(), 'host');
self::checkIsEqual($actual->getPath(), $expected->getPath(), 'url path');
self::checkIsEqual($actual->getMethod(), $expected->getMethod(), 'http method');
self::checkRequestQuery($actual, $expected);
self::checkContentType($actual, $expected);
self::checkRequestBody($actual, $expected);
}
示例2: getRequestAndQuery
/**
* @param RequestInterface $request
* @return array ['query' => ..., 'request' => ...]
*/
protected function getRequestAndQuery(RequestInterface $request)
{
$query = [];
foreach ($request->getQuery() as $param => $val) {
$query[$param] = $val;
}
$requestInfo = ['url' => $request->getUrl(), 'path' => $request->getPath(), 'queryString' => (string) $request->getQuery(), 'method' => $request->getMethod(), 'hostname' => $request->getHost(), 'port' => $request->getPort(), 'resource' => $request->getResource()];
return ['query' => $query, 'request' => $requestInfo];
}
示例3: let
function let(SiteConfigBuilder $siteConfigBuilder, SiteConfig $siteConfig, Factory $authenticatorFactory, ClientInterface $guzzle, Emitter $emitter, BeforeEvent $beforeEvent, CompleteEvent $completeEvent, RequestInterface $request, ResponseInterface $response, Factory $authenticatorFactory)
{
$siteConfig->getHost()->willReturn('example.com');
$siteConfigBuilder->buildForHost('example.com')->willReturn($siteConfig);
$guzzle->getEmitter()->willReturn($emitter);
$request->getHost()->willReturn('example.com');
$beforeEvent->getRequest()->willReturn($request);
$beforeEvent->getClient()->willReturn($guzzle);
$response->getBody()->willReturn('<html></html>');
$completeEvent->getResponse()->willReturn($response);
$completeEvent->getRequest()->willReturn($request);
$completeEvent->getClient()->willReturn($guzzle);
$this->beConstructedWith($siteConfigBuilder, $authenticatorFactory);
}
示例4: signRequest
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
/** @var PostBodyInterface $body */
$body = $request->getBody();
$body->setField('Timestamp', gmdate('c'));
$body->setField('SignatureVersion', '2');
$body->setField('SignatureMethod', 'HmacSHA256');
$body->setField('AWSAccessKeyId', $credentials->getAccessKeyId());
if ($token = $credentials->getSecurityToken()) {
$body->setField('SecurityToken', $token);
}
// build string to sign
$sign = $request->getMethod() . "\n" . $request->getHost() . "\n" . '/' . "\n" . $this->getCanonicalizedParameterString($body);
$request->getConfig()->set('aws.signature', $sign);
$body->setField('Signature', base64_encode(hash_hmac('sha256', $sign, $credentials->getSecretKey(), true)));
}
示例5: add_cookies
private function add_cookies(RequestInterface $request, $value)
{
if ($value === true) {
static $cookie = null;
if (!$cookie) {
$cookie = new Cookie();
}
$request->getEmitter()->attach($cookie);
} elseif (is_array($value)) {
$request->getEmitter()->attach(new Cookie(CookieJar::fromArray($value, $request->getHost())));
} elseif ($value instanceof CookieJarInterface) {
$request->getEmitter()->attach(new Cookie($value));
} elseif ($value !== false) {
throw new \InvalidArgumentException('cookies must be an array, ' . 'true, or a CookieJarInterface object');
}
}
示例6: addCookieHeader
public function addCookieHeader(RequestInterface $request)
{
$values = array();
$scheme = $request->getScheme();
$host = $request->getHost();
$path = $request->getPath();
foreach ($this->cookies as $cookie) {
if ($cookie->matchesPath($path) && $cookie->matchesDomain($host) && !$cookie->isExpired() && (!$cookie->getSecure() || $scheme == 'https')) {
$values[] = $cookie->getName() . '=' . self::getCookieValue($cookie->getValue());
}
}
if ($values) {
$request->setHeader('Cookie', implode('; ', $values));
}
}
示例7: extractCookiesArgument
/**
* @param RequestInterface $request
*/
protected function extractCookiesArgument(RequestInterface $request)
{
$listeners = $request->getEmitter()->listeners('before');
foreach ($listeners as $listener) {
if ($listener[0] instanceof Cookie) {
$values = [];
$scheme = $request->getScheme();
$host = $request->getHost();
$path = $request->getPath();
/** @var SetCookie $cookie */
foreach ($listener[0]->getCookieJar() as $cookie) {
if ($cookie->matchesPath($path) && $cookie->matchesDomain($host) && !$cookie->isExpired() && (!$cookie->getSecure() || $scheme == 'https')) {
$values[] = $cookie->getName() . '=' . CookieJar::getCookieValue($cookie->getValue());
}
}
if ($values) {
$this->addOption('b', escapeshellarg(implode('; ', $values)));
}
}
}
}
示例8: getParameters
/**
* Get context fields to add to the time-line entry.
*
* @param RequestInterface $request
* @param ResponseInterface $response
* @param Exception $error
*
* @return array
*/
protected function getParameters(RequestInterface $request, ResponseInterface $response = null, Exception $error = null)
{
$params = [];
$keys = array_intersect($this->context, $this->availableParameters);
foreach ($keys as $key) {
switch ($key) {
case 'request':
$result = $request;
break;
case 'response':
$result = $response;
break;
case 'method':
$result = $request->getMethod();
break;
case 'url':
$result = $request->getUrl();
break;
case 'resource':
$result = $request->getResource();
break;
case 'request_version':
$result = $request->getProtocolVersion();
break;
case 'response_version':
$result = $response ? $response->getProtocolVersion() : 'NULL';
break;
case 'host':
$result = $request->getHost();
break;
case 'hostname':
$result = gethostname();
break;
case 'status_code':
$result = $response ? $response->getStatusCode() : 'NULL';
break;
case 'phrase':
$result = $response ? $response->getReasonPhrase() : 'NULL';
break;
case 'error':
$result = $error ? $error->getMessage() : 'NULL';
break;
}
$params[$key] = (string) $result ?: '';
}
return $params;
}
示例9: save
/**
* Save data
*
* @author Florian Preusner
* @version 2.1
* @since 2015-05
*
* @param RequestInterface $request
*/
public function save(RequestInterface $request)
{
$this->setHost($request->getHost());
}
示例10: buildSiteConfig
/**
* @return \BD\GuzzleSiteAuthenticator\SiteConfig\SiteConfig|false
*/
private function buildSiteConfig(RequestInterface $request)
{
return $this->configBuilder->buildForHost($request->getHost());
}
示例11: collectRequest
/**
* Collect & sanitize data about a Guzzle request.
*
* @param RequestInterface $request Guzzle request.
* @return array
*/
private function collectRequest(RequestInterface $request)
{
$query = $request->getQuery();
return ['headers' => $request->getHeaders(), 'method' => $request->getMethod(), 'scheme' => $request->getScheme(), 'host' => $request->getHost(), 'path' => $request->getPath(), 'query' => (string) $query, 'queryParams' => $query->toArray(), 'body' => (string) $request->getBody()];
}