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


PHP Uri::fromParts方法代码示例

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


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

示例1: 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

示例2: 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

示例3: __construct

 /**
  * @param array  $params
  * @param string $username
  * @param string $password
  * @param array  $driverOptions
  *
  * @throws HttpException
  */
 public function __construct(array $params, $username, $password, array $driverOptions = array())
 {
     if (!class_exists('GuzzleHttp\\Client')) {
         $message = sprintf('The socket connection requires a package "%s" but was not installed.', static::PACKAGE);
         throw new HttpException($message);
     }
     if (empty($params['host']) or empty($params['port']) or empty($params['dbname']) or empty($params['user']) or empty($params['password'])) {
         throw new HttpException('Host, port, dbname, user and password name must be configured.');
     }
     $this->hostname = $params['host'];
     $this->port = $params['port'];
     $this->username = $params['user'];
     $this->password = $params['password'];
     $this->database = $params['dbname'];
     $uri = Uri::fromParts(array('scheme' => 'http', 'host' => $this->hostname, 'port' => $this->port));
     $this->connection = new BaseConnection(array('base_uri' => $uri, 'handler' => HandlerStack::create(), 'cookies' => new CookieJar()));
     $this->connect();
 }
开发者ID:mihai-stancu,项目名称:orientdb-orm,代码行数:26,代码来源:HttpConnection.php

示例4: buildUri

 /**
  * Build a URI object for the Request.
  *
  * @param \Glassdoor\Action\ActionInterface $action
  *   Action to send to API.
  *
  * @return \GuzzleHttp\Psr7\Uri
  *   Uri object.
  */
 private function buildUri(ActionInterface $action)
 {
     $parts = parse_url($this->config->getBaseUrl());
     $params = $action->getParams();
     $params['v'] = $action->getVersion();
     $params['format'] = $this->config->getResponseFormat();
     $params['t.p'] = $this->config->getPartnerId();
     $params['t.k'] = $this->config->getPartnerKey();
     $params['userip'] = $this->config->getUserIp();
     $params['useragent'] = $this->config->getUserAgent();
     $params['action'] = $action->action();
     // Allow any overrides.
     if (!empty($parts['query'])) {
         parse_str($parts['query'], $query_params);
         array_merge($params, $query_params);
     }
     $parts['query'] = http_build_query($params);
     return Uri::fromParts($parts);
 }
开发者ID:karllhughes,项目名称:glassdoor,代码行数:28,代码来源:Connection.php

示例5: parseConnections

 protected function parseConnections($options, $defaultHost, $defaultPort)
 {
     if (isset($options['host']) || isset($options['port'])) {
         $options['connections'][] = $options;
     } elseif ($options['connection']) {
         $options['connections'][] = $options['connection'];
     }
     /** @var ParameterBag[] $toParse */
     $toParse = [];
     if (isset($options['connections'])) {
         foreach ((array) $options['connections'] as $alias => $conn) {
             if (is_string($conn)) {
                 $conn = ['host' => $conn];
             }
             $conn += ['scheme' => 'tcp', 'host' => $defaultHost, 'port' => $defaultPort];
             $conn = new ParameterBag($conn);
             if ($conn->has('password')) {
                 $conn->set('pass', $conn->get('password'));
                 $conn->remove('password');
             }
             $conn->set('uri', Uri::fromParts($conn->all()));
             $toParse[] = $conn;
         }
     } elseif (isset($options['save_path'])) {
         foreach (explode(',', $options['save_path']) as $conn) {
             $uri = new Uri($conn);
             $connBag = new ParameterBag();
             $connBag->set('uri', $uri);
             $connBag->add(parse_query($uri->getQuery()));
             $toParse[] = $connBag;
         }
     }
     $connections = [];
     foreach ($toParse as $conn) {
         /** @var Uri $uri */
         $uri = $conn->get('uri');
         $parts = explode(':', $uri->getUserInfo(), 2);
         $password = isset($parts[1]) ? $parts[1] : null;
         $connections[] = ['scheme' => $uri->getScheme(), 'host' => $uri->getHost(), 'port' => $uri->getPort(), 'path' => $uri->getPath(), 'alias' => $conn->get('alias'), 'prefix' => $conn->get('prefix'), 'password' => $password, 'database' => $conn->get('database'), 'persistent' => $conn->get('persistent'), 'weight' => $conn->get('weight'), 'timeout' => $conn->get('timeout')];
     }
     return $connections;
 }
开发者ID:gandalf3,项目名称:bolt,代码行数:42,代码来源:SessionServiceProvider.php

示例6: parseConnections

 protected function parseConnections($options, $defaultHost, $defaultPort, $defaultScheme = 'tcp')
 {
     if (isset($options['host']) || isset($options['port'])) {
         $options['connections'][] = $options;
     } elseif ($options['connection']) {
         $options['connections'][] = $options['connection'];
     }
     /** @var ParameterBag[] $toParse */
     $toParse = [];
     if (isset($options['connections'])) {
         foreach ((array) $options['connections'] as $alias => $conn) {
             if (is_string($conn)) {
                 $conn = ['host' => $conn];
             }
             $conn += ['scheme' => $defaultScheme, 'host' => $defaultHost, 'port' => $defaultPort];
             $conn = new ParameterBag($conn);
             if ($conn->has('password')) {
                 $conn->set('pass', $conn->get('password'));
                 $conn->remove('password');
             }
             $conn->set('uri', Uri::fromParts($conn->all()));
             $toParse[] = $conn;
         }
     } else {
         $connections = isset($options['save_path']) ? (array) explode(',', $options['save_path']) : [];
         if (empty($connections)) {
             $connections[] = $defaultHost . ':' . $defaultPort;
         }
         foreach ($connections as $conn) {
             // Default scheme if not given so parse_url works correctly.
             if (!preg_match('~^\\w+://.+~', $conn)) {
                 $conn = $defaultScheme . '://' . $conn;
             }
             $uri = new Uri($conn);
             $connBag = new ParameterBag();
             $connBag->set('uri', $uri);
             $connBag->add(Psr7\parse_query($uri->getQuery()));
             $toParse[] = $connBag;
         }
     }
     $connections = [];
     foreach ($toParse as $conn) {
         /** @var Uri $uri */
         $uri = $conn->get('uri');
         $parts = explode(':', $uri->getUserInfo(), 2);
         $password = isset($parts[1]) ? $parts[1] : null;
         $connections[] = ['scheme' => $uri->getScheme(), 'host' => $uri->getHost(), 'port' => $uri->getPort(), 'path' => $uri->getPath(), 'alias' => $conn->get('alias'), 'prefix' => $conn->get('prefix'), 'password' => $password, 'database' => $conn->get('database'), 'persistent' => $conn->get('persistent'), 'weight' => $conn->get('weight'), 'timeout' => $conn->get('timeout')];
     }
     return $connections;
 }
开发者ID:bolt,项目名称:bolt,代码行数:50,代码来源:SessionServiceProvider.php

示例7: _getBaseUrl

 /**
  * Builds the base url for the guzzle connection.
  *
  * @param \Elastica\Connection $connection
  *
  * @return string
  */
 protected function _getBaseUrl(Connection $connection)
 {
     // If url is set, url is taken. Otherwise port, host and path
     $url = $connection->hasConfig('url') ? $connection->getConfig('url') : '';
     if (!empty($url)) {
         $baseUri = $url;
     } else {
         $baseUri = (string) Uri::fromParts(['scheme' => $this->_scheme, 'host' => $connection->getHost(), 'port' => $connection->getPort(), 'path' => ltrim('/', $connection->getPath())]);
     }
     return rtrim($baseUri, '/');
 }
开发者ID:levijackson,项目名称:Elastica,代码行数:18,代码来源:Guzzle.php

示例8: testDoesNotAddSlashWhenPathIsEmpty

 public function testDoesNotAddSlashWhenPathIsEmpty()
 {
     $uri = Uri::fromParts(['scheme' => 'http', 'host' => 'example.com', 'path' => '', 'query' => 'foo']);
     $this->assertEquals('', $uri->getPath());
     $this->assertEquals('http://example.com?foo', (string) $uri);
 }
开发者ID:azonwan,项目名称:pingju,代码行数:6,代码来源:UriTest.php

示例9: transformToUploadUrl

 private function transformToUploadUrl()
 {
     $parts = parse_url((string) $this->request->getUri());
     if (!isset($parts['path'])) {
         $parts['path'] = '';
     }
     $parts['path'] = '/upload' . $parts['path'];
     $uri = Uri::fromParts($parts);
     $this->request = $this->request->withUri($uri);
 }
开发者ID:Devids,项目名称:google-api-php-client,代码行数:10,代码来源:MediaFileUpload.php

示例10: testFromParts

 /**
  * @dataProvider getValidUris
  */
 public function testFromParts($input)
 {
     $uri = Uri::fromParts(parse_url($input));
     $this->assertSame($input, (string) $uri);
 }
开发者ID:nystudio107,项目名称:instantanalytics,代码行数:8,代码来源:UriTest.php

示例11: resolveUri

 /**
  * @param string $rawPath
  * @param array $query
  * @param array $options
  *
  * @return Uri
  *
  * @throws \Exception
  */
 protected function resolveUri($rawPath, array $query, array $options)
 {
     $query = array_filter($query);
     $matches = [];
     preg_match_all('/[\\{]{1}([\\w]+)[\\}]{1}/', $rawPath, $matches);
     $requiredOptions = $matches[1];
     foreach ($requiredOptions as $option) {
         if (!array_key_exists($option, $options)) {
             throw new \Exception('Missing option ' . $option);
         }
         $rawPath = str_replace('{' . $option . '}', $options[$option], $rawPath);
     }
     $uri = Uri::fromParts(['scheme' => $this->clientDescription->getSchema(), 'host' => $this->clientDescription->getHost(), 'path' => $rawPath]);
     foreach ($query as $name => $value) {
         $uri = Uri::withQueryValue($uri, $name, $value);
     }
     return $uri;
 }
开发者ID:Vesax,项目名称:rest-client-bundle,代码行数:27,代码来源:Client.php

示例12: setBaseUrl

 /**
  * @param string $baseUrl
  */
 public function setBaseUrl($baseUrl)
 {
     $this->baseUrl = Uri::fromParts(parse_url($baseUrl));
 }
开发者ID:noxify,项目名称:apist,代码行数:7,代码来源:Apist.php


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