Skip to content

Commit 3926b3f

Browse files
committed
readme: improved
1 parent ddf28d8 commit 3926b3f

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

readme.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ $class
5151

5252
// to generate PHP code simply cast to string or use echo:
5353
echo $class;
54+
55+
// or use printer:
56+
$printer = new Nette\PhpGenerator\Printer;
57+
echo $printer->printClass($class);
5458
```
5559

5660
It will render this result:
@@ -82,10 +86,10 @@ $class->addProperty('items', [1, 2, 3])
8286
It generates:
8387

8488
```php
85-
const ID = 123;
89+
const ID = 123;
8690

87-
/** @var int[] */
88-
private static $items = [1, 2, 3];
91+
/** @var int[] */
92+
private static $items = [1, 2, 3];
8993
```
9094

9195
And we can add methods with parameters:
@@ -106,14 +110,14 @@ $method->addParameter('items', []) // $items = []
106110
It results in:
107111

108112
```php
109-
/**
110-
* Count it.
111-
* @return int
112-
*/
113-
final protected function count(array &$items = [])
114-
{
115-
return count($items ?: $this->items);
116-
}
113+
/**
114+
* Count it.
115+
* @return int
116+
*/
117+
final protected function count(array &$items = [])
118+
{
119+
return count($items ?: $this->items);
120+
}
117121
```
118122

119123
If the property, constant, method or parameter already exist, it will be overwritten.
@@ -181,11 +185,10 @@ Tabs versus spaces
181185
The generated code uses tabs for indentation. If you want to have the output compatible with PSR-2 or PSR-12, use `PsrPrinter`:
182186

183187
```php
184-
$printer = new Nette\PhpGenerator\PsrPrinter;
185-
186188
$class = new Nette\PhpGenerator\ClassType('Demo');
187189
// ...
188190

191+
$printer = new Nette\PhpGenerator\PsrPrinter;
189192
echo $printer->printClass($class); // 4 spaces indentation
190193
```
191194

0 commit comments

Comments
 (0)