@@ -512,6 +512,8 @@ class MyPrinter extends Nette\PhpGenerator\Printer
512512 public bool $singleParameterOnOneLine = false;
513513 // omits namespaces that do not contain any class or function
514514 public bool $omitEmptyNamespaces = true;
515+ // places declare(strict_types) on the same line as <?php
516+ public bool $declareOnOpenTag = false;
515517 // separator between the right parenthesis and the return type of functions and methods
516518 public string $returnTypeColon = ': ';
517519}
@@ -727,7 +729,7 @@ $class = $namespace->addClass('Task');
727729$interface = $namespace->addInterface('Countable');
728730$trait = $namespace->addTrait('NameAware');
729731
730- // or insert an existing class into the namespace
732+ // or insert an existing class or function into the namespace
731733$class = new Nette\PhpGenerator\ClassType('Task');
732734$namespace->add($class);
733735```
@@ -840,14 +842,12 @@ echo $file;
840842Result:
841843
842844```php
843- <?php
845+ <?php declare(strict_types=1);
844846
845847/**
846848 * This file is auto-generated.
847849 */
848850
849- declare(strict_types=1);
850-
851851namespace Foo;
852852
853853class A
@@ -859,6 +859,14 @@ function foo()
859859}
860860```
861861
862+ You can also insert existing class, function, and namespace objects into the file using the `add()` method:
863+
864+ ```php
865+ $file = new Nette\PhpGenerator\PhpFile;
866+ $class = new Nette\PhpGenerator\ClassType('Demo');
867+ $file->add($class);
868+ ```
869+
862870**Please note:** No additional code (like `echo 'hello'`) can be added to the files outside of functions, classes, or namespaces.
863871
864872
0 commit comments