Пример #1
0
 public function setMd5(PreparedEvent $event)
 {
     $client = $event->getClient();
     $command = $event->getCommand();
     $body = $event->getRequest()->getBody();
     // If ContentMD5 is set or there is no body, there is nothing to do.
     if ($command['ContentMD5'] || !$body) {
         return;
     }
     // If and MD5 is required or enabled, add one.
     $optional = $client->getConfig('calculate_md5') && in_array($command->getName(), self::$canMd5);
     if (in_array($command->getName(), self::$requireMd5) || $optional) {
         // Throw exception is calculating and MD5 would result in an error.
         if (!$body->isSeekable()) {
             throw new CouldNotCreateChecksumException('md5');
         }
         // Set the Content-MD5 header.
         $event->getRequest()->setHeader('Content-MD5', base64_encode(Utils::hash($body, 'md5', true)));
     }
 }
 /**
  * Event to add Segment.io Specific data to the Event Messages
  *
  * @param PreparedEvent $event The PreparedEvent
  *
  * @return bool
  */
 public function onPrepared(PreparedEvent $event)
 {
     if (is_null($this->client)) {
         $this->client = $event->getClient();
     }
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     if (!$operation->getData('batching')) {
         return false;
     }
     $parameters = json_decode($event->getRequest()->getBody()->getContents(), true);
     $this->enqueue(array_merge($parameters, ['action' => $command->getName()]));
     $event->intercept(['success' => true, 'batched' => true]);
     return true;
 }