Skip to content

Commit

Permalink
php-generator 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 15, 2022
1 parent 9498e88 commit d51d8ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
29 changes: 15 additions & 14 deletions doc/cs/php-generator/@home.texy
Expand Up @@ -29,7 +29,6 @@ $class
->setFinal()
->setExtends(ParentClass::class)
->addImplement(Countable::class)
->addTrait(Nette\SmartObject::class)
->addComment("Popis třídy.\nDruhý řádek\n")
->addComment('@property-read Nette\Forms\Form $form');

Expand Down Expand Up @@ -141,7 +140,7 @@ Vlastnosti určené pouze pro čtení zavedené v PHP 8.1 lze označit pomocí f

------

Pokud přidaná vlastnost, konstanta, metoda nebo parametr již existují, budou přepsány.
Pokud přidaná vlastnost, konstanta, metoda nebo parametr již existují, vyhodí se výjimka.

Členy třídy lze odebrat pomocí `removeProperty()`, `removeConstant()`, `removeMethod()` nebo `removeParameter()`.

Expand Down Expand Up @@ -204,9 +203,8 @@ Interface nebo traita
Lze vytvářet rozhraní a traity:

```php
$interface = Nette\PhpGenerator\ClassType::interface('MyInterface');
$trait = Nette\PhpGenerator\ClassType::trait('MyTrait');
// nebo podobně $class = Nette\PhpGenerator\ClassType::class('MyClass');
$interface = Nette\PhpGenerator\InterfaceType('MyInterface');
$trait = Nette\PhpGenerator\TraitType('MyTrait');
```


Expand All @@ -216,7 +214,7 @@ Enums .{data-version:v3.6}
Výčty, které přináší PHP 8.1, můžete snadno vytvořit takto:

```php
$enum = Nette\PhpGenerator\ClassType::enum('Suit');
$enum = Nette\PhpGenerator\EnumType('Suit');
$enum->addCase('Clubs');
$enum->addCase('Diamonds');
$enum->addCase('Hearts');
Expand Down Expand Up @@ -292,7 +290,9 @@ Používání trait
```php
$class = new Nette\PhpGenerator\ClassType('Demo');
$class->addTrait('SmartObject');
$class->addTrait('MyTrait', ['sayHello as protected']);
$class->addTrait('MyTrait')
->addResolution('sayHello as protected')
->addComment('@use MyTrait<Foo>');
echo $class;
```

Expand Down Expand Up @@ -556,7 +556,7 @@ $class = new Nette\PhpGenerator\ClassType('Task');
$namespace->add($class);
```

Pokud třída již existuje, bude přepsána.
Pokud třída již existuje, vyhodí se výjimka.

Můžete definovat klauzule use:

Expand Down Expand Up @@ -707,9 +707,9 @@ Těla funkcí a metod jsou ve výchozím stavu prázdná. Pokud je chcete také
(vyžaduje instalaci balíčku `nikic/php-parser` a PhpGenerator verze 3.4):

```php
$class = Nette\PhpGenerator\ClassType::withBodiesFrom(MyClass::class);
$class = Nette\PhpGenerator\ClassType::from(PDO::class, withBodies: true);

$function = Nette\PhpGenerator\GlobalFunction::withBodyFrom('dump');
$function = Nette\PhpGenerator\GlobalFunction::from('dump', withBody: true);
```


Expand Down Expand Up @@ -760,10 +760,11 @@ Potřebujete na míru upravit chování printeru? Vytvořte si vlastní podědě
```php
class MyPrinter extends Nette\PhpGenerator\Printer
{
protected $indentation = "\t";
protected $linesBetweenProperties = 0;
protected $linesBetweenMethods = 1;
protected $returnTypeColon = ': ';
public int $wrapLength = 120;
public string $indentation = "\t";
public int $linesBetweenProperties = 0;
public int $linesBetweenMethods = 2;
public string $returnTypeColon = ': ';
}
```

Expand Down
29 changes: 15 additions & 14 deletions doc/en/php-generator/@home.texy
Expand Up @@ -29,7 +29,6 @@ $class
->setFinal()
->setExtends(ParentClass::class)
->addImplement(Countable::class)
->addTrait(Nette\SmartObject::class)
->addComment("Description of class.\nSecond line\n")
->addComment('@property-read Nette\Forms\Form $form');

Expand Down Expand Up @@ -141,7 +140,7 @@ Readonly properties introduced by PHP 8.1 can be marked via `setReadOnly()`.

------

If the added property, constant, method or parameter already exist, it will be overwritten.
If the added property, constant, method or parameter already exist, it throws exception.

Members can be removed using `removeProperty()`, `removeConstant()`, `removeMethod()` or `removeParameter()`.

Expand Down Expand Up @@ -204,9 +203,8 @@ Interface or Trait
You can create interfaces and traits:

```php
$interface = Nette\PhpGenerator\ClassType::interface('MyInterface');
$trait = Nette\PhpGenerator\ClassType::trait('MyTrait');
// in a similar way $class = Nette\PhpGenerator\ClassType::class('MyClass');
$interface = Nette\PhpGenerator\InterfaceType('MyInterface');
$trait = Nette\PhpGenerator\TraitType('MyTrait');
```


Expand All @@ -216,7 +214,7 @@ Enums .{data-version:v3.6}
You can easily create the enums that PHP 8.1 brings:

```php
$enum = Nette\PhpGenerator\ClassType::enum('Suit');
$enum = Nette\PhpGenerator\EnumType('Suit');
$enum->addCase('Clubs');
$enum->addCase('Diamonds');
$enum->addCase('Hearts');
Expand Down Expand Up @@ -292,7 +290,9 @@ Using Traits
```php
$class = new Nette\PhpGenerator\ClassType('Demo');
$class->addTrait('SmartObject');
$class->addTrait('MyTrait', ['sayHello as protected']);
$class->addTrait('MyTrait')
->addResolution('sayHello as protected')
->addComment('@use MyTrait<Foo>');
echo $class;
```

Expand Down Expand Up @@ -556,7 +556,7 @@ $class = new Nette\PhpGenerator\ClassType('Task');
$namespace->add($class);
```

If the class already exists, it will be overwritten.
If the class already exists, it throws exception.

You can define use-statements:

Expand Down Expand Up @@ -707,9 +707,9 @@ Function and method bodies are empty by default. If you want to load them as wel
(it requires `nikic/php-parser` to be installed and PhpGenerator version 3.4):

```php
$class = Nette\PhpGenerator\ClassType::withBodiesFrom(MyClass::class);
$class = Nette\PhpGenerator\ClassType::from(PDO::class, withBodies: true);

$function = Nette\PhpGenerator\GlobalFunction::withBodyFrom('dump');
$function = Nette\PhpGenerator\GlobalFunction::from('dump', withBody: true);
```


Expand Down Expand Up @@ -760,10 +760,11 @@ Need to customize printer behavior? Create your own by inheriting the `Printer`
```php
class MyPrinter extends Nette\PhpGenerator\Printer
{
protected $indentation = "\t";
protected $linesBetweenProperties = 0;
protected $linesBetweenMethods = 1;
protected $returnTypeColon = ': ';
public int $wrapLength = 120;
public string $indentation = "\t";
public int $linesBetweenProperties = 0;
public int $linesBetweenMethods = 2;
public string $returnTypeColon = ': ';
}
```

Expand Down

0 comments on commit d51d8ac

Please sign in to comment.