Skip to content

Commit 34aaf23

Browse files
committed
readme: improved info about loading from file [Closes #129]
1 parent 0f1275b commit 34aaf23

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

readme.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ $function = Nette\PhpGenerator\GlobalFunction::from('foo', withBody: true);
766766
Loading from PHP File
767767
---------------------
768768

769-
You can also load classes and functions directly from a PHP file that is not already loaded or string of PHP code:
769+
You can also load functions, classes, interfaces and enums directly from a string of PHP code. For example, we create `ClassType` object this way:
770770

771771
```php
772772
$class = Nette\PhpGenerator\ClassType::fromCode(<<<XX
@@ -779,14 +779,20 @@ $class = Nette\PhpGenerator\ClassType::fromCode(<<<XX
779779
XX);
780780
```
781781

782-
Loading the entire PHP file, which may contain multiple classes or even multiple namespaces:
782+
When loading classes from PHP code, single line comments outside of method bodies are ignored (e.g. for properties, etc.) because this library does not have an API to work with them.
783+
784+
You can also load the entire PHP file directly, which can contain any number of classes, functions or even multiple namespaces:
783785

784786
```php
785787
$file = Nette\PhpGenerator\PhpFile::fromCode(file_get_contents('classes.php'));
786788
```
787789

790+
The initial file comment and the `strict_types` declaration are also loaded. On the other hand, all other global code is ignored.
791+
788792
This requires `nikic/php-parser` to be installed.
789793

794+
*(If you need to manipulate global code in files or individual statements in method bodies, it is better to use the `nikic/php-parser` library directly.)*
795+
790796

791797
Variables Dumper
792798
----------------

0 commit comments

Comments
 (0)