PropertyAccessDecorator example

use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Contracts\Translation\TranslatorInterface;

class ChoiceType extends AbstractType
{
    private ChoiceListFactoryInterface $choiceListFactory;
    private ?TranslatorInterface $translator;

    public function __construct(ChoiceListFactoryInterface $choiceListFactory = null, TranslatorInterface $translator = null)
    {
        $this->choiceListFactory = $choiceListFactory ?? new CachingFactoryDecorator(
            new PropertyAccessDecorator(
                new DefaultChoiceListFactory()
            )
        );
        $this->translator = $translator;
    }

    /** * @return void */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        

class CoreExtension extends AbstractExtension
{
    private PropertyAccessorInterface $propertyAccessor;
    private ChoiceListFactoryInterface $choiceListFactory;
    private ?TranslatorInterface $translator;

    public function __construct(PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null, TranslatorInterface $translator = null)
    {
        $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
        $this->choiceListFactory = $choiceListFactory ?? new CachingFactoryDecorator(new PropertyAccessDecorator(new DefaultChoiceListFactory()$this->propertyAccessor));
        $this->translator = $translator;
    }

    protected function loadTypes(): array
    {
        return [
            new Type\FormType($this->propertyAccessor),
            new Type\BirthdayType(),
            new Type\CheckboxType(),
            new Type\ChoiceType($this->choiceListFactory, $this->translator),
            new Type\CollectionType(),
            
use Symfony\Component\PropertyAccess\PropertyPath;

/** * @author Bernhard Schussek <bschussek@gmail.com> */
class PropertyAccessDecoratorTest extends TestCase
{
    private PropertyAccessDecorator $factory;

    protected function setUp(): void
    {
        $this->factory = new PropertyAccessDecorator(new DefaultChoiceListFactory());
    }

    public function testCreateFromChoicesPropertyPath()
    {
        $object = (object) ['property' => 'value'];

        $this->assertSame(['value' => $object]$this->factory->createListFromChoices([$object], 'property')->getChoices());
    }

    public function testCreateFromChoicesPropertyPathInstance()
    {
        
Home | Imprint | This part of the site doesn't use cookies.