本文整理汇总了PHP中GuzzleHttp\Url类的典型用法代码示例。如果您正苦于以下问题:PHP Url类的具体用法?PHP Url怎么用?PHP Url使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Url类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseVirtualHosted
private function parseVirtualHosted(Url $url, array $matches)
{
$result = self::$defaultResult;
$result['path_style'] = false;
// Remove trailing "." from the prefix to get the bucket
$result['bucket'] = substr($matches[1], 0, -1);
$path = $url->getPath();
// Check if a key was present, and if so, removing the leading "/"
$result['key'] = !$path || $path == '/' ? null : substr($path, 1);
return $result;
}
示例2: getNextRequest
/**
* {@inheritdoc}
*/
public function getNextRequest(ClientInterface $client, JobConfig $jobConfig, $response, $data)
{
$nextUrl = Utils::getDataFromPath($this->urlParam, $response, '.');
if (empty($nextUrl)) {
return false;
}
// start_time validation
// https://developer.zendesk.com/rest_api/docs/core/incremental_export#incremental-ticket-export
$now = new \DateTime();
$startDateTime = \DateTime::createFromFormat('U', Url::fromString($nextUrl)->getQuery()->get('start_time'));
if ($startDateTime && $startDateTime > $now->modify(sprintf("-%d minutes", self::NEXT_PAGE_FILTER_MINUTES))) {
return false;
}
$config = $jobConfig->getConfig();
if (!$this->includeParams) {
$config['params'] = [];
}
if (!$this->paramIsQuery) {
$config['endpoint'] = $nextUrl;
} else {
// Create an array from the query string
$responseQuery = Query::fromString(ltrim($nextUrl, '?'))->toArray();
$config['params'] = array_replace($config['params'], $responseQuery);
}
return $client->createRequest($config);
}
示例3: __construct
/**
* @param AccessTokenInterface $token
* @param array $options
*/
public function __construct(AccessTokenInterface $token, array $options = [])
{
$options = array_merge($options, ['emitter' => EventsManager::getEmitter()]);
parent::__construct($options);
if ($token instanceof OAuth2AccessTokenInterface) {
$this->getEmitter()->on('before', function (BeforeEvent $event) use($token) {
/** @var \Eva\EvaOAuth\OAuth2\Token\AccessToken $token */
$event->getRequest()->setHeader('Authorization', $token->getTokenType() . ' ' . $token->getTokenValue());
});
} else {
$signatureMethod = isset($options['signature_method']) ? $options['signature_method'] : SignatureInterface::METHOD_HMAC_SHA1;
$signatureClasses = [SignatureInterface::METHOD_PLAINTEXT => 'Eva\\EvaOAuth\\OAuth1\\Signature\\PlainText', SignatureInterface::METHOD_HMAC_SHA1 => 'Eva\\EvaOAuth\\OAuth1\\Signature\\Hmac', SignatureInterface::METHOD_RSA_SHA1 => 'Eva\\EvaOAuth\\OAuth1\\Signature\\Rsa'];
if (false === isset($signatureClasses[$signatureMethod])) {
throw new InvalidArgumentException(sprintf('Signature method %s not able to process', $signatureMethod));
}
$signatureClass = $signatureClasses[$signatureMethod];
$this->getEmitter()->on('before', function (BeforeEvent $event) use($token, $signatureClass) {
/** @var Request $request */
$request = $event->getRequest();
/** @var \Eva\EvaOAuth\OAuth1\Token\AccessToken $token */
$httpMethod = strtoupper($request->getMethod());
$url = Url::fromString($request->getUrl());
$parameters = ['oauth_consumer_key' => $token->getConsumerKey(), 'oauth_signature_method' => SignatureInterface::METHOD_HMAC_SHA1, 'oauth_timestamp' => (string) time(), 'oauth_nonce' => strtolower(Text::generateRandomString(32)), 'oauth_token' => $token->getTokenValue(), 'oauth_version' => '1.0'];
$signature = (string) new $signatureClass($token->getConsumerSecret(), Text::buildBaseString($httpMethod, $url, $parameters), $token->getTokenSecret());
$parameters['oauth_signature'] = $signature;
$event->getRequest()->setHeader('Authorization', Text::buildHeaderString($parameters));
});
}
}
示例4: buildEndpoint
/**
* Builds the URI template for a REST based request.
*
* @param array $operation
* @param array $args
*
* @return array
*/
private function buildEndpoint($operation, array $args)
{
$endpoint = Url::fromString($this->endpoint);
$varspecs = [];
if (isset($operation['http']['requestUri'])) {
$endpoint->combine($operation['http']['requestUri']);
// Create an associative array of varspecs used in expansions
if (isset($operation['parameters'])) {
foreach ($operation['parameters'] as $name => $member) {
if ($member['location'] == 'uri') {
$varspecs[isset($member['locationName']) ? $member['locationName'] : $name] = isset($args[$name]) ? $args[$name] : null;
} elseif ($member['location'] == 'query' && !empty($args[$name])) {
$endpoint->getQuery()->set($name, $args[$name]);
}
}
}
}
$uri = (string) $endpoint;
return preg_replace_callback('/%7B([^\\}]+)%7D/', function (array $matches) use($varspecs) {
$isGreedy = substr($matches[1], -1, 1) == '+';
$k = $isGreedy ? substr($matches[1], 0, -1) : $matches[1];
if (!isset($varspecs[$k])) {
return '';
} elseif ($isGreedy) {
return str_replace('%2F', '/', rawurlencode($varspecs[$k]));
} else {
return rawurlencode($varspecs[$k]);
}
}, $uri);
}
示例5: getNextRequest
/**
* {@inheritdoc}
*/
public function getNextRequest(ClientInterface $client, JobConfig $jobConfig, $response, $data)
{
$nextUrl = Utils::getDataFromPath($this->urlParam, $response, '.');
if (empty($nextUrl)) {
return false;
}
// since validation - cannot be greater than now
$now = new \DateTime();
$sinceDateTime = \DateTime::createFromFormat('U', Url::fromString($nextUrl)->getQuery()->get('since'));
if ($sinceDateTime && $sinceDateTime > $now) {
return false;
}
$config = $jobConfig->getConfig();
if (!$this->includeParams) {
$config['params'] = [];
}
if (!$this->paramIsQuery) {
$config['endpoint'] = $nextUrl;
} else {
// Create an array from the query string
$responseQuery = Query::fromString(ltrim($nextUrl, '?'))->toArray();
$config['params'] = array_replace($config['params'], $responseQuery);
}
return $client->createRequest($config);
}
示例6: validateUrl
/**
* Ensures that the url of the certificate is one belonging to AWS, and not
* just something from the amazonaws domain, which includes S3 buckets.
*
* @param Url $url
*
* @throws MessageValidatorException if the cert url is invalid
*/
private function validateUrl(Url $url)
{
// The cert URL must be https, a .pem, and match the following pattern.
$hostPattern = '/^sns\\.[a-zA-Z0-9\\-]{3,}\\.amazonaws\\.com(\\.cn)?$/';
if ($url->getScheme() !== 'https' || substr($url, -4) !== '.pem' || !preg_match($hostPattern, $url->getHost())) {
throw new MessageValidatorException('The certificate is located ' . 'on an invalid domain.');
}
}
示例7: onPrepared
public function onPrepared(PreparedEvent $event)
{
$command = $event->getCommand();
if ($command->hasParam('QueueUrl')) {
$request = $event->getRequest();
$url = Url::fromString($request->getUrl());
$request->setUrl($url->combine($command['QueueUrl']));
}
}
示例8: testStripsFragmentFromHost
public function testStripsFragmentFromHost()
{
Server::flush();
Server::enqueue("HTTP/1.1 200 OK\r\n\r\nContent-Length: 0\r\n\r\n");
// This will fail if the removal of the #fragment is not performed
$url = Url::fromString(Server::$url)->setPath(null)->setFragment('foo');
$client = new Client();
$client->get($url);
}
示例9: getArguments
public static function getArguments()
{
$args = parent::getArguments();
$args['endpoint']['required'] = true;
$args['region']['default'] = function (array $args) {
// Determine the region from the provided endpoint.
// (e.g. http://search-blah.{region}.cloudsearch.amazonaws.com)
return explode('.', Url::fromString($args['endpoint']))[1];
};
return $args;
}
示例10: serialize
/**
* @param array $userValues The user-defined values that will populate the JSON
* @param []Parameter $params The parameter schemas that define how each value is populated.
* For example, specifying any deep nesting or aliasing.
* @param string $inputString The initial URL string being decorated.
*
* @return Url
*/
public function serialize($userValues, array $params, $inputString)
{
$url = Url::fromString($inputString);
$query = new Query();
foreach ($userValues as $paramName => $value) {
$schema = $params[$paramName];
if (!$schema->hasLocation('query')) {
continue;
}
$query->set($schema->getName(), $value);
}
$url->setQuery($query);
return $url;
}
示例11: createPresignedUrl
private function createPresignedUrl(AwsClientInterface $client, CommandInterface $cmd)
{
$newCmd = $client->getCommand('CopySnapshot', $cmd->toArray());
$newCmd->getEmitter()->detach($this);
// Serialize a request for the CopySnapshot operation.
$request = $client->initTransaction($newCmd)->request;
// Create the new endpoint for the target endpoint.
$endpoint = EndpointProvider::resolve($this->endpointProvider, ['region' => $cmd['SourceRegion'], 'service' => 'ec2'])['endpoint'];
// Set the request to hit the target endpoint.
$request->setHost(Url::fromString($endpoint)->getHost());
// Create a presigned URL for our generated request.
$signer = new SignatureV4('ec2', $cmd['SourceRegion']);
return $signer->createPresignedUrl(SignatureV4::convertPostToGet($request), $client->getCredentials(), '+1 hour');
}
示例12: fromMessage
/**
* Create a request or response object from an HTTP message string
*
* @param string $message Message to parse
*
* @return RequestInterface|ResponseInterface
* @throws \InvalidArgumentException if unable to parse a message
*/
public function fromMessage($message)
{
static $parser;
if (!$parser) {
$parser = new MessageParser();
}
// Parse a response
if (strtoupper(substr($message, 0, 4)) == 'HTTP') {
$data = $parser->parseResponse($message);
return $this->createResponse($data['code'], $data['headers'], $data['body'] === '' ? null : $data['body'], $data);
}
// Parse a request
if (!($data = $parser->parseRequest($message))) {
throw new \InvalidArgumentException('Unable to parse request');
}
return $this->createRequest($data['method'], Url::buildUrl($data['request_url']), ['headers' => $data['headers'], 'body' => $data['body'] === '' ? null : $data['body'], 'config' => ['protocol_version' => $data['protocol_version']]]);
}
示例13: __construct
/**
* @param array $config Service description data
* @param array $options Custom options to apply to the description
* - formatter: Can provide a custom SchemaFormatter class
*
* @throws \InvalidArgumentException
*/
public function __construct(array $config, array $options = [])
{
// Keep a list of default keys used in service descriptions that is
// later used to determine extra data keys.
static $defaultKeys = ['name', 'models', 'apiVersion', 'description'];
// Pull in the default configuration values
foreach ($defaultKeys as $key) {
if (isset($config[$key])) {
$this->{$key} = $config[$key];
}
}
// Set the baseUrl
$this->baseUrl = Url::fromString(isset($config['baseUrl']) ? $config['baseUrl'] : '');
// Ensure that the models and operations properties are always arrays
$this->models = (array) $this->models;
$this->operations = (array) $this->operations;
// We want to add operations differently than adding the other properties
$defaultKeys[] = 'operations';
// Create operations for each operation
if (isset($config['operations'])) {
foreach ($config['operations'] as $name => $operation) {
if (!is_array($operation)) {
throw new \InvalidArgumentException('Operations must be arrays');
}
$this->operations[$name] = $operation;
}
}
// Get all of the additional properties of the service description and
// store them in a data array
foreach (array_diff(array_keys($config), $defaultKeys) as $key) {
$this->extraData[$key] = $config[$key];
}
// Configure the schema formatter
if (isset($options['formatter'])) {
$this->formatter = $options['formatter'];
} else {
static $defaultFormatter;
if (!$defaultFormatter) {
$defaultFormatter = new SchemaFormatter();
}
$this->formatter = $defaultFormatter;
}
}
示例14: buildRequestSet
/**
*
* @param string $url
* @return HttpRequest[]
*/
private function buildRequestSet($url)
{
$useEncodingOptions = $this->getConfiguration()->getToggleUrlEncoding() ? array(true, false) : array(true);
$requests = array();
$userAgentSelection = $this->getConfiguration()->getUserAgentSelectionForRequest();
foreach ($userAgentSelection as $userAgent) {
foreach ($this->getConfiguration()->getHttpMethodList() as $methodIndex => $method) {
foreach ($useEncodingOptions as $useEncoding) {
$requestUrl = GuzzleUrl::fromString($url);
$requestUrl->getQuery()->setEncodingType($useEncoding ? GuzzleQuery::RFC3986 : false);
$request = $this->getConfiguration()->getHttpClient()->createRequest('GET', $requestUrl);
$request->setHeader('user-agent', $userAgent);
if ($this->getConfiguration()->hasReferrer()) {
$request->setHeader('Referer', $this->getConfiguration()->getReferrer());
}
$requests[] = $request;
}
}
}
return $requests;
}
示例15: extractHeaders
private function extractHeaders(BrowserKitRequest $request)
{
$headers = array();
$server = $request->getServer();
$uri = Url::fromString($request->getUri());
$server['HTTP_HOST'] = $uri->getHost();
$port = $uri->getPort();
if ($port !== null && $port !== 443 && $port != 80) {
$server['HTTP_HOST'] .= ':' . $port;
}
$contentHeaders = array('Content-Length' => true, 'Content-Md5' => true, 'Content-Type' => true);
foreach ($server as $header => $val) {
$header = implode('-', array_map('ucfirst', explode('-', strtolower(str_replace('_', '-', $header)))));
if (strpos($header, 'Http-') === 0) {
$headers[substr($header, 5)] = $val;
} elseif (isset($contentHeaders[$header])) {
$headers[$header] = $val;
}
}
$zendHeaders = new HttpHeaders();
$zendHeaders->addHeaders($headers);
return $zendHeaders;
}