Closed leprz closed 3 years ago
Hi, Is it possible to add support for constants in attributes arguments?
So generated code may look like this:
#[Argument('name', type: ArgumentTypes::REQUIRED)]
Currently it is possible to do something like [code below] or just use const value:
$class->setAttribute( 'Argument', [ 'name', 'type' => 'ArgumentTypes::REQUIRED' ] );
in the result a constant will be wrapped in the quotes and treated as a string
#[Argument('name', type: 'ArgumentTypes::REQUIRED')]
I believe this feature will be highly demanded as more and more libs and frameworks are adding support for PHP 8 attributes. And they already use constants.
new Nette\PhpGenerator\PhpLiteral('ArgumentTypes::REQUIRED') should do the trick.
new Nette\PhpGenerator\PhpLiteral('ArgumentTypes::REQUIRED')
Thanks @mabar 🥇 It works. I should read documentation more carefully there is a chapter about Literals.
Hi, Is it possible to add support for constants in attributes arguments?
So generated code may look like this:
Currently it is possible to do something like [code below] or just use const value:
in the result a constant will be wrapped in the quotes and treated as a string
I believe this feature will be highly demanded as more and more libs and frameworks are adding support for PHP 8 attributes. And they already use constants.