mpyw\Co\Internal\TypeUtils::isGeneratorClosure PHP Method

isGeneratorClosure() public static method

Check if value is a valid Generator closure.
public static isGeneratorClosure ( mixed $value ) : boolean
$value mixed
return boolean
    public static function isGeneratorClosure($value)
    {
        return $value instanceof \Closure && (new \ReflectionFunction($value))->isGenerator();
    }

Usage Example

Beispiel #1
0
 /**
  * Recursively normalize value.
  *   Generator Closure  -> GeneratorContainer
  *   Array              -> Array (children's are normalized)
  *   Others             -> Others
  * @param  mixed    $value
  * @param  mixed    $yield_key
  * @return mixed
  */
 public static function normalize($value, $yield_key = null)
 {
     if (TypeUtils::isGeneratorClosure($value)) {
         $value = $value();
     }
     if ($value instanceof \Generator) {
         return new GeneratorContainer($value, $yield_key);
     }
     if (is_array($value)) {
         $tmp = [];
         foreach ($value as $k => $v) {
             $tmp[$k] = self::normalize($v, $yield_key);
         }
         return $tmp;
     }
     return $value;
 }