Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a5f0477

Browse files
committed
readme: improvements
1 parent 44101cb commit a5f0477

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

‎readme.md‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Let's start with a straightforward example of generating class using [ClassType]
3636
```php
3737
$class = new Nette\PhpGenerator\ClassType('Demo');
3838

39-
$class->setFinal()
39+
$class
40+
->setFinal()
4041
->setExtends(ParentClass::class)
4142
->addImplement(Countable::class)
4243
->addComment("Description of class.\nSecond line\n")
@@ -171,6 +172,7 @@ $methodRecount = $methodCount->cloneWithName('recount');
171172
$class->addMember($methodRecount);
172173
```
173174

175+
174176
Interface or Trait
175177
------------------
176178

@@ -267,6 +269,7 @@ $obj = new class ($val) {
267269
};
268270
```
269271

272+
270273
Global Function
271274
---------------
272275

@@ -292,6 +295,7 @@ function foo($a, $b)
292295
}
293296
```
294297

298+
295299
Closure
296300
-------
297301

@@ -318,6 +322,7 @@ function ($a, $b) use (&$c) {
318322
}
319323
```
320324

325+
321326
Arrow Function
322327
--------------
323328

@@ -338,6 +343,7 @@ Result:
338343
fn($a, $b) => $a + $b
339344
```
340345

346+
341347
Method and Function Signature
342348
-----------------------------
343349

@@ -377,6 +383,7 @@ function count(...$items)
377383
}
378384
```
379385

386+
380387
Method and Function Body
381388
------------------------
382389

@@ -466,7 +473,8 @@ function foo($a)
466473
}
467474
```
468475

469-
Printers and PSR compliance
476+
477+
Printers and PSR Compliance
470478
---------------------------
471479

472480
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.
@@ -551,11 +559,10 @@ new Literal('substr(?, ?)', [$a, $b]);
551559
```
552560

553561

554-
555562
Attributes
556563
----------
557564

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)).
565+
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.
559566

560567
```php
561568
$class = new Nette\PhpGenerator\ClassType('Demo');
@@ -590,6 +597,7 @@ class Demo
590597
}
591598
```
592599

600+
593601
Namespace
594602
---------
595603

@@ -635,13 +643,13 @@ echo $namespace->resolveName('Bar'); // 'Foo\Bar'
635643
echo $namespace->resolveName('range', $namespace::NameFunction); // 'iter\range'
636644
```
637645

646+
638647
Class Names Resolving
639648
---------------------
640649

641650
**When the class is part of the namespace, it is rendered slightly differently**: all types (ie. type hints, return types, parent class name,
642651
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:
652+
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:
645653

646654
```php
647655
$namespace = new Nette\PhpGenerator\PhpNamespace('Foo');
@@ -690,6 +698,7 @@ $printer->setTypeResolving(false);
690698
echo $printer->printNamespace($namespace);
691699
```
692700

701+
693702
PHP Files
694703
---------
695704

@@ -736,6 +745,7 @@ function foo()
736745
}
737746
```
738747

748+
739749
Generating According to Existing Ones
740750
-------------------------------------
741751

@@ -750,7 +760,7 @@ $function = Nette\PhpGenerator\GlobalFunction::from('trim');
750760

751761
// creates a closure as specified
752762
$closure = Nette\PhpGenerator\Closure::from(
753-
function (stdClass $a, $b = null) {}
763+
function (stdClass $a, $b = null) {},
754764
);
755765
```
756766

@@ -763,6 +773,7 @@ $class = Nette\PhpGenerator\ClassType::from(Foo::class, withBodies: true);
763773
$function = Nette\PhpGenerator\GlobalFunction::from('foo', withBody: true);
764774
```
765775

776+
766777
Loading from PHP File
767778
---------------------
768779

@@ -797,7 +808,7 @@ This requires `nikic/php-parser` to be installed.
797808
Variables Dumper
798809
----------------
799810

800-
The Dumper returns a parsable PHP string representation of a variable. Provides better and clearer output that native functon `var_export()`.
811+
The Dumper returns a parsable PHP string representation of a variable. Provides better and clearer output that native function `var_export()`.
801812

802813
```php
803814
$dumper = new Nette\PhpGenerator\Dumper;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /