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


PHP Psr7\Uri类代码示例

本文整理汇总了PHP中GuzzleHttp\Psr7\Uri的典型用法代码示例。如果您正苦于以下问题:PHP Uri类的具体用法?PHP Uri怎么用?PHP Uri使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: withBaseUri

 /**
  * @param string|UriInterface $baseUri
  * @return ApiUri
  * @throws \InvalidArgumentException
  */
 public function withBaseUri($baseUri)
 {
     if (empty($baseUri)) {
         throw new \InvalidArgumentException('You must provide a non-empty string or PSR-7 UserInterface');
     } elseif (is_string($baseUri)) {
         $baseUri = new Psr7\Uri($baseUri);
     } elseif (!$baseUri instanceof UriInterface) {
         throw new \InvalidArgumentException('Invalid format provided; should either be a string or PSR-7 UriInterface');
     }
     if (!in_array($baseUri->getScheme(), ['http', 'https'])) {
         throw new \InvalidArgumentException('Only http & https schemes are allowed');
     }
     // always store the base URI with a final /
     if (!preg_match('{/$}', $baseUri->getPath())) {
         $baseUri = $baseUri->withPath($baseUri->getPath() . '/');
     }
     /** @var ApiUri $new */
     if ('' === (string) $this) {
         $new = new static($baseUri);
     } else {
         $new = clone $this;
     }
     $new->baseUri = $baseUri;
     return $new;
 }
开发者ID:redefining,项目名称:rest-api-client,代码行数:30,代码来源:ApiUri.php

示例2: register

 public function register(Container $pimple)
 {
     // File extensions used to determine whether a URI points to an asset
     // or an HTML file.
     $pimple['html_extensions'] = static::$html_extensions;
     $pimple['asset_extensions'] = static::$asset_extensions;
     // Matches any URI we think points to an HTML page.
     $pimple['matcher.html'] = function () use($pimple) {
         return Matcher::all()->pathExtensionIs($pimple['html_extensions']);
     };
     // Matches any URI we think points to an asset file.
     $pimple['matcher.asset'] = function () use($pimple) {
         return Matcher::all()->pathExtensionIs($pimple['asset_extensions']);
     };
     // Matches any URI that is considered "in scope."
     $pimple['matcher.internal'] = function () use($pimple) {
         $uri = new Uri($pimple['base_url']);
         return Matcher::all()->schemeIs($uri->getScheme())->hostIs($uri->getHost())->pathMatches('~^' . preg_quote($uri->getPath(), '~') . '~');
     };
     // Matches any URI that is both internal and HTML.
     $pimple['matcher.internal_html'] = function () use($pimple) {
         return Matcher::all()->add($pimple['matcher.internal'])->add($pimple['matcher.html']);
     };
     // Matches any URI that is both internal and an asset.
     $pimple['matcher.internal_asset'] = function () use($pimple) {
         return Matcher::all()->add($pimple['matcher.internal'])->add($pimple['matcher.asset']);
     };
 }
开发者ID:LastCallMedia,项目名称:Crawler,代码行数:28,代码来源:MatcherServiceProvider.php

示例3: initialize

 /**
  * Initialize the stream client and resources
  *
  * @param string $path
  */
 protected function initialize($path)
 {
     $uri = new Uri($path);
     if (!ctype_digit($uri->getHost())) {
         throw new \InvalidArgumentException(sprintf('path "%s" must be of type integer', $path));
     }
     $this->length = (int) $uri->getHost();
 }
开发者ID:epfremmer,项目名称:PHP-Weekly-Issue16,代码行数:13,代码来源:RandomString.php

示例4: perform

 /**
  * {@inheritdoc}
  */
 public function perform(OperationInterface $operation, ConfigurationInterface $configuration)
 {
     $preparedRequestParams = $this->prepareRequestParams($operation, $configuration);
     $queryString = $this->buildQueryString($preparedRequestParams, $configuration);
     $uri = new Uri(sprintf($this->requestTemplate, $configuration->getCountry(), $queryString));
     $request = new \GuzzleHttp\Psr7\Request('GET', $uri->withScheme($this->scheme), ['User-Agent' => 'ApaiIO [' . ApaiIO::VERSION . ']']);
     $result = $this->client->send($request);
     return $result->getBody()->getContents();
 }
开发者ID:exeu,项目名称:apai-io,代码行数:12,代码来源:GuzzleRequest.php

示例5: appendPath

 public static function appendPath($url, $path)
 {
     $uri = new Psr7Uri($url);
     $cutUrl = (string) $uri->withQuery('')->withFragment('');
     if ($path === '' || $path[0] === '#') {
         return $cutUrl . $path;
     } else {
         return rtrim($cutUrl, '/') . '/' . ltrim($path, '/');
     }
 }
开发者ID:vladislavl-hyuna,项目名称:crmapp,代码行数:10,代码来源:Uri.php

示例6: execute

 /**
  * @param array $params {
  *      @var string             $resource Flora resource
  *      @var int|string         $id             optional    Unique item identifier
  *      @var string             $format         optional    Output format (default json)
  *      @var string             $action         optional    API action (default: retrieve)
  *      @var string             $select         optional    Retrieve only specified attributes
  *      @var string             $filter         optional    Filter items by criteria
  *      @var int                $limit          optional    Limit result set
  *      @var int                $page           optional    Paginate through result set
  *      @var string             $search         optional    Search items by full-text search
  *      @var bool               $cache          optional    En-/disable caching (default: true)
  *      @var bool               $authenticate   optional    Use authentication provider to add some authentication information to request
  *      @var string             $httpMethod     optional    Explicitly set/override HTTP (GET, POST,...) method
  *      @var array|\stdClass    $data           optional    Send $data as JSON
  * }
  * @return \stdClass
  * @throws \Flora\Exception
  */
 public function execute(array $params)
 {
     if (!isset($params['resource']) || empty($params['resource'])) {
         throw new Exception('Resource must be set');
     }
     $uri = $this->uri->withPath($this->getPath($params));
     foreach (['resource', 'id', 'format'] as $param) {
         // remove path params from request params
         if (isset($params[$param])) {
             unset($params[$param]);
         }
     }
     if (array_key_exists('cache', $params)) {
         if ((bool) $params['cache'] === false) {
             $params['_'] = time();
         }
         unset($params['cache']);
     }
     if (isset($params['action']) && $params['action'] == 'retrieve') {
         unset($params['action']);
     }
     $httpMethod = $this->getHttpMethod($params);
     $request = new Request($httpMethod, $uri, ['Referer' => $this->getCurrentUri()]);
     if (isset($params['authenticate'])) {
         if ((bool) $params['authenticate']) {
             if ($this->authProvider === null) {
                 throw new Exception('Authentication provider is not configured');
             }
             $request = $this->authProvider->authenticate($request);
         }
         unset($params['authenticate']);
     }
     if (!empty($this->defaultParams)) {
         $params = array_merge($this->defaultParams, $params);
     }
     if (!empty($params)) {
         $request = $this->applyParameters($request, $params);
     }
     try {
         $response = $this->httpClient->send($request, $this->httpOptions);
     } catch (RequestException $e) {
         throw new Exception($e->getMessage());
     }
     $result = $response->getBody();
     $contentType = $response->getHeaderLine('Content-Type');
     if (strpos($contentType, 'application/json') !== false) {
         $result = json_decode($result);
     }
     $statusCode = $response->getStatusCode();
     if ($statusCode < 400) {
         return $result;
     }
     $this->throwError($statusCode, $result->error);
 }
开发者ID:godmodelabs,项目名称:flora-client-php,代码行数:73,代码来源:Client.php

示例7: getSignedUrl

 /**
  * 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 getSignedUrl($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]);
     $uri = new Uri($scheme . '://' . $urlSections[1]);
     $query = Psr7\parse_query($uri->getQuery(), PHP_QUERY_RFC3986);
     $signature = $this->signer->getSignature($this->createResource($scheme, (string) $uri), $expires, $policy);
     $uri = $uri->withQuery(http_build_query($query + $signature, null, '&', PHP_QUERY_RFC3986));
     return $scheme === 'rtmp' ? $this->createRtmpUrl($uri) : (string) $uri;
 }
开发者ID:AWSRandall,项目名称:aws-sdk-php,代码行数:36,代码来源:UrlSigner.php

示例8: transform

 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     // Only apply to a full URL.
     if (is_string($value) && strpos($value, '://') > 0) {
         // URL encode everything after the hostname.
         $parsed_url = parse_url($value);
         // Fail on seriously malformed URLs.
         if ($parsed_url === FALSE) {
             throw new MigrateException("Value '{$value}' is not a valid URL");
         }
         // Iterate over specific pieces of the URL rawurlencoding each one.
         $url_parts_to_encode = array('path', 'query', 'fragment');
         foreach ($parsed_url as $parsed_url_key => $parsed_url_value) {
             if (in_array($parsed_url_key, $url_parts_to_encode)) {
                 // urlencode() would convert spaces to + signs.
                 $urlencoded_parsed_url_value = rawurlencode($parsed_url_value);
                 // Restore special characters depending on which part of the URL this is.
                 switch ($parsed_url_key) {
                     case 'query':
                         $urlencoded_parsed_url_value = str_replace('%26', '&', $urlencoded_parsed_url_value);
                         break;
                     case 'path':
                         $urlencoded_parsed_url_value = str_replace('%2F', '/', $urlencoded_parsed_url_value);
                         break;
                 }
                 $parsed_url[$parsed_url_key] = $urlencoded_parsed_url_value;
             }
         }
         $value = (string) Uri::fromParts($parsed_url);
     }
     return $value;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:35,代码来源:UrlEncode.php

示例9: convertUrlsToAbsolute

 /**
  * Convert relative links, images scr and form actions to absolute
  *
  * @param ElementFinder $page
  * @param string $affectedUrl
  */
 public static function convertUrlsToAbsolute(ElementFinder $page, $affectedUrl)
 {
     $affected = new Uri($affectedUrl);
     $srcElements = $page->element('//*[@src] | //*[@href] | //form[@action]');
     $baseUrl = $page->value('//base/@href')->getFirst();
     foreach ($srcElements as $element) {
         $attributeName = 'href';
         if ($element->hasAttribute('action') === true and $element->tagName === 'form') {
             $attributeName = 'action';
         } else {
             if ($element->hasAttribute('src') === true) {
                 $attributeName = 'src';
             }
         }
         $relative = $element->getAttribute($attributeName);
         # don`t change javascript in href
         if (preg_match('!^\\s*javascript\\s*:\\s*!', $relative)) {
             continue;
         }
         if (parse_url($relative) === false) {
             continue;
         }
         if (!empty($baseUrl) and !preg_match('!^(/|http)!i', $relative)) {
             $relative = Uri::resolve(new Uri($baseUrl), $relative);
         }
         $url = Uri::resolve($affected, (string) $relative);
         $element->setAttribute($attributeName, (string) $url);
     }
 }
开发者ID:xparse,项目名称:parser,代码行数:35,代码来源:LinkConverter.php

示例10: __invoke

 /**
  * @param RequestInterface $request
  * @return RequestInterface
  */
 public function __invoke(RequestInterface $request)
 {
     foreach ($this->params as $param => $value) {
         $request = $request->withUri(Uri::withQueryValue($request->getUri(), $param, $value));
     }
     return $request;
 }
开发者ID:emarref,项目名称:guzzle-param-middleware,代码行数:11,代码来源:ParamMiddleware.php

示例11: getForm

 public function getForm($formId, $params, $headers)
 {
     /** @var DOMElement $form */
     $dom = new DomDocument();
     libxml_use_internal_errors(true);
     $dom->loadHTML($this->response());
     $xpath = new DOMXpath($dom);
     $form = $xpath->query("//form[@id='{$formId}']")->item(0);
     $elements = $xpath->query('//input');
     $form_params = [];
     $allowedTypes = ["hidden", "text", "password"];
     foreach ($elements as $element) {
         /** @var DOMElement $element */
         $type = $element->getAttribute("type");
         if (in_array($type, $allowedTypes)) {
             $name = $element->getAttribute("name");
             $value = $element->getAttribute("value");
             $form_params[$name] = $value;
         }
     }
     $headers = array_merge(["Referer" => $this->baseUri], $headers);
     $url = Uri::resolve(new Uri($this->baseUri), $form->getAttribute("action"))->__toString();
     $method = strtoupper($form->getAttribute("method"));
     return ["method" => $method, "url" => $url, "headers" => $headers, "params" => array_merge($form_params, $params)];
 }
开发者ID:ifgroup,项目名称:browser,代码行数:25,代码来源:Browser.php

示例12: baseString

 /**
  * Generate a base string for a HMAC-SHA1 signature
  * based on the given a url, method, and any parameters.
  *
  * @param Url    $url
  * @param string $method
  * @param array  $parameters
  *
  * @return string
  */
 protected function baseString(Uri $url, $method = 'POST', array $parameters = array())
 {
     $baseString = rawurlencode($method) . '&';
     $schemeHostPath = Uri::fromParts(array('scheme' => $url->getScheme(), 'host' => $url->getHost(), 'path' => $url->getPath()));
     $baseString .= rawurlencode($schemeHostPath) . '&';
     $data = array();
     parse_str($url->getQuery(), $query);
     $data = array_merge($query, $parameters);
     // normalize data key/values
     array_walk_recursive($data, function (&$key, &$value) {
         $key = rawurlencode(rawurldecode($key));
         $value = rawurlencode(rawurldecode($value));
     });
     ksort($data);
     $baseString .= $this->queryStringFromData($data);
     return $baseString;
 }
开发者ID:dukt,项目名称:craft-oauth,代码行数:27,代码来源:HmacSha1Signature.php

示例13: uriFor

 /**
  * @param string $filename
  * @param string $version
  *
  * @return \Psr\Http\Message\UriInterface
  */
 public function uriFor($filename, $version = '')
 {
     $filename = original_version($filename);
     if ($version) {
         $filename .= ":{$version}";
     }
     return Uri::resolve($this->baseUri, $filename);
 }
开发者ID:livetyping,项目名称:hermitage-php-client,代码行数:14,代码来源:Client.php

示例14: appendQueryParams

 /**
  * @param RequestInterface $request
  *
  * @return RequestInterface
  */
 private function appendQueryParams(RequestInterface $request)
 {
     $queryParams = $this->auth->getQueryParameters();
     foreach ($queryParams as $key => $value) {
         $uri = Uri::withQueryValue($request->getUri(), $key, $value);
         $request = $request->withUri($uri);
     }
     return $request;
 }
开发者ID:adlogix,项目名称:guzzle-atlassian-connect-middleware,代码行数:14,代码来源:ConnectMiddleware.php

示例15: research

 /**
  * @param RequestInterface $request
  *
  * @return ResponseInterface
  *
  * @throws ApiException | SearchLimitException
  */
 public function research(RequestInterface $request)
 {
     try {
         $response = $this->httpClient->request('GET', Uri::withQueryValue($request->getUri(), 'apikey', $this->apiKey));
         return new Response($response);
     } catch (\GuzzleHttp\Exception\ClientException $ex) {
         throw ExceptionFactory::createThrowable($ex);
     }
 }
开发者ID:spalax,项目名称:keywordtool-client,代码行数:16,代码来源:Client.php


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