replaceRecursive example

use Shopware\Core\Framework\Log\Package;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

#[Package('core')] class ReplaceRecursiveFilter extends AbstractExtension
{
    public function getFilters(): array
    {
        return [
            new TwigFilter('replace_recursive', $this->replaceRecursive(...)),
        ];
    }

    /** * @param array<mixed> ...$params * * @return array<mixed> */
    public function replaceRecursive(array ...$params): array
    {
        return array_replace_recursive(...$params);
    }
$expect = [
            'foo' => 'bar',
            'demo' => true,
            'lorem' => [
                'ipsum' => false,
                'non' => 'nononono',
                'dolor' => 'sit',
            ],
            'test' => 'case',
        ];

        $result = $this->replaceRecursiveFilter->replaceRecursive($arrayOne$arrayTwo);

        static::assertEquals($expect$result);
    }

    public function testReplaceRecursiveThreeObjects(): void
    {
        $arrayOne = [
            'foo' => 'bar',
            'demo' => true,
            'lorem' => [
                'ipsum' => false,
                
Home | Imprint | This part of the site doesn't use cookies.