You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHP code is generated by `Printer` objects. There is a `PsrPrinter` whose output conforms to PSR-2 and PSR-12 and uses spaces for indentation, and a `Printer` that uses tabs for indentation.
@@ -484,12 +492,19 @@ Need to customize printer behavior? Create your own by inheriting the `Printer`
484
492
```php
485
493
class MyPrinter extends Nette\PhpGenerator\Printer
486
494
{
495
+
/** length of the line after which the line will break */
487
496
public int $wrapLength = 120;
497
+
/** indentation character, can be replaced with a sequence of spaces */
488
498
public string $indentation = "\t";
499
+
/** number of blank lines between properties */
489
500
public int $linesBetweenProperties = 0;
501
+
/** number of blank lines between methods */
490
502
public int $linesBetweenMethods = 2;
503
+
/** number of blank lines between groups of use statements for classes, functions, and constants */
491
504
public int $linesBetweenUseTypes = 0;
505
+
/** position of the opening brace for functions and methods */
492
506
public bool $bracesOnNextLine = true;
507
+
/** separator between the right parenthesis and return type of functions and methods */
493
508
public string $returnTypeColon = ': ';
494
509
}
495
510
```
@@ -551,11 +566,10 @@ new Literal('substr(?, ?)', [$a, $b]);
551
566
```
552
567
553
568
554
-
555
569
Attributes
556
570
----------
557
571
558
-
You can add PHP 8 attributes to all classes, methods, properties, constants, enum cases, functions, closures and parameters (class [Attribute](https://api.nette.org/php-generator/master/Nette/PhpGenerator/Attribute.html)).
572
+
You can add PHP 8 attributes to all classes, methods, properties, constants, enum cases, functions, closures and parameters. [Literals](#literals) can also be used as parameter values.
559
573
560
574
```php
561
575
$class = new Nette\PhpGenerator\ClassType('Demo');
**When the class is part of the namespace, it is rendered slightly differently**: all types (ie. type hints, return types, parent class name,
642
658
implemented interfaces, used traits and attributes) are automatically *resolved* (unless you turn it off, see below).
643
-
It means that you have to **use full class names** in definitions and they will be replaced
644
-
with aliases (according to the use-statements) or fully qualified names in the resulting code:
659
+
It means that you have to **use full class names** in definitions and they will be replaced with aliases (according to the use-statements) or fully qualified names in the resulting code:
645
660
646
661
```php
647
662
$namespace = new Nette\PhpGenerator\PhpNamespace('Foo');
0 commit comments