本文整理汇总了PHP中Zend\Uri\Uri::setScheme方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::setScheme方法的具体用法?PHP Uri::setScheme怎么用?PHP Uri::setScheme使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Uri\Uri
的用法示例。
在下文中一共展示了Uri::setScheme方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Handle incoming messages.
*
* Must be implemented by all extending classes
*
* @param $url
* @param \React\EventLoop\LoopInterface $loop
* @param \Zend\Log\LoggerInterface $logger
* @throws \InvalidArgumentException
*/
public function __construct($url, LoopInterface $loop, LoggerInterface $logger)
{
$uri = new Uri($url);
if ($uri->getScheme() == 'ws') {
$uri->setScheme('tcp');
} elseif ($uri->getScheme() == 'wss') {
$uri->setScheme('ssl');
}
if ($uri->getScheme() != 'tcp' && $uri->getScheme() != 'ssl') {
throw new \InvalidArgumentException("Uri scheme must be one of: tcp, ssl, ws, wss");
}
$this->uri = $uri;
$this->loop = $loop;
$this->_streams = new SplObjectStorage();
$this->_connections = new SplObjectStorage();
$this->_context = stream_context_create();
$this->_logger = $logger;
}
示例2: geocode
/**
* Execute geocoding
*
* @param Request $request
* @return Response
*/
public function geocode(Request $request)
{
if (null === $request) {
throw new Exception\InvalidArgumentException('request');
}
$uri = new Uri();
$uri->setScheme('https');
$uri->setHost(self::GOOGLE_MAPS_APIS_URL);
$uri->setPath(self::GOOGLE_GEOCODING_API_PATH);
$urlParameters = $request->getUrlParameters();
if (null === $urlParameters) {
throw new Exception\RuntimeException('Invalid URL parameters');
}
$uri->setQuery($urlParameters);
$client = $this->getHttpClient();
$client->resetParameters();
$client->setUri($uri->toString());
$stream = $client->send();
$body = Json::decode($stream->getBody(), Json::TYPE_ARRAY);
$hydrator = new ArraySerializable();
$response = new Response();
$response->setRawBody($body);
if (!isset($body['status'])) {
throw new Exception\RuntimeException('Invalid status');
}
$response->setStatus($body['status']);
if (!isset($body['results'])) {
throw new Exception\RuntimeException('Invalid results');
}
$resultSet = new ResultSet();
foreach ($body['results'] as $data) {
$result = new Result();
$hydrator->hydrate($data, $result);
$resultSet->addElement($result);
}
$response->setResults($resultSet);
return $response;
}
示例3: invalidRelativeUriObjectProvider
/**
* Data provider for invalid relative URI objects
*
* @return array
*/
public function invalidRelativeUriObjectProvider()
{
// Empty URI is not valid
$obj1 = new Uri();
// Path cannot begin with '//'
$obj2 = new Uri();
$obj2->setPath('//path');
// A object with port
$obj3 = new Uri();
$obj3->setPort(123);
// A object with userInfo
$obj4 = new Uri();
$obj4->setUserInfo('shahar:password');
// A object with scheme
$obj5 = new Uri();
$obj5->setScheme('https');
// A object with host
$obj6 = new Uri();
$obj6->setHost('example.com');
return array(array($obj1), array($obj2), array($obj3), array($obj4), array($obj5), array($obj6));
}
示例4: enforceScheme
/**
* Enforce the defined scheme on the URI
*
* This will also adjust the host and path parts of the URI as expected in
* the case of scheme-less network URIs
*
* @param Uri $uri
*/
protected function enforceScheme(Uri $uri)
{
$path = $uri->getPath();
if (strpos($path, '/') !== false) {
list($host, $path) = explode('/', $path, 2);
$path = '/' . $path;
} else {
$host = $path;
$path = '';
}
// We have nothing to do if we have no host
if (!$host) {
return;
}
$uri->setScheme($this->enforcedScheme)->setHost($host)->setPath($path);
}
示例5: testSetInvalidScheme
/**
* Test that setting an invalid scheme causes an exception
*
* @param string $scheme
* @dataProvider invalidSchemeProvider
*/
public function testSetInvalidScheme($scheme)
{
$uri = new Uri;
$this->setExpectedException('Zend\Uri\Exception\InvalidUriPartException');
$uri->setScheme($scheme);
}
示例6: ftpCurl
/**
* Build cURL for FTP
*
* @param Uri $uri
* @param array $options
*
* @return resource
* @throws \InitializationException
*/
protected function ftpCurl(Uri $uri, array $options)
{
if (!extension_loaded('curl')) {
throw new \InitializationException('cURL extension is not installed.');
}
$uri->setScheme('ftp');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $uri->__toString());
if (!empty($options['username']) && !empty($options['password'])) {
$userpwd = $options['username'] . ':' . $options['password'];
curl_setopt($curl, CURLOPT_USERPWD, $userpwd);
}
if (isset($options['timeout'])) {
curl_setopt($curl, CURLOPT_TIMEOUT, (int) $options['timeout']);
}
return $curl;
}
示例7: setScheme
/**
* Set the URI scheme
*
* @param string $scheme
* @throws Exception\InvalidUriPartException
* @return \Zend\Uri\Uri
*/
public function setScheme($scheme)
{
$this->uri->setScheme($scheme);
return $this;
}