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


PHP Collection::add方法代码示例

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

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

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

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

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

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

示例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;
 }
开发者ID:vdmi,项目名称:guzzle-oauth,代码行数:22,代码来源:OauthPlugin.php

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

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

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

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

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

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

示例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;
     }
 }
开发者ID:diandianxiyu,项目名称:Yii2Api,代码行数:21,代码来源:AbstractMessage.php

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


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