作者:jdecoste
项目:SlackBundl
/**
* @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;
}
作者:risyasi
项目:webpagetes
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();
}
}
作者:romainneutro
项目:aws-sdk-ph
/**
* 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];
}
作者:cna
项目:yandex_metric
/**
* Запрос На авторизацию
*
* @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();
}
作者:T-REX-X
项目:SSDPFinde
/**
* Get description URL
*
* @return Url
*/
public function getDescriptionUrl()
{
if (is_null($this->descriptionUrl)) {
return Url::factory(SsdpInterface::DEFAULT_DESCRIPTION_URL);
}
return $this->descriptionUrl;
}
作者:bryon-czoc
项目:eBay-CL
/**
* @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);
}
}
}
作者:T-REX-X
项目:SSDPFinde
/**
* 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;
}
作者:cstude
项目:nagios-plugin
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'));
}
作者:huhugo
项目:ss
/**
* 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);
}
作者:cstude
项目:nagios-plugin
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());
}
作者:ige
项目:gaiaeh
/**
* {@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);
}
作者:Ryu062
项目:SaNaV
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;
}
作者:mickdan
项目:zidish
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());
}
作者:owlycod
项目:reactboar
/**
* {@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);
}
}
作者:cultuurne
项目:aut
/**
* @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;
}
作者:dangermar
项目:chameleonlab
/**
* Factory method that instantiates an object from a Response object.
*
* @param Response $response
* @param ServiceInterface $service
* @return static
*/
public static function fromResponse(Response $response, ServiceInterface $service)
{
$self = parent::fromResponse($response, $service);
$segments = Url::factory($response->getEffectiveUrl())->getPathSegments();
$self->name = end($segments);
return $self;
}
作者:nlegof
项目:Phraseane
private function generateUrl($pathfile, array $entry)
{
$path = substr($pathfile, strlen($entry['directory']));
$hexTime = dechex(time() + 3600);
$token = md5($entry['passphrase'] . $path . $hexTime);
return Url::factory($entry['mount-point'] . '/' . $token . "/" . $hexTime . $path);
}
作者:nuxe
项目:nuxeo-automation-php-clien
/**
* @param string $url
* @param string $username
* @param string $password
* @throws NuxeoClientException
*/
public function __construct($url = 'http://localhost:8080/nuxeo', $username = 'Administrator', $password = 'Administrator') {
try {
$this->baseUrl = Url::factory($url);
$this->httpClient = new Client($url, array(
Client::REQUEST_OPTIONS => array(
'headers' => array(
'Content-Type' => 'application/json+nxrequest'
)
)
));
} catch(GuzzleException $ex) {
throw NuxeoClientException::fromPrevious($ex);
}
$this->httpClient->setRequestFactory(new RequestFactory());
$self = $this;
/**
* @param RequestInterface $request
*/
$this->interceptors[] = function($request) use ($self, $username, $password) {
try {
$request->setAuth($username, $password);
} catch(GuzzleException $ex) {
throw NuxeoClientException::fromPrevious($ex);
}
};
}
作者:Ryu062
项目:SaNaV
public function getStringToSign(RequestInterface $request, $timestamp, $nonce)
{
$params = $this->getParamsToSign($request, $timestamp, $nonce);
$params = $this->prepareParameters($params);
$parameterString = new QueryString($params);
$url = Url::factory($request->getUrl())->setQuery('')->setFragment(null);
return strtoupper($request->getMethod()) . '&' . rawurlencode($url) . '&' . rawurlencode((string) $parameterString);
}
作者:jtsternber
项目:oauth1-clien
/**
* 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(Url $url, $method = 'POST', array $parameters = array())
{
$baseString = rawurlencode($method) . '&';
$schemeHostPath = Url::buildUrl(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;
}