Hi everyone! Revisiting a ZF app after a small hiatus, and I had a quick question about setObject, when the object in question has constructor arguments.
In FooFormFactory:
use DoctrineModule\Stdlib\Hydrator\DoctrineObject;
...
$form = new FooForm();
$form->setHydrator(new DoctrineObject($serviceManager->get('doctrine.entitymanager.orm_default'), false));
$form->setInputFilter($serviceManager->get('InputFilterManager')->get(FooInputFilter::class));
So far, so good.
Foo’s constructor looks like so:
public function __construct( string $domainRequirement );
This string is being punched in using the form, and at Factory time, it is unknown. This here won’t work:
$form = new FooForm();
$form->setHydrator(new DoctrineObject($serviceManager->get('doctrine.entitymanager.orm_default'), false));
$form->setInputFilter($serviceManager->get('InputFilterManager')->get(FooInputFilter::class));
$form->setObject(new Foo()); // missing ctor arg
This here works, but it feels dirty?
$form = new LemonadeInstanceForm();
$form->setHydrator(new DoctrineObject($serviceManager->get('doctrine.entitymanager.orm_default'), false));
$form->setInputFilter($serviceManager->get('InputFilterManager')->get(LemonadeInstanceInputFilter::class));
$class = new \ReflectionClass(Foo::class);
$form->setObject($class->newInstanceWithoutConstructor());
Is that how you go about it in your code? Would you go so far as to use a custom DTO in between as mediator between the form and the object to get around this?
Thanks a bunch.
Alex