• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Psr7\Uri类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: executeKohanaRequest

 private function executeKohanaRequest(ServerRequestInterface $request, $redirect = 0)
 {
     if ($redirect >= self::MAX_REDIRECTS) {
         throw new LogicException(sprintf('Maximum Number of redirects (%s) for url %s', self::MAX_REDIRECTS, $request->getUri()));
     }
     Request::$initial = $kohanaRequest = $this->getKohanaRequest($request);
     Request::$user_agent = self::USER_AGENT;
     $_FILES = $request->getAttribute('FILES');
     $kohanaResponse = $kohanaRequest->execute();
     $this->current = $request;
     $status = $kohanaResponse->status();
     if ($status >= 300 && $status < 400) {
         $redirectUri = new Psr7\Uri($kohanaResponse->headers('location'));
         $localUri = $redirectUri->withScheme(null)->withUserInfo(null)->withHost(null)->withPort(null);
         return $this->executeKohanaRequest(new Psr7\ServerRequest('GET', $localUri), $redirect + 1);
     }
     return $kohanaResponse;
 }
开发者ID:spiderling-php,项目名称:kohana-driver,代码行数:18,代码来源:Loader.php


示例17: __invoke

 /**
  * {@inheritDoc}
  */
 public function __invoke(RequestInterface $request, array $options)
 {
     $next = $this->nextHandler;
     if (!$this->config->has('access_token') || $this->config->get('access_token') === null) {
         return $next($request, $options);
     }
     $uri = Uri::withQueryValue($request->getUri(), 'access_token', $this->config->get('access_token')->getToken());
     return parent::__invoke($request->withUri($uri)->withHeader('Content-Type', 'application/json'), $options);
 }
开发者ID:larabros,项目名称:elogram,代码行数:12,代码来源:AuthMiddleware.php


示例18: __construct

 public function __construct(Options $options, OutputInterface $ouput)
 {
     $timeout = $options->getTimeout();
     $client = new ClientGuzzle(['timeout' => $timeout]);
     $url = $options->getUrl();
     $response = $client->get($url);
     if ($response->getStatusCode() != 200) {
         throw new RuntimeException(sprintf('Cannot access this url: "%s"', $url));
     }
     $uri = new Uri($url);
     $baseUri = $uri->getScheme() . '://' . $uri->getHost();
     if (!empty($uri->getPort())) {
         $baseUri .= ':' . $uri->getPort();
     }
     $options->setBaseUri($baseUri);
     $this->options = $options;
     $this->output = $ouput;
 }
开发者ID:tmquang6805,项目名称:scrapimage,代码行数:18,代码来源:Client.php


示例19: get

 public static function get(array $options, $key)
 {
     $stack = HandlerStack::create();
     $stack->unshift(Middleware::mapRequest(function (RequestInterface $request) use($key) {
         return $request->withUri(Uri::withQueryValue($request->getUri(), 'key', $key));
     }));
     $options['handler'] = $stack;
     return new Client($options);
 }
开发者ID:mcfedr,项目名称:youtubelivestreamsbundle,代码行数:9,代码来源:GuzzleClientFactory.php


示例20: makeUri

 /**
  * @param $url
  * @param array $params
  *
  * @return \Psr\Http\Message\UriInterface
  */
 private function makeUri($url, $params = array())
 {
     $uri = \GuzzleHttp\uri_template($this->endpoint, array_merge($this->defaults, $params));
     $uri = new Psr7\Uri($uri);
     // All arguments must be urlencoded (as per RFC 1738).
     $query = Psr7\build_query($params, PHP_QUERY_RFC1738);
     $uri = $uri->withQuery($query);
     return Psr7\Uri::withQueryValue($uri, 'url', $url);
 }
开发者ID:bangpound,项目名称:oembed,代码行数:15,代码来源:StandardProvider.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Stream\Stream类代码示例发布时间:2022-05-23
下一篇:
PHP Psr7\Response类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap