コード例 #1
0
ファイル: RequestFactory.php プロジェクト: Ryu0621/SaNaVi
public function fromParts(
$method,
array $urlParts,
$headers = null,
$body = null,
$protocol = 'HTTP',
$protocolVersion = '1.1'
) {
return $this->create($method, Url::buildUrl($urlParts), $headers, $body)
->setProtocolVersion($protocolVersion);
}
コード例 #2
0
 /**
  * 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);
     foreach (array_merge($query, $parameters) as $key => $value) {
         $data[rawurlencode($key)] = rawurlencode($value);
     }
     ksort($data);
     array_walk($data, function (&$value, $key) {
         $value = $key . '=' . $value;
     });
     $baseString .= rawurlencode(implode('&', $data));
     return $baseString;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 public function build()
 {
     // Resolve configuration
     $config = Collection::fromConfig($this->config, array_merge(self::$commonConfigDefaults, $this->configDefaults), $this->configRequirements);
     // Make sure base_url is correctly set
     if (!($baseUrl = $config->get(Options::BASE_URL))) {
         throw new InvalidArgumentException('You must provide the endpoint for the CloudSearch domain.');
     } elseif (strpos($baseUrl, 'http') !== 0) {
         $config->set(Options::BASE_URL, Url::buildUrl(array('scheme' => $config->get(Options::SCHEME), 'host' => $baseUrl)));
     }
     // Determine the region from the endpoint
     $endpoint = Url::factory($config->get(Options::BASE_URL));
     list(, $region) = explode('.', $endpoint->getHost());
     $config[Options::REGION] = $config[Options::SIGNATURE_REGION] = $region;
     // Create dependencies
     $exceptionParser = new JsonQueryExceptionParser();
     $description = ServiceDescription::factory(sprintf($config->get(Options::SERVICE_DESCRIPTION), $config->get(Options::VERSION)));
     $signature = $this->getSignature($description, $config);
     $credentials = $this->getCredentials($config);
     // Resolve backoff strategy
     $backoff = $config->get(Options::BACKOFF);
     if ($backoff === null) {
         $backoff = new BackoffPlugin(new TruncatedBackoffStrategy(3, new ThrottlingErrorChecker($exceptionParser, new CurlBackoffStrategy(null, new HttpBackoffStrategy(array(500, 503, 509), new ExponentialBackoffStrategy())))));
         $config->set(Options::BACKOFF, $backoff);
     }
     if ($backoff) {
         $this->addBackoffLogger($backoff, $config);
     }
     // Create client
     $client = new CloudSearchDomainClient($credentials, $signature, $config);
     $client->setDescription($description);
     // Add exception marshaling so that more descriptive exception are thrown
     $client->addSubscriber(new ExceptionListener(new NamespaceExceptionFactory($exceptionParser, __NAMESPACE__ . '\\Exception', __NAMESPACE__ . '\\Exception\\CloudSearchDomainException')));
     // Add the UserAgentPlugin to append to the User-Agent header of requests
     $client->addSubscriber(new UserAgentListener());
     // Filters used for the cache plugin
     $client->getConfig()->set('params.cache.key_filter', 'header=date,x-amz-date,x-amz-security-token,x-amzn-authorization');
     // Disable parameter validation if needed
     if ($config->get(Options::VALIDATION) === false) {
         $params = $config->get('command.params') ?: array();
         $params['command.disable_validation'] = true;
         $config->set('command.params', $params);
     }
     return $client;
 }
コード例 #5
0
ファイル: UrlTest.php プロジェクト: mickdane/zidisha
 public function testAddsQueryStringIfPresent()
 {
     $this->assertEquals('?foo=bar', Url::buildUrl(array('query' => 'foo=bar')));
 }
コード例 #6
0
 /**
  * @dataProvider urlProvider
  */
 public function testBuildsUrlsFromParts($url, $parts)
 {
     $this->assertEquals($url, Url::buildUrl($parts));
 }
コード例 #7
0
ファイル: Queue.php プロジェクト: enoch85/owncloud-testserver
 /**
  * Post multiple messages.
  *
  * @param array $messages
  * @return bool
  */
 public function createMessages(array $messages)
 {
     $objects = array();
     foreach ($messages as $dataArray) {
         $objects[] = $this->getMessage($dataArray)->createJson();
     }
     $json = json_encode(array_slice($objects, 0, self::MAX_POST_MESSAGES));
     $this->checkJsonError();
     $response = $this->getClient()->post($this->getUrl('messages'), self::getJsonHeader(), $json)->send();
     if (null !== ($location = $response->getHeader('Location'))) {
         $parts = array_merge($this->getUrl()->getParts(), parse_url($location));
         $url = Url::factory(Url::buildUrl($parts));
         $options = $this->makeResourceIteratorOptions(__NAMESPACE__ . '\\Message') + array('baseUrl' => $url, 'limit.page' => 10);
         return PaginatedIterator::factory($this, $options);
     }
     return true;
 }
コード例 #8
0
ファイル: SOAPTransport.php プロジェクト: Maksold/platform
 /**
  * @param string $wsdlUrl
  *
  * @param array $options
  * @return \SoapClient
  */
 protected function getSoapClient($wsdlUrl, array $options = [])
 {
     $options['trace'] = true;
     $urlParts = parse_url($wsdlUrl);
     if (isset($urlParts['user'], $urlParts['pass'])) {
         $options['login'] = $urlParts['user'];
         $options['password'] = $urlParts['pass'];
         unset($urlParts['user'], $urlParts['pass']);
     }
     $wsdlUrl = Url::buildUrl($urlParts);
     return new \SoapClient($wsdlUrl, $options);
 }
コード例 #9
0
ファイル: Queue.php プロジェクト: huhugon/sso
 /**
  * Post multiple messages.
  *
  * @param array $messages
  * @return bool
  */
 public function createMessages(array $messages)
 {
     $objects = array();
     foreach ($messages as $dataArray) {
         $objects[] = $this->getMessage($dataArray)->createJson();
     }
     $json = json_encode(array_slice($objects, 0, self::MAX_POST_MESSAGES));
     $this->checkJsonError();
     $response = $this->getClient()->post($this->getUrl('messages'), array(), $json)->send();
     if (null !== ($location = $response->getHeader('Location'))) {
         $parts = array_merge($this->getUrl()->getParts(), parse_url($location));
         $url = Url::buildUrl($parts);
         return $this->getService()->resourceList('Message', $url, $this);
     }
     return true;
 }
コード例 #10
0
 /**
  * Creates a new object
  *
  * @param array $params array of values to set when creating the object
  * @return HttpResponse
  * @throws VolumeCreateError if HTTP status is not Success
  */
 public function create($params = array())
 {
     // set parameters
     if (!empty($params)) {
         $this->populate($params, false);
     }
     // construct the JSON
     $json = json_encode($this->createJson());
     $this->checkJsonError();
     $createUrl = $this->createUrl();
     $response = $this->getClient()->post($createUrl, array(), $json)->setExceptionHandler(array(201 => array('allow' => true, 'callback' => function ($response) use($createUrl) {
         if ($location = $response->getHeader('Location')) {
             $parts = array_merge($createUrl->getParts(), parse_url($location));
             var_dump(Url::buildUrl($parts));
             die;
             $this->refresh(null, Url::buildUrl($parts));
         }
     }), 204 => array('message' => sprintf('Error creating [%s] [%s]', get_class($this), $this->getProperty($this->primaryKeyField())))))->send();
     // We have to try to parse the response body first because it should have precedence over a Location refresh.
     // I'd like to reverse the order, but Nova instances return ephemeral properties on creation which are not
     // available when you follow the Location link...
     if (null !== ($decoded = $this->parseResponse($response))) {
         $this->populate($decoded);
     } elseif ($location = $response->getHeader('Location')) {
         $this->refreshFromLocationUrl($location);
     }
     return $response;
 }
コード例 #11
0
 /**
  * @covers Guzzle\Http\Url::setPath
  * @covers Guzzle\Http\Url::getPath
  * @covers Guzzle\Http\Url::getPathSegments
  * @covers Guzzle\Http\Url::buildUrl
  */
 public function testHandlesPathsCorrectly()
 {
     $url = Url::factory('http://www.test.com');
     $this->assertEquals('/', $url->getPath());
     $url->setPath('test');
     $this->assertEquals('/test', $url->getPath());
     $url->setPath('/test/123/abc');
     $this->assertEquals(array('test', '123', 'abc'), $url->getPathSegments());
     $parts = parse_url('http://www.test.com/test');
     $parts['path'] = '';
     $this->assertEquals('http://www.test.com/', Url::buildUrl($parts));
     $parts['path'] = 'test';
     $this->assertEquals('http://www.test.com/test', Url::buildUrl($parts));
 }