当前位置: 首页>>代码示例>>PHP>>正文


PHP Url::fromString方法代码示例

本文整理汇总了PHP中GuzzleHttp\Url::fromString方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::fromString方法的具体用法?PHP Url::fromString怎么用?PHP Url::fromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Url的用法示例。


在下文中一共展示了Url::fromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:keboola,项目名称:juicer,代码行数:29,代码来源:ZendeskResponseUrlScroller.php

示例2: __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));
         });
     }
 }
开发者ID:assad2012,项目名称:EvaOAuth,代码行数:33,代码来源:AuthorizedHttpClient.php

示例3: 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);
 }
开发者ID:danielcosta,项目名称:sellercenter-sdk,代码行数:38,代码来源:RestSerializer.php

示例4: 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);
 }
开发者ID:keboola,项目名称:juicer,代码行数:28,代码来源:FacebookResponseUrlScroller.php

示例5: 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']));
     }
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:9,代码来源:QueueUrlSubscriber.php

示例6: 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);
 }
开发者ID:hilmysyarif,项目名称:sic,代码行数:9,代码来源:AbstractCurl.php

示例7: 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;
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:11,代码来源:CloudSearchDomainClient.php

示例8: 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;
 }
开发者ID:boxrice007,项目名称:openstack,代码行数:22,代码来源:QuerySerializer.php

示例9: 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');
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:14,代码来源:CopySnapshotSubscriber.php

示例10: parse

 /**
  * Parses a URL into an associative array of Amazon S3 data including:
  *
  * - bucket: The Amazon S3 bucket (null if none)
  * - key: The Amazon S3 key (null if none)
  * - path_style: Set to true if using path style, or false if not
  * - region: Set to a string if a non-class endpoint is used or null.
  *
  * @param $uri
  *
  * @return array
  * @throws \InvalidArgumentException
  */
 public function parse($uri)
 {
     $url = Url::fromString($uri);
     if (!$url->getHost()) {
         throw new \InvalidArgumentException('No hostname found in URI: ' . $uri);
     }
     if (!preg_match($this->pattern, $url->getHost(), $matches)) {
         return $this->parseCustomEndpoint($url);
     }
     // Parse the URI based on the matched format (path / virtual)
     $result = empty($matches[1]) ? $this->parsePathStyle($url) : $this->parseVirtualHosted($url, $matches);
     // Add the region if one was found and not the classic endpoint
     $result['region'] = $matches[2] == 'amazonaws' ? null : $matches[2];
     return $result;
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:28,代码来源:S3UriParser.php

示例11: validate

 /**
  * Validates a message from SNS to ensure that it was delivered by AWS
  *
  * @param Message $message The message to validate
  *
  * @throws MessageValidatorException If the certificate cannot be
  *     retrieved, if the certificate's source cannot be verified, or if the
  *     message's signature is invalid.
  */
 public function validate(Message $message)
 {
     // Get and validate the URL for the certificate.
     $certUrl = Url::fromString($message->get('SigningCertURL'));
     $this->validateUrl($certUrl);
     // Get the cert itself and extract the public key
     $certificate = $this->client->get((string) $certUrl)->getBody();
     $key = openssl_get_publickey($certificate);
     if (!$key) {
         throw new MessageValidatorException('Cannot get the public key ' . 'from the certificate.');
     }
     // Verify the signature of the message
     $content = $message->getStringToSign();
     $signature = base64_decode($message->get('Signature'));
     if (!openssl_verify($content, $signature, $key, OPENSSL_ALGO_SHA1)) {
         throw new MessageValidatorException('The message signature is ' . 'invalid.');
     }
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:27,代码来源:MessageValidator.php

示例12: __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;
     }
 }
开发者ID:danieledangeli,项目名称:guzzle-services,代码行数:50,代码来源:Description.php

示例13: getUrlSigner

 /**
  * Create a signed Amazon CloudFront URL.
  *
  * Keep in mind that URLs meant for use in media/flash players may have
  * different requirements for URL formats (e.g. some require that the
  * extension be removed, some require the file name to be prefixed
  * - mp4:<path>, some require you to add "/cfx/st" into your URL).
  *
  * @param string              $url     URL to sign (can include query
  *                                     string string and wildcards
  * @param string|integer|null $expires UTC Unix timestamp used when signing
  *                                     with a canned policy. Not required
  *                                     when passing a custom $policy.
  * @param string              $policy  JSON policy. Use this option when
  *                                     creating a signed URL for a custom
  *                                     policy.
  *
  * @return string The file URL with authentication parameters
  * @throws \InvalidArgumentException if the URL provided is invalid
  * @link http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/WorkingWithStreamingDistributions.html
  */
 public function getUrlSigner($url, $expires = null, $policy = null)
 {
     // Determine the scheme of the url
     $urlSections = explode('://', $url);
     if (count($urlSections) < 2) {
         throw new \InvalidArgumentException("Invalid URL: {$url}");
     }
     // Get the real scheme by removing wildcards from the scheme
     $scheme = str_replace('*', '', $urlSections[0]);
     if ($policy) {
         $isCustom = true;
     } else {
         $isCustom = false;
         $policy = $this->createCannedPolicy($scheme, $url, $expires);
     }
     $policy = str_replace(' ', '', $policy);
     $url = Url::fromString($scheme . '://' . $urlSections[1]);
     $this->prepareQuery($isCustom, $policy, $url->getQuery(), $expires);
     return $scheme === 'rtmp' ? $this->createRtmpUrl($url) : (string) $url;
 }
开发者ID:briareos,项目名称:aws-sdk-php,代码行数:41,代码来源:UrlSigner.php

示例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;
 }
开发者ID:webignition,项目名称:url-health-checker,代码行数:26,代码来源:UrlHealthChecker.php

示例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;
 }
开发者ID:kansey,项目名称:yii2albom,代码行数:23,代码来源:ZF2.php


注:本文中的GuzzleHttp\Url::fromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。