Skip to content

Commit 47131b6

Browse files
committed
nette/php-generator 4.1.7
1 parent 26285b6 commit 47131b6

17 files changed

+1462
-68
lines changed

php-generator/bg/@home.texy

+86-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class=perex>
55
Търсите ли инструмент за генериране на PHP код за класове, функции или цели файлове?
66

7-
- Поддържа всички най-нови функции на PHP (като enums и др.)
7+
- Поддържа всички най-нови функции на PHP (като кукички за свойства, енуми, атрибути и др.)
88
- Позволява ви лесно да променяте съществуващи класове
99
- Изход, съвместим със стила на кодиране PSR-12 / PER
1010
- Зряла, стабилна и широко използвана библиотека
@@ -634,6 +634,88 @@ class Demo
634634
```
635635

636636

637+
Куки за имоти .[#toc-property-hooks]
638+
------------------------------------
639+
640+
Можете също така да дефинирате куки за свойства (представени от класа [PropertyHook |api:Nette\PhpGenerator\PropertyHook]) за операции get и set - функция, въведена в PHP 8.4:
641+
642+
```php
643+
$class = new Nette\PhpGenerator\ClassType('Demo');
644+
$prop = $class->addProperty('firstName')
645+
->setType('string');
646+
647+
$prop->addHook('set', 'strtolower($value)')
648+
->addParameter('value')
649+
->setType('string');
650+
651+
$prop->addHook('get')
652+
->setBody('return ucfirst($this->firstName);');
653+
654+
echo $class;
655+
```
656+
657+
Това генерира:
658+
659+
```php
660+
class Demo
661+
{
662+
public string $firstName {
663+
set(string $value) => strtolower($value);
664+
get {
665+
return ucfirst($this->firstName);
666+
}
667+
}
668+
}
669+
```
670+
671+
Свойствата и куките за свойства могат да бъдат абстрактни или окончателни:
672+
673+
```php
674+
$class->addProperty('id')
675+
->setType('int')
676+
->addHook('get')
677+
->setAbstract();
678+
679+
$class->addProperty('role')
680+
->setType('string')
681+
->addHook('set', 'strtolower($value)')
682+
->setFinal();
683+
```
684+
685+
686+
Асиметрична видимост .[#toc-asymmetric-visibility]
687+
--------------------------------------------------
688+
689+
В PHP 8.4 е въведена асиметрична видимост за свойствата. Можете да зададете различни нива на достъп за четене и писане.
690+
691+
Видимостта може да бъде зададена или чрез метода `setVisibility()` с два параметъра, или чрез използване на `setPublic()`, `setProtected()` или `setPrivate()` с параметъра `mode`, който определя дали видимостта се отнася за получаване или задаване на свойството. Режимът по подразбиране е `'get'`.
692+
693+
```php
694+
$class = new Nette\PhpGenerator\ClassType('Demo');
695+
696+
$class->addProperty('name')
697+
->setType('string')
698+
->setVisibility('public', 'private'); // public for read, private for write
699+
700+
$class->addProperty('id')
701+
->setType('int')
702+
->setProtected('set'); // protected for write
703+
704+
echo $class;
705+
```
706+
707+
По този начин се генерира:
708+
709+
```php
710+
class Demo
711+
{
712+
public private(set) string $name;
713+
714+
protected(set) int $id;
715+
}
716+
```
717+
718+
637719
Пространство от имена .[#toc-namespace]
638720
---------------------------------------
639721

@@ -867,10 +949,10 @@ $property = $manipulator->inheritProperty('foo');
867949
$property->setValue('new value');
868950
```
869951

870-
Методът `implementInterface()` автоматично имплементира всички методи от дадения интерфейс във вашия клас:
952+
Методът `implement()` автоматично имплементира всички методи и свойства от дадения интерфейс или абстрактен клас:
871953

872954
```php
873-
$manipulator->implementInterface(SomeInterface::class);
955+
$manipulator->implement(SomeInterface::class);
874956
// Сега вашият клас имплементира SomeInterface и включва всички негови методи
875957
```
876958

@@ -892,6 +974,6 @@ echo $dumper->dump($var); // отпечатва ['a', 'b', 123]
892974
Таблица за съвместимост .[#toc-compatibility-table]
893975
---------------------------------------------------
894976

895-
PhpGenerator 4.0 и 4.1 са съвместими с PHP 8.0 до 8.3
977+
PhpGenerator 4.1 е съвместим с PHP 8.0 до 8.4.
896978

897979
{{leftbar: nette:@menu-topics}}

php-generator/cs/@home.texy

+86-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Generátor PHP kódu
44
<div class="perex">
55
Hledáte nástroj pro generování PHP kódu tříd, funkcí či kompletních souborů?
66

7-
- Umí všechny nejnovější vychytávky v PHP (jako enumy atd.)
7+
- Umí všechny nejnovější vychytávky v PHP (jako property hooks, enumy, atributy atd.)
88
- Umožní vám snadno modifikovat existující třídy
99
- Výstupní kód je v souladu s PSR-12 / PER coding style
1010
- Zralá, stabilní a široce používaná knihovna
@@ -634,6 +634,88 @@ class Demo
634634
```
635635

636636

637+
Property Hooks
638+
--------------
639+
640+
Pomocí property hooks (reprezentované třídou [PropertyHook|api:Nette\PhpGenerator\PropertyHook]) můžete definovat operace get a set pro vlastnosti, což je funkce zavedená v PHP 8.4:
641+
642+
```php
643+
$class = new Nette\PhpGenerator\ClassType('Demo');
644+
$prop = $class->addProperty('firstName')
645+
->setType('string');
646+
647+
$prop->addHook('set', 'strtolower($value)')
648+
->addParameter('value')
649+
->setType('string');
650+
651+
$prop->addHook('get')
652+
->setBody('return ucfirst($this->firstName);');
653+
654+
echo $class;
655+
```
656+
657+
Vygeneruje:
658+
659+
```php
660+
class Demo
661+
{
662+
public string $firstName {
663+
set(string $value) => strtolower($value);
664+
get {
665+
return ucfirst($this->firstName);
666+
}
667+
}
668+
}
669+
```
670+
671+
Property a property hooks mohou být abstraktní nebo finální:
672+
673+
```php
674+
$class->addProperty('id')
675+
->setType('int')
676+
->addHook('get')
677+
->setAbstract();
678+
679+
$class->addProperty('role')
680+
->setType('string')
681+
->addHook('set', 'strtolower($value)')
682+
->setFinal();
683+
```
684+
685+
686+
Asymetrická viditelnost
687+
-----------------------
688+
689+
PHP 8.4 zavádí asymetrickou viditelnost pro vlastnosti. Můžete nastavit různé úrovně přístupu pro čtení a zápis.
690+
691+
Viditelnost lze nastavit buď pomocí metody `setVisibility()` se dvěma parametry, nebo pomocí `setPublic()`, `setProtected()` nebo `setPrivate()` s parametrem `mode`, který určuje, zda se viditelnost vztahuje ke čtení nebo zápisu vlastnosti. Výchozí režim je `'get'`.
692+
693+
```php
694+
$class = new Nette\PhpGenerator\ClassType('Demo');
695+
696+
$class->addProperty('name')
697+
->setType('string')
698+
->setVisibility('public', 'private'); // public pro čtení, private pro zápis
699+
700+
$class->addProperty('id')
701+
->setType('int')
702+
->setProtected('set'); // protected pro zápis
703+
704+
echo $class;
705+
```
706+
707+
Vygeneruje:
708+
709+
```php
710+
class Demo
711+
{
712+
public private(set) string $name;
713+
714+
protected(set) int $id;
715+
}
716+
```
717+
718+
637719
Jmenný prostor
638720
--------------
639721

@@ -867,10 +949,10 @@ $property = $manipulator->inheritProperty('foo');
867949
$property->setValue('new value');
868950
```
869951

870-
Metoda `implementInterface()` automaticky implementuje všechny metody z daného rozhraní ve vaší třídě:
952+
Metoda `implement()` automaticky implementuje všechny metody a vlastnosti z daného rozhraní nebo abstraktní třídy ve vaší třídě:
871953

872954
```php
873-
$manipulator->implementInterface(SomeInterface::class);
955+
$manipulator->implement(SomeInterface::class);
874956
// Nyní vaše třída implementuje SomeInterface a obsahuje všechny jeho metody
875957
```
876958

@@ -892,6 +974,6 @@ echo $dumper->dump($var); // vypíše ['a', 'b', 123]
892974
Tabulka kompatibility
893975
---------------------
894976

895-
PhpGenerator 4.0 a 4.1 jsou kompatibilní s PHP 8.0 až 8.3.
977+
PhpGenerator 4.1 je kompatibilní s PHP 8.0 až 8.4.
896978

897979
{{leftbar: nette:@menu-topics}}

php-generator/de/@home.texy

+86-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ PHP-Code-Generator
44
<div class=perex>
55
Suchen Sie ein Tool, um PHP-Code für Klassen, Funktionen oder komplette Dateien zu generieren?
66

7-
- Unterstützt alle aktuellen PHP-Funktionen (wie Enums, etc.)
7+
- Unterstützt alle aktuellen PHP-Funktionen (wie Property Hooks, Enums, Attribute usw.)
88
- Ermöglicht die einfache Änderung bestehender Klassen
99
- Ausgabe in Übereinstimmung mit PSR-12 / PER-Kodierung
1010
- Ausgereifte, stabile und weit verbreitete Bibliothek
@@ -634,6 +634,88 @@ class Demo
634634
```
635635

636636

637+
Eigentumshaken .[#toc-property-hooks]
638+
-------------------------------------
639+
640+
Sie können auch Property Hooks (repräsentiert durch die Klasse [PropertyHook |api:Nette\PhpGenerator\PropertyHook]) für Get- und Set-Operationen definieren, eine Funktion, die in PHP 8.4 eingeführt wurde:
641+
642+
```php
643+
$class = new Nette\PhpGenerator\ClassType('Demo');
644+
$prop = $class->addProperty('firstName')
645+
->setType('string');
646+
647+
$prop->addHook('set', 'strtolower($value)')
648+
->addParameter('value')
649+
->setType('string');
650+
651+
$prop->addHook('get')
652+
->setBody('return ucfirst($this->firstName);');
653+
654+
echo $class;
655+
```
656+
657+
Dies erzeugt:
658+
659+
```php
660+
class Demo
661+
{
662+
public string $firstName {
663+
set(string $value) => strtolower($value);
664+
get {
665+
return ucfirst($this->firstName);
666+
}
667+
}
668+
}
669+
```
670+
671+
Eigenschaften und Eigenschaftshaken können abstrakt oder endgültig sein:
672+
673+
```php
674+
$class->addProperty('id')
675+
->setType('int')
676+
->addHook('get')
677+
->setAbstract();
678+
679+
$class->addProperty('role')
680+
->setType('string')
681+
->addHook('set', 'strtolower($value)')
682+
->setFinal();
683+
```
684+
685+
686+
Asymmetrische Sichtbarkeit .[#toc-asymmetric-visibility]
687+
--------------------------------------------------------
688+
689+
PHP 8.4 führt eine asymmetrische Sichtbarkeit für Eigenschaften ein. Sie können unterschiedliche Zugriffsebenen für das Lesen und Schreiben festlegen.
690+
691+
Die Sichtbarkeit kann entweder mit der Methode `setVisibility()` mit zwei Parametern oder mit `setPublic()`, `setProtected()` oder `setPrivate()` mit dem Parameter `mode` eingestellt werden, der angibt, ob die Sichtbarkeit für das Abrufen oder Setzen der Eigenschaft gilt. Der Standardmodus ist `'get'`.
692+
693+
```php
694+
$class = new Nette\PhpGenerator\ClassType('Demo');
695+
696+
$class->addProperty('name')
697+
->setType('string')
698+
->setVisibility('public', 'private'); // public for read, private for write
699+
700+
$class->addProperty('id')
701+
->setType('int')
702+
->setProtected('set'); // protected for write
703+
704+
echo $class;
705+
```
706+
707+
Dies erzeugt:
708+
709+
```php
710+
class Demo
711+
{
712+
public private(set) string $name;
713+
714+
protected(set) int $id;
715+
}
716+
```
717+
718+
637719
Namensraum .[#toc-namespace]
638720
----------------------------
639721

@@ -867,10 +949,10 @@ $property = $manipulator->inheritProperty('foo');
867949
$property->setValue('new value');
868950
```
869951

870-
Die Methode `implementInterface()` implementiert automatisch alle Methoden der angegebenen Schnittstelle in Ihrer Klasse:
952+
Die Methode `implement()` implementiert automatisch alle Methoden und Eigenschaften der angegebenen Schnittstelle oder abstrakten Klasse:
871953

872954
```php
873-
$manipulator->implementInterface(SomeInterface::class);
955+
$manipulator->implement(SomeInterface::class);
874956
// Ihre Klasse implementiert nun SomeInterface und enthält alle seine Methoden
875957
```
876958

@@ -892,6 +974,6 @@ echo $dumper->dump($var); // druckt ['a', 'b', 123]
892974
Kompatibilitätstabelle .[#toc-compatibility-table]
893975
--------------------------------------------------
894976

895-
PhpGenerator 4.0 und 4.1 sind kompatibel mit PHP 8.0 bis 8.3
977+
PhpGenerator 4.1 ist kompatibel mit PHP 8.0 bis 8.4.
896978

897979
{{leftbar: nette:@menu-topics}}

0 commit comments

Comments
 (0)