sonata-project / exporter

Lightweight Exporter library
https://docs.sonata-project.org/projects/exporter
MIT License
438 stars 88 forks source link

Use enableMagicCall when creating the propertyAccessor to make the exporter more flexible #674

Open gravitiq-cm opened 2 months ago

gravitiq-cm commented 2 months ago

Feature Request

Is there a reason not to enable use of methods accessed via magic __call() in the exporter?

Since everything has to be done through a property string, it's not possible to pass in arguments. Enabling use of __call() makes the exporter more flexible and gives power to the user to decide how to use it.

The change is relatively simple:

    public function __construct(
        protected array $fields,
        protected string $dateTimeFormat = 'r',
        protected bool $useBackedEnumValue = true
    ) {
        // original version:
        //     $this->propertyAccessor = PropertyAccess::createPropertyAccessor();

        $this->propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
            ->enableMagicCall()
            ->getPropertyAccessor()
        ;
    }
VincentLanglet commented 1 month ago

Feel free to provide a PR (with a test) and I wont see a reason to refuse it