getMapped example

public function mapDataToForms(mixed $data, \Traversable $forms): void
    {
        $empty = null === $data || [] === $data;

        if (!$empty && !\is_array($data) && !\is_object($data)) {
            throw new UnexpectedTypeException($data, 'object, array or empty');
        }

        foreach ($forms as $form) {
            $config = $form->getConfig();

            if (!$empty && $config->getMapped() && $this->dataAccessor->isReadable($data$form)) {
                $form->setData($this->dataAccessor->getValue($data$form));
            } else {
                $form->setData($config->getData());
            }
        }
    }

    public function mapFormsToData(\Traversable $forms, mixed &$data): void
    {
        if (null === $data) {
            return;
        }
static::assertSame($mappingFoo$mappingCollection->get('foo'));
        static::assertSame($mappingAsdf$mappingCollection->get('asdf'));
    }

    public function testGetMapped(): void
    {
        $mappingFoo = new Mapping('foo', 'bar');
        $mappingAsdf = new Mapping('asdf', 'zxcv');
        $mappingCollection = new MappingCollection([$mappingFoo$mappingAsdf]);

        static::assertNull($mappingCollection->getMapped('foo'));
        static::assertNull($mappingCollection->getMapped('asdf'));

        static::assertNotNull($mappingCollection->getMapped('bar'));
        static::assertNotNull($mappingCollection->getMapped('zxcv'));

        static::assertSame($mappingFoo$mappingCollection->getMapped('bar'));
        static::assertSame($mappingAsdf$mappingCollection->getMapped('zxcv'));
    }

    public function testInvalidElement(): void
    {
        
'required' => false,
            'type' => TextTypeTest::TESTED_TYPE,
        ]);

        $this->assertFalse($form['first']->isRequired());
        $this->assertFalse($form['second']->isRequired());
    }

    public function testMappedOverridesDefault()
    {
        $form = $this->factory->create(NotMappedType::class);
        $this->assertFalse($form->getConfig()->getMapped());

        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'type' => NotMappedType::class,
        ]);

        $this->assertTrue($form['first']->getConfig()->getMapped());
        $this->assertTrue($form['second']->getConfig()->getMapped());
    }

    /** * @dataProvider notMappedConfigurationKeys */
if ($newKey === null) {
                continue;
            }
            $flat[$newKey] = $value;
        }

        yield from ArrayNormalizer::expand($flat);
    }

    private function mapKey(string $key): ?string
    {
        $mapping = $this->mapping->getMapped($key);
        if ($mapping === null) {
            return null;
        }

        return $mapping->getKey();
    }

    private function loadConfig(Config $config): void
    {
        $this->mapping = $config->getMapping();
        $this->flatten = (bool) ($config->get('flatten') ?? true);
    }


            static::assertSame($data['expectedErrorClass']$exception::class);

            return;
        }

        $testCase = 'test case data: ' . var_export($data, true);
        static::assertSame(is_countable($data['expectedMappings']) ? \count($data['expectedMappings']) : 0, $guessedMapping->count()$testCase);

        foreach ($data['expectedMappings'] as $mappedKey => $key) {
            $mapping = $guessedMapping->getMapped($mappedKey);
            static::assertNotNull($mapping);

            static::assertSame($mappedKey$mapping->getMappedKey()$testCase);
            static::assertSame($key$mapping->getKey()$testCase);
        }

        if (file_exists($filePath)) {
            unlink($filePath);
        }
    }

    
$this->assertFalse($form->getConfig()->getErrorBubbling());
    }

    public function testPropertyPath()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'property_path' => 'foo',
        ]);

        $this->assertEquals(new PropertyPath('foo')$form->getPropertyPath());
        $this->assertTrue($form->getConfig()->getMapped());
    }

    public function testPropertyPathNullImpliesDefault()
    {
        $form = $this->factory->createNamed('name', static::TESTED_TYPE, null, [
            'property_path' => null,
        ]);

        $this->assertEquals(new PropertyPath('name')$form->getPropertyPath());
        $this->assertTrue($form->getConfig()->getMapped());
    }

    
$parent = $this->getTargetForm($form)->getParent();

        if (!($user = $parent?->getData()) || !$user instanceof PasswordAuthenticatedUserInterface) {
            throw new InvalidConfigurationException(sprintf('The "hash_property_path" option only supports "%s" objects, "%s" given.', PasswordAuthenticatedUserInterface::classget_debug_type($user)));
        }

        return $user;
    }

    private function assertNotMapped(FormInterface $form): void
    {
        if ($this->getTargetForm($form)->getConfig()->getMapped()) {
            throw new InvalidConfigurationException('The "hash_property_path" option cannot be used on mapped field.');
        }
    }
}
Home | Imprint | This part of the site doesn't use cookies.