本文整理汇总了PHP中Guzzle\Http\Url类的典型用法代码示例。如果您正苦于以下问题:PHP Url类的具体用法?PHP Url怎么用?PHP Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Url类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildRequestUrl
/**
* @param Actions\ActionsInterface $action
* @param array $requestParams
* @return Url
*/
protected function buildRequestUrl(Actions\ActionsInterface $action, array $requestParams)
{
$url = new Url('https', $this->connection->getEndpoint());
$url->setPath($action->getAction());
$url->setQuery($requestParams);
return $url;
}
示例2: validateUrl
private function validateUrl(Url $url)
{
// The host must match the following pattern
$hostPattern = '/^sns\\.[a-zA-Z0-9\\-]{3,}\\.amazonaws\\.com(\\.cn)?$/';
if ($url->getScheme() !== 'https' || substr($url, -4) !== '.pem' || !preg_match($hostPattern, $url->getHost())) {
throw new CertificateFromUnrecognizedSourceException();
}
}
示例3: parseServiceName
/**
* Parse the AWS service name from a URL
*
* @param Url $url HTTP URL
*
* @return string Returns a service name (or empty string)
* @link http://docs.amazonwebservices.com/general/latest/gr/rande.html
*/
public static function parseServiceName(Url $url)
{
// The service name is the first part of the host
$parts = explode('.', $url->getHost(), 2);
// Special handling for S3
if (stripos($parts[0], 's3') === 0) {
return 's3';
}
return $parts[0];
}
示例4: getLoginUrl
/**
* Запрос На авторизацию
*
* @param string $redirectUrl Урл для
* @param string $state дополнительный get параметр который подставляется к урл
*
* @return string
*/
public function getLoginUrl($redirectUrl, $state = ' ')
{
$this->redirectUrl = $redirectUrl;
$query = new QueryString();
$query->add('response_type', 'code');
$query->add('client_id', $this->clientId);
$query->add('redirect_uri', $redirectUrl);
$query->add('state', $state);
//$url = new Url('https','o2.mail.ru',null,null,null,'login',$query);
$url = new Url('https', 'oauth.yandex.ru', null, null, null, 'authorize', $query);
return $url->__toString();
}
示例5: getDescriptionUrl
/**
* Get description URL
*
* @return Url
*/
public function getDescriptionUrl()
{
if (is_null($this->descriptionUrl)) {
return Url::factory(SsdpInterface::DEFAULT_DESCRIPTION_URL);
}
return $this->descriptionUrl;
}
示例6: testParseCookie
/**
* @dataProvider cookieParserDataProvider
*/
public function testParseCookie($cookie, $parsed, $url = null)
{
$c = $this->cookieParserClass;
$parser = new $c();
$request = null;
if ($url) {
$url = Url::factory($url);
$host = $url->getHost();
$path = $url->getPath();
} else {
$host = '';
$path = '';
}
foreach ((array) $cookie as $c) {
$p = $parser->parseCookie($c, $host, $path);
// Remove expires values from the assertion if they are relatively equal by allowing a 5 minute difference
if ($p['expires'] != $parsed['expires']) {
if (abs($p['expires'] - $parsed['expires']) < 300) {
unset($p['expires']);
unset($parsed['expires']);
}
}
if (is_array($parsed)) {
foreach ($parsed as $key => $value) {
$this->assertEquals($parsed[$key], $p[$key], 'Comparing ' . $key . ' ' . var_export($value, true) . ' : ' . var_export($parsed, true) . ' | ' . var_export($p, true));
}
foreach ($p as $key => $value) {
$this->assertEquals($p[$key], $parsed[$key], 'Comparing ' . $key . ' ' . var_export($value, true) . ' : ' . var_export($parsed, true) . ' | ' . var_export($p, true));
}
} else {
$this->assertEquals($parsed, $p);
}
}
}
示例7: fromString
/**
* Create response from string
*
* @param string $string
*
* @return $this
*/
public static function fromString($string)
{
/** @var Discover $message */
$message = new static();
foreach (explode(PHP_EOL, trim($string)) as $line) {
$tuple = explode(':', trim($line), 2);
if (2 == count($tuple)) {
$value = trim(array_pop($tuple));
switch (strtoupper(array_pop($tuple))) {
case 'CACHE-CONTROL':
$message->setLifetime(intval(substr($value, strpos($value, '=') + 1)));
break;
case 'DATE':
$message->setDate(new DateTime($value));
break;
case 'LOCATION':
$message->setDescriptionUrl(Url::factory($value));
break;
case 'SERVER':
$message->setServerString($value);
break;
case 'ST':
$message->setSearchTarget(SearchTarget::fromString($value));
break;
case 'USN':
$message->setUniqueServiceName(UniqueServiceName::fromString($value));
break;
}
}
}
return $message;
}
示例8: testCreatesPresignedUrlsWithStrtotime
public function testCreatesPresignedUrlsWithStrtotime()
{
/** @var $client S3Client */
$client = $this->getServiceBuilder()->get('s3');
$url = Url::factory($client->createPresignedUrl($client->get('/foobar'), '10 minutes'));
$this->assertTrue(time() < $url->getQuery()->get('Expires'));
}
示例9: getUrl
/**
* Returns the URL of the metadata (key or block)
*
* @return string
* @param string $subresource not used; required for strict compatibility
* @throws ServerUrlerror
*/
public function getUrl($path = null, array $query = array())
{
if (!isset($this->url)) {
throw new Exceptions\ServerUrlError('Metadata has no URL (new object)');
}
return Url::factory($this->url)->addPath($this->key);
}
示例10: testEstimatingTemplateCostMarshalsDataCorrectly
public function testEstimatingTemplateCostMarshalsDataCorrectly()
{
self::log('Estimate a template\'s cost.');
$result = $this->client->estimateTemplateCost(array('TemplateBody' => file_get_contents(__DIR__ . '/template.json'), 'Parameters' => array(array('ParameterKey' => 'KeyName', 'ParameterValue' => 'keypair-name'))));
$url = Url::factory($result->get('Url'));
$this->assertEquals('calculator.s3.amazonaws.com', $url->getHost());
}
示例11: onOpen
/**
* {@inheritdoc}
* @throws \UnexpectedValueException If a controller is not \Ratchet\Http\HttpServerInterface
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
{
if (null === $request) {
throw new \UnexpectedValueException('$request can not be null');
}
$context = $this->_matcher->getContext();
$context->setMethod($request->getMethod());
$context->setHost($request->getHost());
try {
$route = $this->_matcher->match($request->getPath());
} catch (MethodNotAllowedException $nae) {
return $this->close($conn, 403);
} catch (ResourceNotFoundException $nfe) {
return $this->close($conn, 404);
}
if (is_string($route['_controller']) && class_exists($route['_controller'])) {
$route['_controller'] = new $route['_controller']();
}
if (!$route['_controller'] instanceof HttpServerInterface) {
throw new \UnexpectedValueException('All routes must implement Ratchet\\Http\\HttpServerInterface');
}
$parameters = array();
foreach ($route as $key => $value) {
if (is_string($key) && '_' !== substr($key, 0, 1)) {
$parameters[$key] = $value;
}
}
$url = Url::factory($request->getPath());
$url->setQuery($parameters);
$request->setUrl($url);
$conn->controller = $route['_controller'];
$conn->controller->onOpen($conn, $request);
}
示例12: createRedirectRequest
protected function createRedirectRequest(RequestInterface $request, $statusCode, $location, RequestInterface $original)
{
$redirectRequest = null;
$strict = $original->getParams()->get(self::STRICT_REDIRECTS);
if ($request instanceof EntityEnclosingRequestInterface && ($statusCode == 303 || !$strict && $statusCode <= 302)) {
$redirectRequest = RequestFactory::getInstance()->cloneRequestWithMethod($request, 'GET');
} else {
$redirectRequest = clone $request;
}
$redirectRequest->setIsRedirect(true);
$redirectRequest->setResponseBody($request->getResponseBody());
$location = Url::factory($location);
if (!$location->isAbsolute()) {
$originalUrl = $redirectRequest->getUrl(true);
$originalUrl->getQuery()->clear();
$location = $originalUrl->combine((string) $location, true);
}
$redirectRequest->setUrl($location);
$redirectRequest->getEventDispatcher()->addListener('request.before_send', $func = function ($e) use(&$func, $request, $redirectRequest) {
$redirectRequest->getEventDispatcher()->removeListener('request.before_send', $func);
$e['request']->getParams()->set(RedirectPlugin::PARENT_REQUEST, $request);
});
if ($redirectRequest instanceof EntityEnclosingRequestInterface && $redirectRequest->getBody()) {
$body = $redirectRequest->getBody();
if ($body->ftell() && !$body->rewind()) {
throw new CouldNotRewindStreamException('Unable to rewind the non-seekable entity body of the request after redirecting. cURL probably ' . 'sent part of body before the redirect occurred. Try adding acustom rewind function using on the ' . 'entity body of the request using setRewindFunction().');
}
}
return $redirectRequest;
}
示例13: testCreatesPutRequests
public function testCreatesPutRequests()
{
// Test using a string
$request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, 'Data');
$this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
$this->assertEquals('PUT', $request->getMethod());
$this->assertEquals('http', $request->getScheme());
$this->assertEquals('http://www.google.com/path?q=1&v=2', $request->getUrl());
$this->assertEquals('www.google.com', $request->getHost());
$this->assertEquals('/path', $request->getPath());
$this->assertEquals('/path?q=1&v=2', $request->getResource());
$this->assertInstanceOf('Guzzle\\Http\\EntityBody', $request->getBody());
$this->assertEquals('Data', (string) $request->getBody());
unset($request);
// Test using an EntityBody
$request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, EntityBody::factory('Data'));
$this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
$this->assertEquals('Data', (string) $request->getBody());
// Test using a resource
$resource = fopen('php://temp', 'w+');
fwrite($resource, 'Data');
$request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, $resource);
$this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
$this->assertEquals('Data', (string) $request->getBody());
// Test using an object that can be cast as a string
$request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, Url::factory('http://www.example.com/'));
$this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
$this->assertEquals('http://www.example.com/', (string) $request->getBody());
}
示例14: onOpen
/**
* {@inheritdoc}
*/
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
{
if (null === $request) {
throw new \UnexpectedValueException('$request can not be null');
}
$context = $this->_matcher->getContext();
$context->setMethod($request->getMethod());
$context->setHost($request->getHost());
try {
$parameters = $this->_matcher->match($request->getPath());
} catch (MethodNotAllowedException $nae) {
return $this->close($conn, 403);
} catch (ResourceNotFoundException $nfe) {
return $this->close($conn, 404);
}
if ($parameters['_controller'] instanceof ServingCapableInterface) {
$parameters['_controller']->serve($conn, $request, $parameters);
} else {
$query = array();
foreach ($query as $key => $value) {
if (is_string($key) && '_' !== substr($key, 0, 1)) {
$query[$key] = $value;
}
}
$url = Url::factory($request->getPath());
$url->setQuery($query);
$request->setUrl($url);
$conn->controller = $parameters['_controller'];
$conn->controller->onOpen($conn, $request);
}
}
示例15: __construct
/**
* @param string $baseUrl
* @param ConsumerCredentials $consumer
* @param TokenCredentials $tokenCredentials
*/
public function __construct($baseUrl, ConsumerCredentials $consumerCredentials, TokenCredentials $tokenCredentials = null)
{
// @todo check type of $baseUrl
$this->baseUrl = Url::factory($baseUrl);
$this->consumerCredentials = $consumerCredentials;
$this->tokenCredentials = $tokenCredentials;
}