本文整理汇总了PHP中Guzzle\Common\Collection类的典型用法代码示例。如果您正苦于以下问题:PHP Collection类的具体用法?PHP Collection怎么用?PHP Collection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collection类的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: __construct
/**
* @param CredentialsInterface $credentials AWS credentials
* @param SignatureInterface $signature Signature implementation
* @param Collection $config Configuration options
*
* @throws InvalidArgumentException if an endpoint provider isn't provided
*/
public function __construct(CredentialsInterface $credentials, SignatureInterface $signature, Collection $config)
{
// Use the system's CACert if running as a phar
if (defined('AWS_PHAR')) {
$config->set(self::SSL_CERT_AUTHORITY, 'system');
}
// Bootstrap with Guzzle
parent::__construct($config->get(Options::BASE_URL), $config);
$this->credentials = $credentials;
$this->signature = $signature;
$this->endpointProvider = $config->get(Options::ENDPOINT_PROVIDER);
// Make sure an endpoint provider was provided in the config
if (!$this->endpointProvider instanceof EndpointProviderInterface) {
throw new InvalidArgumentException('An endpoint provider must be provided to instantiate an AWS client');
}
// Make sure the user agent is prefixed by the SDK version
$this->setUserAgent('aws-sdk-php2/' . Aws::VERSION, true);
// Set the service description on the client
$this->addServiceDescriptionFromConfig();
// Add the event listener so that requests are signed before they are sent
$this->getEventDispatcher()->addSubscriber(new SignatureListener($credentials, $signature));
// Resolve any config options on the client that require a client to be instantiated
$this->resolveOptions();
// Add a resource iterator factory that uses the Iterator directory
$this->addDefaultResourceIterator();
}
示例3: headerCollectionToArray
/**
* @param Collection $headers
* @return array
*/
private function headerCollectionToArray(Collection $headers)
{
$headers_arr = array();
foreach ($headers->toArray() as $name => $val) {
$headers_arr[$name] = current($val);
}
return $headers_arr;
}
示例4: 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;
}
示例5: defaultMissingFunction
/**
* Default method to execute when credentials are not specified
*
* @param Collection $config Config options
*
* @return CredentialsInterface
*/
protected function defaultMissingFunction(Collection $config)
{
if ($config->get(Options::KEY) && $config->get(Options::SECRET)) {
// Credentials were not provided, so create them using keys
return Credentials::factory($config->getAll());
}
// Attempt to get credentials from the EC2 instance profile server
return new RefreshableInstanceProfileCredentials(new Credentials('', '', '', 1));
}
示例6: __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);
}
示例7: fromResult
/**
* Collects items from the result of a DynamoDB operation and returns them as an ItemIterator.
*
* @param Collection $result The result of a DynamoDB operation that potentially contains items
* (e.g., BatchGetItem, DeleteItem, GetItem, PutItem, Query, Scan, UpdateItem)
*
* @return self
*/
public static function fromResult(Collection $result)
{
if (!($items = $result->get('Items'))) {
if ($item = $result->get('Item') ?: $result->get('Attributes')) {
$items = array($item);
} else {
$items = $result->getPath('Responses/*');
}
}
return new self(new \ArrayIterator($items ?: array()));
}
示例8: 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;
}
示例9: 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());
}
示例10: prepareConfig
/**
* Validate and prepare configuration parameters
*
* @param array $config Configuration values to apply.
* @param array $defaults Default parameters
* @param array $required Required parameter names
*
* @return Collection
* @throws InvalidArgumentException if a parameter is missing
*/
public static function prepareConfig(array $config = null, array $defaults = null, array $required = null)
{
$collection = new Collection($defaults);
foreach ((array) $config as $key => $value) {
$collection->set($key, $value);
}
foreach ((array) $required as $key) {
if ($collection->hasKey($key) === false) {
throw new ValidationException("Config must contain a '{$key}' key");
}
}
return $collection;
}
示例11: 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);
}
}
示例12: testConstructorCallsResolvers
public function testConstructorCallsResolvers()
{
$config = new Collection(array(Options::ENDPOINT_PROVIDER => $this->getMock('Aws\\Common\\Region\\EndpointProviderInterface')));
$signature = new SignatureV4();
$credentials = new Credentials('test', '123');
$config->set('client.resolvers', array(new BackoffOptionResolver(function () {
return BackoffPlugin::getExponentialBackoff();
})));
$client = $this->getMockBuilder('Aws\\Common\\Client\\AbstractClient')->setConstructorArgs(array($credentials, $signature, $config))->getMockForAbstractClass();
// Ensure that lazy resolvers were triggered
$this->assertInstanceOf('Guzzle\\Plugin\\Backoff\\BackoffPlugin', $client->getConfig(Options::BACKOFF));
// Ensure that the client removed the option
$this->assertNull($config->get('client.resolvers'));
}
示例13: 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'));
}
}
示例14: 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'));
}
}
示例15: 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);
}
}