RecursiveArrayIterator example


    public function isValid($value)
    {
        $this->_setValue($value);
        if ($this->getRecursive()) {
            $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($this->_haystack));
            foreach($iterator as $element) {
                if ($this->_strict) {
                    if ($element === $value) {
                        return true;
                    }
                } else if ($element == $value) {
                    return true;
                }
            }
        } else {
            if (in_array($value$this->_haystack, $this->_strict)) {
                

  public function providerTestSupportsNormalization() {
    return [
      // Something that is not an object should return FALSE immediately.       [FALSE, []],
      // An object with no class set should return FALSE.       [FALSE, new \stdClass()],
      // Set a supported Class.       [TRUE, new \stdClass(), 'stdClass'],
      // Set a supported interface.       [TRUE, new \RecursiveArrayIterator(), 'RecursiveIterator'],
      // Set a different class.       [FALSE, new \stdClass(), 'ArrayIterator'],
      // Set a different interface.       [FALSE, new \stdClass(), 'RecursiveIterator'],
    ];
  }

}

/** * Test class for NormalizerBase. */
->addOrderBy($queryBuilder->expr()->asc('shop.id'))
                ->getQuery()
                ->getArrayResult();

            return array_column($result, 'id');
        }

        if ($argumentName === 'analyzer') {
            $client = $this->container->get(Client::class);

            $recursive = new RecursiveIteratorIterator(
                new RecursiveArrayIterator($client->indices()->getMapping()),
                RecursiveIteratorIterator::SELF_FIRST
            );

            $analyzer = [];
            foreach ($recursive as $key => $value) {
                if ($key === 'analyzer') {
                    $analyzer[] = $value;
                }
            }

            return array_unique(array_merge($analyzer, self::DEFAULT_ANALYZERS));
        }

    public function arrayGetPath($array$glue = '.')
    {
        $result = [];
        $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
        foreach ($iterator as $leafValue) {
            $parts = [];
            foreach (range(0, $iterator->getDepth()) as $depth) {
                $parts[] = $iterator->getSubIterator($depth)->key();
            }

            $path = implode($glue$parts);

            $result[$path] = $leafValue;
        }

        
dump($arrayObject);
$arrayObject['X'] = 'A';
$arrayObject['Y'] = new \ArrayObject(['type' => 'object']);
$arrayObject['Y']['Z'] = 'B';

$arrayIterator = new \ArrayIterator();
dump($arrayIterator);
$arrayIterator['X'] = 'A';
$arrayIterator['Y'] = new \ArrayIterator(['type' => 'object']);
$arrayIterator['Y']['Z'] = 'B';

$recursiveArrayIterator = new \RecursiveArrayIterator();
dump($recursiveArrayIterator);
$recursiveArrayIterator['X'] = 'A';
$recursiveArrayIterator['Y'] = new \RecursiveArrayIterator(['type' => 'object']);
$recursiveArrayIterator['Y']['Z'] = 'B';

--EXPECTF--
%s on line %d:
ArrayObject {#%d   storage: []
  flag::STD_PROP_LIST: false
  flag::ARRAY_AS_PROPS: false
  
foreach ($array as $field => $value) {
                $pointer = &$output[$name];

                if (is_array($value)) {
                    $pointer[$field] = $value;

                    continue;
                }

                $stack    = [&$pointer];
                $iterator = new RecursiveIteratorIterator(
                    new RecursiveArrayIterator($value),
                    RecursiveIteratorIterator::SELF_FIRST
                );

                foreach ($iterator as $key => $val) {
                    array_splice($stack$iterator->getDepth() + 1);
                    $pointer = &$stack[count($stack) - 1];
                    $pointer = &$pointer[$key];
                    $stack[] = &$pointer;

                    // RecursiveIteratorIterator::hasChildren() can be used. RecursiveIteratorIterator                     // forwards all unknown method calls to the underlying RecursiveIterator internally.

    public function withAttributes(?array $attributes)static
    {
        $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($attributes ?? []), \RecursiveIteratorIterator::LEAVES_ONLY);

        foreach ($it as $attribute) {
            if (!\is_string($attribute)) {
                throw new InvalidArgumentException(sprintf('Each attribute must be a string, "%s" given.', get_debug_type($attribute)));
            }
        }

        return $this->with(AbstractNormalizer::ATTRIBUTES, $attributes);
    }

    /** * If AbstractNormalizer::ATTRIBUTES are specified, and the source has fields that are not part of that list, * configures whether to ignore those attributes or throw an ExtraAttributesException. */

    private function get_expect_header($data) {
        if (!is_array($data)) {
            return strlen((string) $data) >= 1048576 ? '100-Continue' : '';
        }

        $bytesize = 0;
        $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data));

        foreach ($iterator as $datum) {
            $bytesize += strlen((string) $datum);

            if ($bytesize >= 1048576) {
                return '100-Continue';
            }
        }

        return '';
    }
}
if ($element instanceof \ArrayAccess) {
      $filtered_element = clone $element;
    }
    else {
      $filtered_element = $element;
    }
    $args = func_get_args();
    unset($args[0]);
    // Since the remaining arguments can be a mix of arrays and strings, we use     // some native PHP iterator classes to allow us to recursively iterate over     // everything in a single pass.     $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($args));
    foreach ($iterator as $key) {
      unset($filtered_element[$key]);
    }
    return $filtered_element;
  }

  /** * Adds a theme suggestion to the element. * * @param array|null $element * A theme element render array. * @param string|\Stringable $suggestion * The theme suggestion part to append to the existing theme hook(s). * * @return array|null * The element with the full theme suggestion added as the highest priority. */
/** * Flatten nested array values to single array values. * * For example, [[1, 2, [3, 4]]] becomes [1, 2, 3, 4]. */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row$destination_property) {
    if (!is_array($value) && !is_object($value)) {
      $type = gettype($value);
      throw new MigrateException(sprintf("Input should be an array or an object, instead it was of type '%s'", $type));
    }
    return iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($value)), FALSE);
  }

}

    public function withAttributes(?array $attributes)static
    {
        $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($attributes ?? []), \RecursiveIteratorIterator::LEAVES_ONLY);

        foreach ($it as $attribute) {
            if (!\is_string($attribute)) {
                throw new InvalidArgumentException(sprintf('Each attribute must be a string, "%s" given.', get_debug_type($attribute)));
            }
        }

        return $this->with(AbstractNormalizer::ATTRIBUTES, $attributes);
    }

    /** * If AbstractNormalizer::ATTRIBUTES are specified, and the source has fields that are not part of that list, * configures whether to ignore those attributes or throw an ExtraAttributesException. */

          else {
            $entity_ids_by_type[$entity_type][$index][$relationship_id] = $result->$id_alias;
          }
        }
      }
    }

    // Load all entities and assign them to the correct result row.     foreach ($entity_ids_by_type as $entity_type => $ids) {
      $entity_storage = $this->entityTypeManager->getStorage($entity_type);
      $flat_ids = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($ids)), FALSE);

      $entities = $entity_storage->loadMultiple(array_unique($flat_ids));
      $results = $this->assignEntitiesToResult($ids$entities$results);
    }

    // Now load all revisions.     foreach ($revision_ids_by_type as $entity_type => $revision_ids) {
      $entity_storage = $this->entityTypeManager->getStorage($entity_type);
      $entities = [];

      foreach ($revision_ids as $index => $revision_id_by_relationship) {
        
Home | Imprint | This part of the site doesn't use cookies.