@@ -582,6 +582,13 @@ new Literal('substr(?, ?)', [$a, $b]);
582
582
// generates, for example: substr('hello', 5);
583
583
```
584
584
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
+
585
592
586
593
Attributes
587
594
----------
@@ -590,10 +597,15 @@ You can add PHP 8 attributes to all classes, methods, properties, constants, enu
590
597
591
598
``` php
592
599
$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
+ ]);
594
606
595
607
$class->addProperty('list')
596
- ->addAttribute('WithArguments', [1, 2] );
608
+ ->addAttribute('Deprecated' );
597
609
598
610
$method = $class->addMethod('count')
599
611
->addAttribute('Foo\Cached', ['mode' => true]);
@@ -607,16 +619,18 @@ echo $class;
607
619
Result:
608
620
609
621
``` php
610
- #[Deprecated ]
622
+ #[Table(name: 'user', constraints: [new UniqueConstraint(name: 'ean', columns: ['ean'])]) ]
611
623
class Demo
612
624
{
613
- #[WithArguments(1, 2) ]
625
+ #[Deprecated ]
614
626
public $list;
615
627
616
628
617
629
#[Foo\Cached(mode: true)]
618
- public function count(#[Bar] $items)
619
- {
630
+ public function count(
631
+ #[Bar]
632
+ $items,
633
+ ) {
620
634
}
621
635
}
622
636
```
0 commit comments