当前位置: 首页>>代码示例>>PHP>>正文


PHP Common\Collection类代码示例

本文整理汇总了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;
 }
开发者ID:MicroSDHC,项目名称:justinribeiro.com-examples,代码行数:43,代码来源:Response.php

示例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();
 }
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:33,代码来源:AbstractClient.php

示例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;
 }
开发者ID:NavalKishor,项目名称:PHP-Rocker,代码行数:12,代码来源:Client.php

示例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;
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:11,代码来源:Activity.php

示例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));
 }
开发者ID:noahkim,项目名称:kowop,代码行数:16,代码来源:CredentialsOptionResolver.php

示例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);
 }
开发者ID:ja1cap,项目名称:GoogleTranslateBundle,代码行数:10,代码来源:Translator.php

示例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()));
 }
开发者ID:risyasin,项目名称:webpagetest,代码行数:19,代码来源:ItemIterator.php

示例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;
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:15,代码来源:ReferencingApplicationFindResults.php

示例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());
 }
开发者ID:MicroSDHC,项目名称:justinribeiro.com-examples,代码行数:20,代码来源:Cookie.php

示例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;
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:23,代码来源:Inspector.php

示例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);
     }
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:17,代码来源:Note.php

示例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'));
 }
开发者ID:noahkim,项目名称:kowop,代码行数:14,代码来源:AbstractClientTest.php

示例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'));
     }
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:17,代码来源:ReportNotification.php

示例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'));
     }
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:17,代码来源:User.php

示例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);
     }
 }
开发者ID:cultuurnet,项目名称:search,代码行数:19,代码来源:Collector.php


注:本文中的Guzzle\Common\Collection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。