@@ -582,6 +582,13 @@ new Literal('substr(?, ?)', [$a, $b]);
582582// generates, for example: substr('hello', 5);
583583```
584584
585+ The literal representing the creation of a new object is easily generated by the ` new ` method:
586+
587+ ``` php
588+ Literal::new(Demo::class, [$a, 'foo' => $b]);
589+ // generates, for example: new Demo(10, foo: 20)
590+ ```
591+
585592
586593Attributes
587594----------
@@ -590,10 +597,15 @@ You can add PHP 8 attributes to all classes, methods, properties, constants, enu
590597
591598``` php
592599$class = new Nette\PhpGenerator\ClassType('Demo');
593- $class->addAttribute('Deprecated');
600+ $class->addAttribute('Table', [
601+ 'name' => 'user',
602+ 'constraints' => [
603+ Literal::new('UniqueConstraint', ['name' => 'ean', 'columns' => ['ean']]),
604+ ],
605+ ]);
594606
595607$class->addProperty('list')
596- ->addAttribute('WithArguments', [1, 2] );
608+ ->addAttribute('Deprecated' );
597609
598610$method = $class->addMethod('count')
599611 ->addAttribute('Foo\Cached', ['mode' => true]);
@@ -607,16 +619,18 @@ echo $class;
607619Result:
608620
609621``` php
610- #[Deprecated ]
622+ #[Table(name: 'user', constraints: [new UniqueConstraint(name: 'ean', columns: ['ean'])]) ]
611623class Demo
612624{
613- #[WithArguments(1, 2) ]
625+ #[Deprecated ]
614626 public $list;
615627
616628
617629 #[Foo\Cached(mode: true)]
618- public function count(#[Bar] $items)
619- {
630+ public function count(
631+ #[Bar]
632+ $items,
633+ ) {
620634 }
621635}
622636```
0 commit comments