Closed Eydamos closed 1 year ago
Agree with the problem, not so much with the proposed solution. You cannot revert __construct
call, unless it uses promoted properties only.
What I think should work always is nesting Nette\PhpGenerator\Attribute
objects, i.e.
$class->addAttribute(ORM\Table::class, [
'name' => new Literal('self::TABLE_NAME'),
'indexes' => [
new Attribute(ORM\Index::class, [
'columns' => [...],
]),
],
]);
This works:
$class->addAttribute(ORM\Table::class, [
'name' => new Literal('self::TABLE_NAME'),
'indexes' => [
Literal::new(ORM\Index::class, [
'columns' => [...],
]),
],
]);
If I'm not missing something in the documentation it is currently very cumbersome to have nested attributes as the nested attributes use the
new
keyword. Therefore I would need to manually build a string likenew SomeClassName('argument1', someOptionalParam: 'argument2')
and then wrap it withLiteral()
to be able to generate nested attributes. Instead it would be very helpful if the generator would recognise that there is an object as a parameter for the attribute and render it accordingly.Example generator:
Expected result:
Actual result: