Пример #1
0
 private function fulfillIncludedElements()
 {
     $elements = array_map(function (Relationship $relationship) {
         return $relationship->getData();
     }, $this->buildRelationships());
     // fulfill included elements
     $promises = $this->getPendingPromisesFromElements($elements);
     if (!empty($promises)) {
         Promise\all($promises)->wait();
     }
 }
Пример #2
0
 /**
  * @param array $files of [$source, $destination]
  * @return array
  */
 public function bulkSave(array $files)
 {
     $promises = [];
     foreach ($files as $file) {
         $promises[] = $this->s3Upload($file[0], $file[1]);
     }
     $results = Promise\all($promises)->wait();
     gc_collect_cycles();
     return array_map(function (Result $result) {
         return $result->toArray()['ObjectURL'];
     }, $results);
 }
 /**
  * Creates a BatchDelete object from all of the paginated results of a
  * ListObjects operation. Each result that is returned by the ListObjects
  * operation will be deleted.
  *
  * @param AwsClientInterface $client            AWS Client to use.
  * @param array              $listObjectsParams ListObjects API parameters
  * @param array              $options           BatchDelete options.
  *
  * @return BatchDelete
  */
 public static function fromListObjects(AwsClientInterface $client, array $listObjectsParams, array $options = [])
 {
     $iter = $client->getPaginator('ListObjects', $listObjectsParams);
     $bucket = $listObjectsParams['Bucket'];
     $fn = function (BatchDelete $that) use($iter) {
         return $iter->each(function ($result) use($that) {
             $promises = [];
             foreach ($result['Contents'] as $object) {
                 if ($promise = $that->enqueue($object)) {
                     $promises[] = $promise;
                 }
             }
             return $promises ? Promise\all($promises) : null;
         });
     };
     return new self($client, $bucket, $fn, $options);
 }
Пример #4
0
 /**
  * Api mail send
  * @return [json] Api return
  */
 private function apiMailSend($uri, $gateway, $params)
 {
     // change mail gateway
     $this->setGateways($gateway);
     // get Async config
     $async = $this->getAsync();
     if (!$async) {
         // send
         $client = new \GuzzleHttp\Client();
         // sync send
         $res = $client->request('post', $uri, ['form_params' => $params]);
         return (string) $res->getBody();
     } else {
         // async send
         $curl = new CurlMultiHandler();
         $handler = HandlerStack::create($curl);
         // send
         $client = new \GuzzleHttp\Client(['handler' => $handler]);
         $promise = $client->requestAsync('post', $uri, ['form_params' => $params]);
         if (isset($params['xsmtpapi'])) {
             $params['xsmtpapi'] = json_encode(json_decode($params['xsmtpapi']), JSON_UNESCAPED_UNICODE);
         }
         $promise->then(function (ResponseInterface $res) use($params) {
             $fileDir = $this->getSendCloudLogDir();
             $this->logInfo('[' . Carbon::now($this->local)->format('Y-m-d H:i:s') . ']' . json_encode($params, JSON_UNESCAPED_UNICODE) . chr(10), $fileDir);
         }, function (RequestException $e) use($params) {
             $fileDir = $this->getSendCloudFailLogDir();
             $this->logInfo('[' . Carbon::now($this->local)->format('Y-m-d H:i:s') . ']' . json_encode($params, JSON_UNESCAPED_UNICODE) . chr(10), $fileDir);
         });
         $aggregate = Promise\all([$promise]);
         while (!Promise\is_settled($aggregate)) {
             $curl->tick();
         }
         return true;
     }
 }