Пример #1
0
 /**
  * Prepare command before execution
  */
 protected function build()
 {
     if (!$this->action) {
         // @codeCoverageIgnoreStart
         throw new \Exception('You must define an action name');
         // @codeCoverageIgnoreEnd
     }
     if (!$this->request) {
         $this->request = $this->client->createRequest($this->requestMethod);
     }
     $this->request->getQuery()->set('Action', $this->action)->set('Version', $this->version);
     // Set cURL options
     $this->request->getCurlOptions()->set(CURLOPT_SSL_VERIFYHOST, 0)->set(CURLOPT_SSL_VERIFYPEER, 0)->set(CURLOPT_FORBID_REUSE, 1)->set(CURLOPT_TIMEOUT, 600);
     // Set authorization fields
     $config = $this->getClient()->getConfig();
     $this->request->getQuery()->set('AWSAccessKeyId', $config['access_key'])->set('Marketplace', $config['marketplace_id'])->set('Merchant', $config['merchant_id']);
     // Add any additional method params
     foreach ($this->data as $param => $value) {
         if ($param == 'headers') {
             continue;
         }
         $param = ucfirst(Inflector::camel($param));
         if (is_array($value)) {
             // It's an array, convert to amazon array naming convention
             foreach ($value as $listName => $listValues) {
                 foreach ($listValues as $i => $listValue) {
                     $this->request->getQuery()->set($param . '.' . $listName . '.' . ($i + 1), $listValue);
                 }
             }
             $this->request->getQuery()->remove($param);
         } else {
             if ($value instanceof \DateTime) {
                 // It's a date, format as ISO 8601 string
                 $this->request->getQuery()->set($param, $value->format('c'));
             } else {
                 if (is_bool($value)) {
                     // It's a bool, convert to string
                     $this->request->getQuery()->set($param, $value ? 'true' : 'false');
                 } else {
                     // It's a scalar
                     $this->request->getQuery()->set($param, $value);
                 }
             }
         }
     }
 }