コード例 #1
0
ファイル: ChunkingIterator.php プロジェクト: PeeHaa/Artax
 public function current()
 {
     if ($this->isLastChunk) {
         return $this->applyChunkEncoding('');
     } elseif (($current = $this->iterator->current()) === '') {
         return null;
     } elseif (is_string($current)) {
         return $this->applyChunkEncoding($current);
     } elseif ($current instanceof Promise) {
         $future = new Future();
         $current->when(function ($error, $result) use($future) {
             if ($error) {
                 $future->fail($error);
             } elseif (is_string($result)) {
                 $future->succeed($this->applyChunkEncoding($result));
             } else {
                 $future->fail(new \DomainException(sprintf('Only string/Promise elements may be chunked; %s provided', gettype($result))));
             }
         });
         return $future->promise();
     } else {
         // @TODO How to react to an invalid type returned from an iterator?
         return null;
     }
 }
コード例 #2
0
ファイル: FileBody.php プロジェクト: PeeHaa/Artax
 private function generateNaiveHeaders()
 {
     $future = new Future();
     $this->generateNaiveLength()->when(function ($error, $result) use($future) {
         if ($error) {
             $future->fail($error);
         } else {
             $future->succeed(['Content-Length' => $result]);
         }
     });
     return $future->promise();
 }
コード例 #3
0
ファイル: HttpSocketPool.php プロジェクト: PeeHaa/Artax
 private function tunnelThroughProxy(Future $future, $socket, $authority)
 {
     if (empty(stream_context_get_options($socket)['artax*']['is_tunneled'])) {
         $futureTunnel = $this->tunneler->tunnel($socket, $authority);
         $futureTunnel->when(function ($error) use($future, $socket) {
             if ($error) {
                 $future->fail($error);
             } else {
                 $future->succeed($socket);
             }
         });
     } else {
         $future->succeed($socket);
     }
 }
コード例 #4
0
ファイル: SocketPool.php プロジェクト: PeeHaa/Artax
 private function initializeNewConnection(Future $future, $uri, $options)
 {
     $futureSocket = $this->connector->connect($uri, $options);
     $futureSocket->when(function ($error, $socket) use($future, $uri) {
         if ($error) {
             $future->fail($error);
         } else {
             $this->finalizeNewConnection($future, $uri, $socket);
         }
     });
 }
コード例 #5
0
ファイル: FormBody.php プロジェクト: PeeHaa/Artax
 private function sumMultipartFieldLengths(Reactor $reactor, array $fields)
 {
     $lengths = [];
     foreach ($fields as $field) {
         if (is_string($field)) {
             $lengths[] = strlen($field);
         } else {
             $lengths[] = $field->getLength($reactor);
         }
     }
     $future = new Future();
     \After\all($lengths)->when(function ($error, $result) use($future) {
         if ($error) {
             $future->fail($error);
         } else {
             $future->succeed(array_sum($result));
         }
     });
     return $future->promise();
 }