mpyw\Co\Internal\YieldableUtils::getYieldables PHP Method

getYieldables() public static method

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.
public static getYieldables ( mixed $value, array $keylist = [], array &$runners = [] ) : array
$value mixed Must be already normalized.
$keylist array Internally used.
$runners array
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;
    }

Usage Example

コード例 #1
0
ファイル: ControlUtils.php プロジェクト: mpyw/co
 /**
  * Executed by Co::any() or Co::race().
  * @param  mixed    $value
  * @param  callable $filter  self::reverse or self::fail.
  * @param  string   $message Used for failure.
  * @return \Generator
  */
 public static function anyOrRace($value, callable $filter, $message)
 {
     $value = YieldableUtils::normalize($value);
     $yieldables = YieldableUtils::getYieldables($value);
     $wrapper = self::getWrapperGenerator($yieldables, $filter);
     try {
         $results = (yield $wrapper);
     } catch (ControlException $e) {
         (yield CoInterface::RETURN_WITH => $e->getValue());
     }
     $apply = YieldableUtils::getApplier($value, $yieldables);
     throw new AllFailedException($message, 0, $apply($results));
 }
All Usage Examples Of mpyw\Co\Internal\YieldableUtils::getYieldables