isCurl() public static method

Check if value is a valid cURL handle.
public static isCurl ( mixed $value ) : boolean
$value mixed
return boolean
Example #1
0
 public function testIsCurl()
 {
     $ch = curl_init();
     $this->assertTrue(TypeUtils::isCurl($ch));
     curl_close($ch);
     $this->assertFalse(TypeUtils::isCurl($ch));
     $this->assertFalse(TypeUtils::isCurl(curl_multi_init()));
     $this->assertFalse(TypeUtils::isCurl([1]));
     $this->assertFalse(TypeUtils::isCurl((object) [1]));
 }
Example #2
0
 /**
  * Recursively search yieldable values.
  * Each entries are assoc those contain keys 'value' and 'keylist'.
  *   value   -> the value itself.
  *   keylist -> position of the value. nests are represented as array values.
  * @param  mixed $value   Must be already normalized.
  * @param  array $keylist Internally used.
  * @param  array &$runners Running cURL or Generator identifiers.
  * @return array
  */
 public static function getYieldables($value, array $keylist = [], array &$runners = [])
 {
     $r = [];
     if (!is_array($value)) {
         if (TypeUtils::isCurl($value) || TypeUtils::isGeneratorContainer($value)) {
             if (isset($runners[(string) $value])) {
                 throw new \DomainException('Duplicated cURL resource or Generator instance found.');
             }
             $r[(string) $value] = $runners[(string) $value] = ['value' => $value, 'keylist' => $keylist];
         }
         return $r;
     }
     foreach ($value as $k => $v) {
         $newlist = array_merge($keylist, [$k]);
         $r = array_merge($r, self::getYieldables($v, $newlist, $runners));
     }
     return $r;
 }
Example #3
0
File: Co.php Project: mpyw/co
 /**
  * Promise all changes in yieldables are prepared.
  * @param  array $yieldables
  * @param  bool  $throw_acceptable
  * @return PromiseInterface
  */
 private function promiseAll(array $yieldables, $throw_acceptable)
 {
     $promises = [];
     foreach ($yieldables as $yieldable) {
         // Add or enqueue cURL handles
         if (TypeUtils::isCurl($yieldable['value'])) {
             $promises[(string) $yieldable['value']] = $this->pool->addCurl($yieldable['value']);
             continue;
         }
         // Process generators
         if (TypeUtils::isGeneratorContainer($yieldable['value'])) {
             $promises[(string) $yieldable['value']] = $this->processGeneratorContainer($yieldable['value']);
             continue;
         }
     }
     // If caller cannot accept exception,
     // we handle rejected value as resolved.
     if (!$throw_acceptable) {
         $promises = array_map(['\\mpyw\\Co\\Internal\\YieldableUtils', 'safePromise'], $promises);
     }
     return \React\Promise\all($promises);
 }