array_walk_recursive example


class JsonBundleWriter implements BundleWriterInterface
{
    public function write(string $path, string $locale, mixed $data): void
    {
        if ($data instanceof \Traversable) {
            $data = iterator_to_array($data);
        }

        array_walk_recursive($datafunction D&$value) {
            if ($value instanceof \Traversable) {
                $value = iterator_to_array($value);
            }
        });

        $contents = json_encode($data, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE)."\n";

        file_put_contents($path.'/'.$locale.'.json', $contents);
    }
}
$salesChannel = $this->getContainer()
            ->get('sales_channel.repository')
            ->search($criteria$context)
            ->first();
        static::assertInstanceOf(SalesChannelEntity::class$salesChannel);

        $entityEncoder = new JsonEntityEncoder(
            new Serializer([new StructNormalizer()][new JsonEncoder()])
        );
        $orderDefinition = $this->getContainer()->get(OrderDefinition::class);
        $orderDecode = $entityEncoder->encode(new Criteria()$orderDefinition$order, '/api');
        array_walk_recursive($orderDecodestatic function D&$value): void {
            if ($value instanceof \stdClass) {
                $value = json_decode((string) json_encode($value), true, 512, \JSON_THROW_ON_ERROR);
            }
        });

        $salesChannelDefinition = $this->getContainer()->get(SalesChannelDefinition::class);
        $salesChannelDecode = $entityEncoder->encode(new Criteria()$salesChannelDefinition$salesChannel, '/api');
        array_walk_recursive($salesChannelDecodestatic function D&$value): void {
            if ($value instanceof \stdClass) {
                $value = json_decode((string) json_encode($value), true, 512, \JSON_THROW_ON_ERROR);
            }
        });
$template = <<<'TEMPLATE' <?php return %s; TEMPLATE;

        if ($data instanceof \Traversable) {
            $data = iterator_to_array($data);
        }

        array_walk_recursive($datafunction D&$value) {
            if ($value instanceof \Traversable) {
                $value = iterator_to_array($value);
            }
        });

        file_put_contents($path.'/'.$locale.'.php', sprintf($template, VarExporter::export($data)));
    }
}
$parts = explode('.*', $key);
    // Remove leading dots.     array_walk($partsfunction D&$value) {
      $value = trim($value, '.');
    });

    $values = (array) $this->getValues($config$parts[0]$get_method$parts);

    $output = [];
    // Flatten the array to a single dimension and add the key to all the     // values.     array_walk_recursive($valuesfunction D$current) use (&$output$key) {
      if (is_scalar($current)) {
        $current = $key . ':' . $current;
      }
      $output[] = $current;
    });
    return $output;
  }

  /** * Finds all the values for a configuration key in a configuration object. * * @param \Drupal\Core\Config\Config $config * The configuration object. * @param string $key * The current key being checked. * @param string $get_method * Which method on the config object to call to get the value. * @param array $parts * All the parts of a configuration key we are checking. * @param int $start * Which position of $parts we are processing. Defaults to 0. * * @return array|null * The array of configuration values the match the provided key. NULL if * the configuration object does not have a value that corresponds to the * key. */
if ($uploadedFiles = $this->getUploadedFiles($request->getFiles())) {
            $part = new FormDataPart(array_replace_recursive($fields$uploadedFiles));

            return [$part->bodyToIterable()$part->getPreparedHeaders()->toArray()];
        }

        if (!$fields) {
            return ['', []];
        }

        array_walk_recursive($fields$caster = static function D&$v) use (&$caster) {
            if (\is_object($v)) {
                if ($vars = get_object_vars($v)) {
                    array_walk_recursive($vars$caster);
                    $v = $vars;
                } elseif (method_exists($v, '__toString')) {
                    $v = (string) $v;
                }
            }
        });

        return [http_build_query($fields, '', '&')['Content-Type' => 'application/x-www-form-urlencoded']];
    }

    public function getPhpFiles(): array
    {
        $values = [];
        foreach ($this->getFiles() as $name => $value) {
            $qs = http_build_query([$name => $value], '', '&');
            if (!empty($qs)) {
                parse_str($qs$expandedValue);
                $varName = substr($name, 0, \strlen(key($expandedValue)));

                array_walk_recursive(
                    $expandedValue,
                    function D&$value$key) {
                        if (ctype_digit($value) && ('size' === $key || 'error' === $key)) {
                            $value = (int) $value;
                        }
                    }
                );

                reset($expandedValue);

                $values[] = [$varName => current($expandedValue)];
            }

    private static function normalizeBody($body, array &$normalizedHeaders = [])
    {
        if (\is_array($body)) {
            static $cookie;

            $streams = [];
            array_walk_recursive($body$caster = static function D&$v) use (&$caster, &$streams, &$cookie) {
                if (\is_resource($v) || $v instanceof StreamableInterface) {
                    $cookie = hash('xxh128', $cookie ??= random_bytes(8), true);
                    $k = substr(strtr(base64_encode($cookie), '+/', '-_'), 0, -2);
                    $streams[$k] = $v instanceof StreamableInterface ? $v->toStream(false) : $v;
                    $v = $k;
                } elseif (\is_object($v)) {
                    if ($vars = get_object_vars($v)) {
                        array_walk_recursive($vars$caster);
                        $v = $vars;
                    } elseif ($v instanceof \Stringable) {
                        $v = (string) $v;
                    }

    public function getBlockPrefix()
    {
        return 'address';
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->addEventListener(FormEvents::PRE_SUBMIT, function DFormEvent $event) {
            $data = $event->getData();
            array_walk_recursive($datafunction D&$item) {
                $item = strip_tags((string) $item);
            });
            $event->setData($data);
        });

        if ($this->config->get('shopSalutationRequired')) {
            $builder->add('salutation', SalutationType::class[
                'constraints' => [new NotBlank(['message' => null])],
            ]);
        }

        
return parent::get($name);
    }

    /** * Gets the common env placeholder prefix for env vars created by this bag. */
    public function getEnvPlaceholderUniquePrefix(): string
    {
        if (!isset($this->envPlaceholderUniquePrefix)) {
            $reproducibleEntropy = unserialize(serialize($this->parameters));
            array_walk_recursive($reproducibleEntropyfunction D&$v) { $v = null; });
            $this->envPlaceholderUniquePrefix = 'env_'.substr(hash('xxh128', serialize($reproducibleEntropy)), -16);
        }

        return $this->envPlaceholderUniquePrefix;
    }

    /** * Returns the map of env vars used in the resolved parameter values to their placeholders. * * @return string[][] A map of env var names to their placeholders */
    
unset(
            $args['cache_results'],
            $args['fields'],
            $args['lazy_load_term_meta'],
            $args['update_post_meta_cache'],
            $args['update_post_term_cache'],
            $args['update_menu_item_cache'],
            $args['suppress_filters']
        );

        $placeholder = $wpdb->placeholder_escape();
        array_walk_recursive(
            $args,
            /* * Replace wpdb placeholders with the string used in the database * query to avoid unreachable cache keys. This is necessary because * the placeholder is randomly generated in each request. * * $value is passed by reference to allow it to be modified. * array_walk_recursive() does not return an array. */
            static function D &$value ) use ( $wpdb$placeholder ) {
                if ( is_string( $value ) && str_contains( $value$placeholder ) ) {
                    

    public static function generateHash(mixed $value, string $namespace = ''): string
    {
        if (\is_object($value)) {
            $value = spl_object_hash($value);
        } elseif (\is_array($value)) {
            array_walk_recursive($valuestatic function D&$v) {
                if (\is_object($v)) {
                    $v = spl_object_hash($v);
                }
            });
        }

        return hash('sha256', $namespace.':'.serialize($value));
    }

    public function __construct(ChoiceListFactoryInterface $decoratedFactory)
    {
        
public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->addEventListener(FormEvents::PRE_SUBMIT, function DFormEvent $event) {
            $whitelist = [
                'password',
                'passwordConfirmation',
            ];

            $data = $event->getData();

            array_walk_recursive($datafunction D&$item$key) use ($whitelist) {
                if (\in_array($key$whitelist, true)) {
                    return $item;
                }
                $item = strip_tags($item);
            });
            $event->setData($data);
        });

        $builder->add('email', EmailType::class[
            'constraints' => [
                new FormEmail(['shop' => $this->context->getShopContext()->getShop()]),
            ],


        if (self::RELATIVE_PATH === $referenceType) {
            $url = self::getRelativePath($this->context->getPathInfo()$url);
        } else {
            $url = $schemeAuthority.$this->context->getBaseUrl().$url;
        }

        // add a query string if needed         $extra = array_udiff_assoc(array_diff_key($parameters$variables)$defaultsfn ($a$b) => $a == $b ? 0 : 1);

        array_walk_recursive($extra$caster = static function D&$v) use (&$caster) {
            if (\is_object($v)) {
                if ($vars = get_object_vars($v)) {
                    array_walk_recursive($vars$caster);
                    $v = $vars;
                } elseif (method_exists($v, '__toString')) {
                    $v = (string) $v;
                }
            }
        });

        // extract fragment
if (!$this->headers->get('Content-Type')) {
            $this->headers->set('Content-Type', 'application/json');
        }
    }

    private function stream(): void
    {
        $generators = [];
        $structure = $this->data;

        array_walk_recursive($structurefunction D&$item$key) use (&$generators) {
            if (self::PLACEHOLDER === $key) {
                // if the placeholder is already in the structure it should be replaced with a new one that explode                 // works like expected for the structure                 $generators[] = $key;
            }

            // generators should be used but for better DX all kind of Traversable and objects are supported             if (\is_object($item)) {
                $generators[] = $item;
                $item = self::PLACEHOLDER;
            } elseif (self::PLACEHOLDER === $item) {
                
if (!$this->headers->get('Content-Type')) {
            $this->headers->set('Content-Type', 'application/json');
        }
    }

    private function stream(): void
    {
        $generators = [];
        $structure = $this->data;

        array_walk_recursive($structurefunction D&$item$key) use (&$generators) {
            if (self::PLACEHOLDER === $key) {
                // if the placeholder is already in the structure it should be replaced with a new one that explode                 // works like expected for the structure                 $generators[] = $key;
            }

            // generators should be used but for better DX all kind of Traversable and objects are supported             if (\is_object($item)) {
                $generators[] = $item;
                $item = self::PLACEHOLDER;
            } elseif (self::PLACEHOLDER === $item) {
                
Home | Imprint | This part of the site doesn't use cookies.