本文整理汇总了PHP中Guzzle\Common\Collection::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::add方法的具体用法?PHP Collection::add怎么用?PHP Collection::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Common\Collection
的用法示例。
在下文中一共展示了Collection::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromMessage
/**
* Create a new Response based on a raw response message
*
* @param string $message Response message
*
* @return Response
* @throws InvalidArgumentException if an empty $message is provided
*/
public static function fromMessage($message)
{
if (!$message) {
throw new InvalidArgumentException('No response message provided');
}
// Normalize line endings
$message = preg_replace("/([^\r])(\n)\\b/", "\$1\r\n", $message);
$protocol = $code = $status = '';
$parts = explode("\r\n\r\n", $message, 2);
$headers = new Collection();
foreach (array_values(array_filter(explode("\r\n", $parts[0]))) as $i => $line) {
// Remove newlines from headers
$line = implode(' ', explode("\n", $line));
if ($i === 0) {
// Check the status line
list($protocol, $code, $status) = array_map('trim', explode(' ', $line, 3));
} else {
if (strpos($line, ':')) {
// Add a header
list($key, $value) = array_map('trim', explode(':', $line, 2));
// Headers are case insensitive
$headers->add($key, $value);
}
}
}
$body = null;
if (isset($parts[1]) && $parts[1] != "\n") {
$body = EntityBody::factory(trim($parts[1]));
// Always set the appropriate Content-Length if Content-Legnth
$headers['Content-Length'] = $body->getSize();
}
$response = new static(trim($code), $headers, $body);
$response->setProtocol($protocol)->setStatus($code, $status);
return $response;
}
示例2: fromCommand
/**
* {@inheritdoc}
*/
public static function fromCommand(OperationCommand $command)
{
$activities = new Collection();
foreach ($command->getResponse()->json() as $key => $activity) {
$activities->add($key, self::hydrateModelProperties(new self(), $activity));
}
return $activities;
}
示例3: testCanGetAllValuesByArray
/**
* @covers Guzzle\Common\Collection::getAll
*/
public function testCanGetAllValuesByArray()
{
$this->coll->add('foo', 'bar');
$this->coll->add('tEsT', 'value');
$this->coll->add('tesTing', 'v2');
$this->coll->add('key', 'v3');
$this->assertNull($this->coll->get('test'));
$this->assertEquals(array('foo' => 'bar', 'tEsT' => 'value', 'tesTing' => 'v2'), $this->coll->getAll(array('foo', 'tesTing', 'tEsT')));
}
示例4: __construct
public function __construct($apiKey, ParametersEscaper $parametersEscaper, $environment)
{
$this->apiKey = $apiKey;
$this->parametersEscaper = $parametersEscaper;
$this->environment = $environment;
$headers = new Collection();
$headers->add('X-HTTP-Method-Override', 'GET');
$this->client = new Client();
$this->client->setDefaultHeaders($headers);
}
示例5: fromCommand
/**
* {@inheritdoc}
*/
public static function fromCommand(OperationCommand $command)
{
$data = $command->getResponse()->json();
$records = new Collection();
if (isset($data['records']) && is_array($data['records'])) {
foreach ($data['records'] as $key => $object) {
$records->add($key, self::hydrateModelProperties(new ReferencingApplicationFindResult(), $object, array('applicationUuid' => 'referencingApplicationUuId')));
}
}
$instance = self::hydrateModelProperties(new self(), $data, array(), array('records' => $records));
return $instance;
}
示例6: factory
/**
* Create a Cookie by parsing a Cookie HTTP header
*
* @param string $cookieString Cookie HTTP header
*
* @return Cookie
*/
public static function factory($cookieString)
{
$data = new Collection();
if ($cookieString) {
foreach (explode(';', $cookieString) as $kvp) {
$parts = explode('=', $kvp, 2);
$key = urldecode(trim($parts[0]));
$value = isset($parts[1]) ? trim($parts[1]) : '';
$data->add($key, urldecode($value));
}
}
return new static($data->getAll());
}
示例7: 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;
}
示例8: fromCommand
/**
* {@inheritdoc}
*/
public static function fromCommand(OperationCommand $command)
{
$data = $command->getResponse()->json();
// Collection of notifications
if (self::isResponseDataIndexedArray($data)) {
$notifications = new Collection();
foreach ($data as $key => $documentData) {
$notifications->add($key, self::hydrateModelProperties(new self(), $documentData, array('applicationId' => 'referencingApplicationUuId')));
}
return $notifications;
} else {
return self::hydrateModelProperties(new self(), $data, array('applicationId' => 'referencingApplicationUuId'));
}
}
示例9: fromCommand
/**
* {@inheritdoc}
*/
public static function fromCommand(OperationCommand $command)
{
$data = $command->getResponse()->json();
// Collection of notes
if (self::isResponseDataIndexedArray($data)) {
$notes = new Collection();
foreach ($data as $key => $noteData) {
$notes->add($key, self::hydrateModelProperties(new self(), $noteData));
}
return $notes;
} else {
return self::hydrateModelProperties(new self(), $data);
}
}
示例10: fromCommand
/**
* {@inheritdoc}
*/
public static function fromCommand(OperationCommand $command)
{
$data = $command->getResponse()->json();
// Indexed array of agent users
if (self::isResponseDataIndexedArray($data)) {
$users = new Collection();
foreach ($data as $key => $userData) {
$users->add($key, self::hydrateModelProperties(new self(), $userData, array('agentUserId' => 'agentUserUuId', 'fullName' => 'name')));
}
return $users;
} else {
return self::hydrateModelProperties(new self(), $data, array('agentUserId' => 'agentUserUuId', 'fullName' => 'name'));
}
}
示例11: addParameters
/**
* @param Parameter[] $parameters
* @param Collection $collection
*/
public function addParameters(array $parameters, Collection $collection)
{
foreach ($parameters as $parameter) {
$value = '';
$localParams = $parameter->getLocalParams();
if (!empty($localParams)) {
if (!isset($localParameterSerializer)) {
$localParameterSerializer = new LocalParameterSerializer();
}
$value = $localParameterSerializer->serialize($localParams);
}
$value .= $parameter->getValue();
$collection->add($parameter->getKey(), $value);
}
}
示例12: fromCommand
/**
* {@inheritdoc}
*/
public static function fromCommand(OperationCommand $command)
{
// If there is no content then assume an empty collection
if (204 == $command->getResponse()->getStatusCode()) {
return new Collection();
}
$data = $command->getResponse()->json();
// Collection of products
if (self::isResponseDataIndexedArray($data)) {
$products = new Collection();
foreach ($data as $key => $productData) {
$products->add($key, self::hydrateModelProperties(new self(), $productData, array('productId' => 'id')));
}
return $products;
} else {
return self::hydrateModelProperties(new self(), $data, array('productId' => 'id'));
}
}
示例13: fromCommand
/**
* {@inheritdoc}
*/
public static function fromCommand(OperationCommand $command)
{
$data = $command->getResponse()->json();
// Indexed array of branches
if (self::isResponseDataIndexedArray($data)) {
$branches = new Collection();
foreach ($data as $key => $branchData) {
$branches->add($key, self::hydrateModelProperties(new self(), $branchData, array('agentBranchId' => 'agentBranchUuId')));
}
return $branches;
} else {
$address = self::hydrateModelProperties(new Address(), $data['address']);
$correspondenceAddress = self::hydrateModelProperties(new Address(), $data['correspondenceAddress']);
$brandAddress = self::hydrateModelProperties(new Address(), $data['agentBrand']['address']);
$brand = self::hydrateModelProperties(new Brand(), $data['agentBrand'], array(), array('address' => $brandAddress));
return self::hydrateModelProperties(new self(), $data, array(), array('address' => $address, 'correspondenceAddress' => $correspondenceAddress, 'agentBrand' => $brand));
}
}
示例14: getTokenizedHeader
/**
* @deprecated Use $message->getHeader()->parseParams()
* @codeCoverageIgnore
*/
public function getTokenizedHeader($header, $token = ';')
{
Version::warn(__METHOD__ . ' is deprecated. Use $message->getHeader()->parseParams()');
if ($this->hasHeader($header)) {
$data = new Collection();
foreach ($this->getHeader($header)->parseParams() as $values) {
foreach ($values as $key => $value) {
if ($value === '') {
$data->set($data->count(), $key);
} else {
$data->add($key, $value);
}
}
}
return $data;
}
}
示例15: parseMessage
/**
* {@inheritdoc}
*/
public function parseMessage($message)
{
if (!$message) {
return false;
}
$headers = new Collection();
$scheme = $host = $body = $method = $user = $pass = $query = $port = $version = $protocol = '';
$path = '/';
// Inspired by https://github.com/kriswallsmith/Buzz/blob/message-interfaces/lib/Buzz/Message/Parser/Parser.php#L16
$lines = preg_split('/(\\r?\\n)/', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($i = 0, $c = count($lines); $i < $c; $i += 2) {
$line = $lines[$i];
// If two line breaks were encountered, then this is the body
if (empty($line)) {
$body = implode('', array_slice($lines, $i + 2));
break;
}
// Parse message headers
if (!$method) {
list($method, $path, $proto) = explode(' ', $line);
$method = strtoupper($method);
list($protocol, $version) = explode('/', strtoupper($proto));
$scheme = 'http';
} else {
if (strpos($line, ':')) {
list($key, $value) = explode(':', $line, 2);
$key = trim($key);
// Normalize standard HTTP headers
if (in_array(strtolower($key), static::$requestHeaders)) {
$key = str_replace(' ', '-', ucwords(str_replace('-', ' ', $key)));
}
// Headers are case insensitive
$headers->add($key, trim($value));
}
}
}
// Check for the Host header
if (isset($headers['Host'])) {
$host = $headers['Host'];
}
if (strpos($host, ':')) {
list($host, $port) = array_map('trim', explode(':', $host));
if ($port == 443) {
$scheme = 'https';
}
} else {
$port = '';
}
// Check for basic authorization
$auth = isset($headers['Authorization']) ? $headers['Authorization'] : '';
if ($auth) {
list($type, $data) = explode(' ', $auth);
if (strtolower($type) == 'basic') {
$data = base64_decode($data);
list($user, $pass) = explode(':', $data);
}
}
// Check if a query is present
$qpos = strpos($path, '?');
if ($qpos) {
$query = substr($path, $qpos);
$path = substr($path, 0, $qpos);
}
return array('method' => $method, 'protocol' => $protocol, 'protocol_version' => $version, 'parts' => array('scheme' => $scheme, 'host' => $host, 'port' => $port, 'user' => $user, 'pass' => $pass, 'path' => $path, 'query' => $query), 'headers' => $headers->getAll(), 'body' => $body);
}