@@ -766,7 +766,7 @@ $function = Nette\PhpGenerator\GlobalFunction::from('foo', withBody: true);
766
766
Loading from PHP File
767
767
---------------------
768
768
769
- You can also load classesand 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 :
770
770
771
771
``` php
772
772
$class = Nette\PhpGenerator\ClassType::fromCode(<<<XX
@@ -779,14 +779,20 @@ $class = Nette\PhpGenerator\ClassType::fromCode(<<<XX
779
779
XX);
780
780
```
781
781
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:
783
785
784
786
```php
785
787
$file = Nette\PhpGenerator\PhpFile::fromCode(file_get_contents( ' classes.php' ));
786
788
```
787
789
790
+ The initial file comment and the `strict_types` declaration are also loaded. On the other hand, all other global code is ignored.
791
+
788
792
This requires `nikic /php-parser` to be installed.
789
793
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
+
790
796
791
797
Variables Dumper
792
798
----------------
0 commit comments