Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction of typo #1025

Closed
wants to merge 47 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ad29ee0
di: added Global State and Singletons
dg Mar 1, 2023
33a5e79
typo
dg Mar 13, 2023
d6d2555
```bash -> shell
dg Mar 14, 2023
44cd690
composer: improved content
dg Mar 14, 2023
38c3fa9
contributing/documentation: improved
dg Mar 20, 2023
2af8489
contributing/code: rewritten
dg Apr 8, 2023
bd86fe9
presenter Homepage -> Home
dg Mar 14, 2023
be57009
added new page 'installation'
dg Mar 15, 2023
bf945e6
home restruct
dg Mar 16, 2023
338d8c5
home: added sponsor
dg Apr 8, 2023
24ba949
quickstart: reference to installation
dg Mar 16, 2023
0b82ebb
added best-practices:lets-create-contact-form (removed pla)
dg Mar 7, 2023
925fb1a
packages: removed installation info
dg Mar 17, 2023
00a4f67
typo in Latte (#970)
janvalentik Mar 20, 2023
e6ede1d
di/passing-dependencies: better class & variables naming
dg Mar 21, 2023
4dfe968
di/passing-dependencies: highlighting inject info
dg Mar 21, 2023
73b3c27
di/passing-dependencies: added constructor hell
dg Mar 21, 2023
ef53cef
di: added FAQ
dg Mar 1, 2023
3d3fb3e
typo (#972)
berbeflo Mar 23, 2023
ca516be
Typo (#973)
johny-patera Mar 25, 2023
c54b483
php-generator: fixes
dg Mar 23, 2023
54fc2ec
persistent parameters: improved info
dg Mar 27, 2023
5cd2752
form reuse: improved
dg Mar 27, 2023
2106763
retranslated by GPT-4 (only EN version)
dg Mar 28, 2023
71729a1
inject injection: improved
dg Mar 29, 2023
89b7224
latte: added perex to cookbook
dg Apr 4, 2023
2f21671
tracy: improved
dg Apr 5, 2023
ea62e48
tracy: Adding a line to the Tracy activation code sample (#991)
mildabre Apr 7, 2023
6f4dee1
form: improvements (#995)(#996)(#997)(#998)
mildabre Apr 7, 2023
3decfab
application: improvements (#990)(#993)(#999)(#1002)
mildabre Apr 7, 2023
9861824
wording (#1000) (#1001)
mildabre Apr 7, 2023
9953432
latte: added {formContainer}
dg Apr 9, 2023
156353a
typo (#1004)
mildabre Apr 11, 2023
f0ba9e0
troubleshooting: testing .htaccess / mod_rewrite
dg Apr 14, 2023
ae6153c
10-reasons-why-nette: rewritten
dg Apr 16, 2023
7e781cb
latte: added "why use"
dg Apr 18, 2023
34c63d3
Typo (#1008)
diegosardina Apr 24, 2023
e89fbb2
Typos. (#1010)
radekdostal Apr 26, 2023
b17c6e8
application: improved leftmenu
dg May 14, 2023
3909369
typo (cs) (#1013)
Dzardys May 17, 2023
3302b2e
added: AVIF support (#1011)
jhabaj May 22, 2023
4be96ac
php-generator: better info about PSR
dg May 22, 2023
b64b740
coding-standard: added image of signature/body separation
dg May 22, 2023
60bf5cd
migration guide for Nette 4.0 [WIP]
dg Feb 10, 2023
0956ea5
assistant wip
dg Apr 19, 2023
e83d416
latte: improved {do} & {php}
dg May 31, 2023
f9e2dcb
Correction of typo
mildabre Jul 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
di/passing-dependencies: better class & variables naming
  • Loading branch information
dg committed May 29, 2023
commit e6ede1d385ca8f4d0a33ec8fe3e2d08f5db77b2e
42 changes: 21 additions & 21 deletions dependency-injection/bg/passing-dependencies.texy
Original file line number Diff line number Diff line change
@@ -21,17 +21,17 @@
Зависимостите се предават като аргументи на конструктора при създаването на обекта:

```php
class MyService
class MyClass
{
private Cache $cache;

public function __construct(Cache $service)
public function __construct(Cache $cache)
{
$this->cache = $service;
$this->cache = $cache;
}
}

$service = new MyService($cache);
$obj = new MyClass($cache);
```

Тази форма е полезна за задължителни зависимости, които са абсолютно необходими за функционирането на класа, тъй като без тях не може да се създаде инстанция.
@@ -40,10 +40,10 @@ $service = new MyService($cache);

```php
// PHP 8.0
class MyService
class MyClass
{
public function __construct(
private Cache $service,
private Cache $cache,
) {
}
}
@@ -53,10 +53,10 @@ class MyService

```php
// PHP 8.1
class MyService
class MyClass
{
public function __construct(
private readonly Cache $service,
private readonly Cache $cache,
) {
}
}
@@ -71,35 +71,35 @@ class MyService
Зависимостите се предават чрез извикване на метод, който ги съхранява в частно свойство. Обичайната конвенция за именуване на тези методи е `set*()`, затова те се наричат setters.

```php
class MyService
class MyClass
{
private Cache $cache;

public function setCache(Cache $service): void
public function setCache(Cache $cache): void
{
$this->cache = $service;
$this->cache = $cache;
}
}

$service = new MyService;
$service->setCache($cache);
$obj = new MyClass;
$obj->setCache($cache);
```

Този метод е полезен за незадължителни зависимости, които не са необходими за функционирането на класа, тъй като не е гарантирано, че обектът действително ще ги получи (т.е. че потребителят ще извика метода).

В същото време този метод позволява многократно извикване на setter за промяна на зависимостта. Ако това не е желателно, добавете проверка към метода или, от версия PHP 8.1, маркирайте свойството `$cache` с флага `readonly`.

```php
class MyService
class MyClass
{
private Cache $cache;

public function setCache(Cache $service): void
public function setCache(Cache $cache): void
{
if ($this->cache) {
throw new RuntimeException('The dependency has already been set');
}
$this->cache = $service;
$this->cache = $cache;
}
}
```
@@ -109,7 +109,7 @@ class MyService
```neon
services:
-
create: MyService
create: MyClass
setup:
- setCache
```
@@ -121,13 +121,13 @@ services:
Зависимостите се предават директно на свойството:

```php
class MyService
class MyClass
{
public Cache $cache;
}

$service = new MyService;
$service->cache = $cache;
$obj = new MyClass;
$obj->cache = $cache;
```

Този метод се счита за неприемлив, тъй като свойството трябва да бъде декларирано като `public`. Следователно нямаме контрол върху това дали предадената зависимост действително има зададения тип (това беше вярно преди PHP 7.4) и губим възможността да реагираме на новоназначената зависимост със собствен код, например за да предотвратим последващи промени. В същото време свойството става част от публичния интерфейс на класа, което може да е нежелателно.
@@ -137,7 +137,7 @@ $service->cache = $cache;
```neon
services:
-
create: MyService
create: MyClass
setup:
- $cache = @\Cache
```
42 changes: 21 additions & 21 deletions dependency-injection/cs/passing-dependencies.texy
Original file line number Diff line number Diff line change
@@ -21,17 +21,17 @@ Předávání konstruktorem
Závislosti jsou předávány v okamžiku vytváření objektu jako argumenty konstruktoru:

```php
class MyService
class MyClass
{
private Cache $cache;

public function __construct(Cache $service)
public function __construct(Cache $cache)
{
$this->cache = $service;
$this->cache = $cache;
}
}

$service = new MyService($cache);
$obj = new MyClass($cache);
```

Tato forma je vhodná pro povinné závislosti, které třída nezbytně potřebuje ke své funkci, neboť bez nich nepůjde instanci vytvořit.
@@ -40,10 +40,10 @@ Od PHP 8.0 můžeme použít kratší formu zápisu ([constructor property promo

```php
// PHP 8.0
class MyService
class MyClass
{
public function __construct(
private Cache $service,
private Cache $cache,
) {
}
}
@@ -53,10 +53,10 @@ Od PHP 8.1 lze proměnnou označit příznakem `readonly`, který deklaruje, že

```php
// PHP 8.1
class MyService
class MyClass
{
public function __construct(
private readonly Cache $service,
private readonly Cache $cache,
) {
}
}
@@ -71,35 +71,35 @@ Předávání setterem
Závislosti jsou předávány voláním metody, která je uloží do privátní proměnné. Obvyklou konvencí pojmenování těchto metod je tvar `set*()`, proto se jim říká settery.

```php
class MyService
class MyClass
{
private Cache $cache;

public function setCache(Cache $service): void
public function setCache(Cache $cache): void
{
$this->cache = $service;
$this->cache = $cache;
}
}

$service = new MyService;
$service->setCache($cache);
$obj = new MyClass;
$obj->setCache($cache);
```

Tento způsob je vhodný pro nepovinné závislosti, které nejsou pro funkci třídy nezbytné, neboť není garantováno, že objekt závislost skutečně dostane (tj. že uživatel metodu zavolá).

Zároveň tento způsob připouští volat setter opakovaně a závislost tak měnit. Pokud to není žádoucí, přidáme do metody kontrolu, nebo od PHP 8.1 označíme property `$cache` příznakem `readonly`.

```php
class MyService
class MyClass
{
private Cache $cache;

public function setCache(Cache $service): void
public function setCache(Cache $cache): void
{
if ($this->cache) {
throw new RuntimeException('The dependency has already been set');
}
$this->cache = $service;
$this->cache = $cache;
}
}
```
@@ -109,7 +109,7 @@ Volání setteru definujeme v konfiguraci DI kontejneru v [klíči setup |servic
```neon
services:
-
create: MyService
create: MyClass
setup:
- setCache
```
@@ -121,13 +121,13 @@ Nastavením proměnné
Závislosti jsou předávány zapsáním přímo do členské proměnné:

```php
class MyService
class MyClass
{
public Cache $cache;
}

$service = new MyService;
$service->cache = $cache;
$obj = new MyClass;
$obj->cache = $cache;
```

Tento způsob se považuje za nevhodný, protože členská proměnná musí být deklarována jako `public`. A tudíž nemáme kontrolu nad tím, že předaná závislost bude skutečně daného typu (platilo před PHP 7.4) a přicházíme o možnost reagovat na nově přiřazenou závislost vlastním kódem, například zabránit následné změně. Zároveň se proměnná stává součástí veřejného rozhraní třídy, což nemusí být žádoucí.
@@ -137,7 +137,7 @@ Nastavení proměnné definujeme v konfiraci DI kontejneru v [sekci setup |servi
```neon
services:
-
create: MyService
create: MyClass
setup:
- $cache = @\Cache
```
42 changes: 21 additions & 21 deletions dependency-injection/de/passing-dependencies.texy
Original file line number Diff line number Diff line change
@@ -21,17 +21,17 @@ Konstruktor-Injektion .[#toc-constructor-injection]
Abhängigkeiten werden als Argumente an den Konstruktor übergeben, wenn das Objekt erstellt wird:

```php
class MyService
class MyClass
{
private Cache $cache;

public function __construct(Cache $service)
public function __construct(Cache $cache)
{
$this->cache = $service;
$this->cache = $cache;
}
}

$service = new MyService($cache);
$obj = new MyClass($cache);
```

Diese Form ist nützlich für obligatorische Abhängigkeiten, die die Klasse unbedingt benötigt, um zu funktionieren, da ohne sie die Instanz nicht erstellt werden kann.
@@ -40,10 +40,10 @@ Seit PHP 8.0 können wir eine kürzere Form der Notation verwenden ([constructor

```php
// PHP 8.0
class MyService
class MyClass
{
public function __construct(
private Cache $service,
private Cache $cache,
) {
}
}
@@ -53,10 +53,10 @@ Seit PHP 8.1 kann eine Eigenschaft mit einem Flag `readonly` markiert werden, da

```php
// PHP 8.1
class MyService
class MyClass
{
public function __construct(
private readonly Cache $service,
private readonly Cache $cache,
) {
}
}
@@ -71,35 +71,35 @@ Setter-Injektion .[#toc-setter-injection]
Abhängigkeiten werden durch den Aufruf einer Methode übergeben, die sie in einer privaten Eigenschaft speichert. Die übliche Namenskonvention für diese Methoden ist die Form `set*()`, weshalb sie auch Setter genannt werden.

```php
class MyService
class MyClass
{
private Cache $cache;

public function setCache(Cache $service): void
public function setCache(Cache $cache): void
{
$this->cache = $service;
$this->cache = $cache;
}
}

$service = new MyService;
$service->setCache($cache);
$obj = new MyClass;
$obj->setCache($cache);
```

Diese Methode ist nützlich für optionale Abhängigkeiten, die für die Funktion der Klasse nicht notwendig sind, da nicht garantiert ist, dass das Objekt sie tatsächlich erhält (d. h. dass der Benutzer die Methode aufruft).

Gleichzeitig ermöglicht diese Methode, dass der Setter wiederholt aufgerufen werden kann, um die Abhängigkeit zu ändern. Wenn dies nicht erwünscht ist, fügen Sie der Methode ein Häkchen hinzu, oder markieren Sie ab PHP 8.1 die Eigenschaft `$cache` mit dem Flag `readonly`.

```php
class MyService
class MyClass
{
private Cache $cache;

public function setCache(Cache $service): void
public function setCache(Cache $cache): void
{
if ($this->cache) {
throw new RuntimeException('The dependency has already been set');
}
$this->cache = $service;
$this->cache = $cache;
}
}
```
@@ -109,7 +109,7 @@ Der Setter-Aufruf wird in der DI-Container-Konfiguration im [Abschnitt setup |se
```neon
services:
-
create: MyService
create: MyClass
setup:
- setCache
```
@@ -121,13 +121,13 @@ Property Injection .[#toc-property-injection]
Abhängigkeiten werden direkt an die Eigenschaft übergeben:

```php
class MyService
class MyClass
{
public Cache $cache;
}

$service = new MyService;
$service->cache = $cache;
$obj = new MyClass;
$obj->cache = $cache;
```

Diese Methode wird als ungeeignet angesehen, da die Eigenschaft als `public` deklariert werden muss. Daher haben wir keine Kontrolle darüber, ob die übergebene Abhängigkeit tatsächlich vom angegebenen Typ ist (dies war vor PHP 7.4 der Fall), und wir verlieren die Möglichkeit, auf die neu zugewiesene Abhängigkeit mit unserem eigenen Code zu reagieren, um zum Beispiel nachträgliche Änderungen zu verhindern. Gleichzeitig wird die Eigenschaft Teil der öffentlichen Schnittstelle der Klasse, was möglicherweise nicht wünschenswert ist.
@@ -137,7 +137,7 @@ Die Einstellung der Variablen wird in der Konfiguration des DI-Containers im [Ab
```neon
services:
-
create: MyService
create: MyClass
setup:
- $cache = @\Cache
```
Loading