本文整理汇总了PHP中Guzzle\Common\Collection::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::merge方法的具体用法?PHP Collection::merge怎么用?PHP Collection::merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Common\Collection
的用法示例。
在下文中一共展示了Collection::merge方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGuzzleClient
/**
* @param type $baseUrl
* @param type $config
* @return \Guzzle\Http\Client
*/
public function getGuzzleClient($baseUrl = '', $config = null)
{
if (!is_null($config)) {
$this->config->merge($config);
}
return new Client($baseUrl, $this->config);
}
示例2: testImplementsArrayAccess
public function testImplementsArrayAccess()
{
$this->coll->merge(array('k1' => 'v1', 'k2' => 'v2'));
$this->assertTrue($this->coll->offsetExists('k1'));
$this->assertFalse($this->coll->offsetExists('Krull'));
$this->coll->offsetSet('k3', 'v3');
$this->assertEquals('v3', $this->coll->offsetGet('k3'));
$this->assertEquals('v3', $this->coll->get('k3'));
$this->coll->offsetUnset('k1');
$this->assertFalse($this->coll->offsetExists('k1'));
}
示例3: onRequestRetry
/**
* Called when a request is being retried
*
* @param Event $event Event emitted
*/
public function onRequestRetry(Event $event)
{
$request = $event['request'];
$response = $event['response'];
$handle = $event['handle'];
$data = new Collection(array('ts' => gmdate('c'), 'method' => $request->getMethod(), 'url' => $request->getUrl(), 'retries' => $event['retries'], 'delay' => $event['delay']));
if ($response) {
$data->merge(array('code' => $response->getStatusCode(), 'phrase' => $response->getReasonPhrase(), 'connect_time' => $response->getInfo('connect_time'), 'total_time' => $response->getInfo('total_time')));
} elseif ($handle) {
$data->merge(array('connect_time' => $handle->getInfo(CURLINFO_CONNECT_TIME), 'total_time' => $handle->getInfo(CURLINFO_TOTAL_TIME)));
}
if ($handle) {
$data->set('curl_error', $handle->getError());
$data->set('curl_code', $handle->getErrorNo());
}
// Add request headers to the possible template values
foreach ($request->getHeaders(true) as $header => $value) {
$data->set("header_{$header}", (string) $value);
}
$this->logger->log($data->inject($this->template), LOG_INFO, $data);
}
示例4: getParamsToSign
public function getParamsToSign(RequestInterface $request, $timestamp, $nonce)
{
$params = new Collection(array('oauth_consumer_key' => $this->config['consumer_key'], 'oauth_nonce' => $nonce, 'oauth_signature_method' => $this->config['signature_method'], 'oauth_timestamp' => $timestamp, 'oauth_version' => $this->config['version']));
// Filter out oauth_token during temp token step, as in request_token.
if ($this->config['token'] !== false) {
$params->add('oauth_token', $this->config['token']);
}
// Add call back uri
if (isset($this->config['callback_uri']) && !empty($this->config['callback_uri'])) {
$params->add('oauth_callback', $this->config['callback_uri']);
}
// Add query string parameters
$params->merge($request->getQuery());
// Add POST fields to signing string
if (!$this->config->get('disable_post_params') && $request instanceof EntityEnclosingRequestInterface && false !== strpos($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded')) {
$params->merge($request->getPostFields());
}
// Sort params
$params = $params->getAll();
ksort($params);
return $params;
}
示例5: getParamsToSign
/**
* Parameters sorted and filtered in order to properly sign a request
*
* @param RequestInterface $request Request to generate a signature for
* @param integer $timestamp Timestamp to use for nonce
* @param string $nonce
*
* @return array
*/
public function getParamsToSign(RequestInterface $request, $timestamp, $nonce)
{
$params = new Collection(array('oauth_consumer_key' => $this->config['consumer_key'], 'oauth_nonce' => $nonce, 'oauth_signature_method' => $this->config['signature_method'], 'oauth_timestamp' => $timestamp, 'oauth_token' => $this->config['token'], 'oauth_version' => $this->config['version']));
if (array_key_exists('callback', $this->config) == true) {
$params['oauth_callback'] = $this->config['callback'];
}
if (array_key_exists('verifier', $this->config) == true) {
$params['oauth_verifier'] = $this->config['verifier'];
}
// Add query string parameters
$params->merge($request->getQuery());
// Add POST fields to signing string if required
if ($this->shouldPostFieldsBeSigned($request)) {
$params->merge($request->getPostFields());
}
// Sort params
$params = $params->toArray();
ksort($params);
return $params;
}
示例6: getStringToSign
/**
* Calculate string to sign
*
* @param RequestInterface $request Request to generate a signature for
* @param int $timestamp Timestamp to use for nonce
*
* @return string
*/
public function getStringToSign(RequestInterface $request, $timestamp)
{
$params = new Collection(array('oauth_consumer_key' => $this->config['consumer_key'], 'oauth_nonce' => $this->generateNonce($request, $timestamp), 'oauth_signature_method' => $this->config['signature_method'], 'oauth_timestamp' => $timestamp, 'oauth_token' => $this->config['token'], 'oauth_version' => $this->config['version']));
// Add query string parameters
$params->merge($request->getQuery());
// Add POST fields to signing string
if ($request instanceof EntityEnclosingRequestInterface && $request->getHeader('Content-Type') == 'application/x-www-form-urlencoded') {
$params->merge($request->getPostFields());
}
// Sort params
$params = $params->getAll();
ksort($params);
// Build signing string from combined params
$parameterString = array();
foreach ($params as $key => $values) {
$key = rawurlencode($key);
$values = (array) $values;
sort($values);
foreach ($values as $value) {
if (is_bool($value)) {
$value = $value ? 'true' : 'false';
}
$parameterString[] = $key . '=' . rawurlencode($value);
}
}
$url = Url::factory($request->getUrl())->setQuery('')->setFragment('');
return strtoupper($request->getMethod()) . '&' . rawurlencode($url) . '&' . rawurlencode(implode('&', $parameterString));
}