Skip to content

Commit 2a04889

Browse files
committed
improved smartobject
1 parent eb33028 commit 2a04889

16 files changed

+50
-50
lines changed

utils/bg/smartobject.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Foo extends Nette\Object
158158

159159
$obj = new Foo;
160160
$reflection = $obj->getReflection();
161-
$reflection->getAnnotation('author'); // връща 'John Doe
161+
$reflection->getAnnotation('author'); // връща 'John Doe'
162162
```
163163

164164
От версия 8.0 на PHP вече е възможен достъп до метаинформация под формата на атрибути:
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```

utils/cs/smartobject.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Foo extends Nette\Object
158158

159159
$obj = new Foo;
160160
$reflection = $obj->getReflection();
161-
$reflection->getAnnotation('author'); // vrátí 'John Doe
161+
$reflection->getAnnotation('author'); // vrátí 'John Doe'
162162
```
163163

164164
Od PHP 8.0 je možné přistupovat k metainformacím v podobě atributů:
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```

utils/de/smartobject.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Foo extends Nette\Object
158158

159159
$obj = new Foo;
160160
$reflection = $obj->getReflection();
161-
$reflection->getAnnotation('author'); // returns 'John Doe
161+
$reflection->getAnnotation('author'); // returns 'John Doe'
162162
```
163163

164164
Seit PHP 8.0 ist es möglich, auf Metainformationen in Form von Attributen zuzugreifen:
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```

utils/el/smartobject.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Foo extends Nette\Object
158158

159159
$obj = new Foo;
160160
$reflection = $obj->getReflection();
161-
$reflection->getAnnotation('author'); // returns 'John Doe
161+
$reflection->getAnnotation('author'); // returns 'John Doe'
162162
```
163163

164164
Από την PHP 8.0, είναι δυνατή η πρόσβαση σε μετα-πληροφορίες με τη μορφή χαρακτηριστικών:
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```

utils/en/smartobject.texy

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SmartObject
22
***********
33

44
.[perex]
5-
SmartObject used to fix objects behavior in many ways, but today's PHP already includes most of these improvements natively. However, it still adds support for *property*.
5+
SmartObject used to fix objects behavior in many ways, but today's PHP already includes most of these improvements natively. However, it still adds support for *properties*.
66

77

88
Installation:
@@ -65,16 +65,16 @@ echo $circle->visible; // calls isVisible()
6565
Properties are primarily "syntactic sugar"((syntactic sugar)), which is intended to make the programmer's life sweeter by simplifying the code. If you don't want them, you don't have to use them.
6666

6767

68-
A Look into the History
69-
=======================
68+
A Glimpse into History
69+
======================
7070

71-
SmartObject used to fix object behavior in many ways, but today's PHP already includes most of the improvements natively. The following is a nostalgic look back in history and a reminder of how things have evolved.
71+
SmartObject used to refine the behavior of objects in numerous ways, but today's PHP already incorporates most of these enhancements natively. The following text is a nostalgic look back at history, reminding us of how things evolved.
7272

73-
From the beginning, the PHP object model suffered from a number of serious flaws and inefficiencies. This was the reason for the creation of the `Nette\Object` class (in 2007), which attempted to remedy them and improve the experience of using PHP. It was enough for other classes to inherit from it, and gain the benefits it brought. When PHP 5.4 came with trait support, the `Nette\Object` class was replaced by `Nette\SmartObject`. Thus, it was no longer necessary to inherit from a common ancestor. In addition, trait could be used in classes that already inherited from another class. The final end of `Nette\Object` came with the release of PHP 7.2, which forbade classes to be named `Object`.
73+
From its inception, PHP's object model suffered from a myriad of serious shortcomings and deficiencies. This led to the creation of the `Nette\Object` class (in 2007), which aimed to rectify these issues and enhance the comfort of using PHP. All that was needed was for other classes to inherit from it, and they would gain the benefits it offered. When PHP 5.4 introduced support for traits, the `Nette\Object` class was replaced by the `Nette\SmartObject` trait. This eliminated the need to inherit from a common ancestor. Moreover, the trait could be used in classes that already inherited from another class. The definitive end of `Nette\Object` came with the release of PHP 7.2, which prohibited classes from being named `Object`.
7474

75-
As PHP development went on, the object model and language capabilities were improved. The individual functions of the `SmartObject` class became redundant. Since the release of PHP 8.2, the only feature that remains that is not yet directly supported in PHP is the ability to use so-called [properties |#Properties, Getters and Setters].
75+
As PHP development continued, its object model and language capabilities improved. Various functions of the `SmartObject` class became redundant. Since the release of PHP 8.2, there remains only one feature not directly supported in PHP: the ability to use so-called [properties|#Properties, getters, and setters].
7676

77-
What features did `Nette\Object` and `Nette\Object` once offer? Here is an overview. (The examples use the `Nette\Object` class, but most of the properties also apply to the `Nette\SmartObject` trait.)
77+
What features did `Nette\Object` and, by extension, `Nette\SmartObject` offer? Here's an overview. (In the examples, the `Nette\Object` class is used, but most features also apply to the `Nette\SmartObject` trait).
7878

7979

8080
Inconsistent Errors
@@ -87,14 +87,14 @@ $obj->undeclared = 1; // passes silently without reporting
8787
$obj->unknownMethod(); // Fatal error (not catchable by try/catch)
8888
```
8989

90-
Fatal error terminated the application without any possibility to react. Silently writing to non-existent members without warning could lead to serious errors that were difficult to detect. `Nette\Object` All of these cases were caught and an exception `MemberAccessException` was thrown.
90+
A fatal error would terminate the application without any chance of response. Silently writing to non-existent members without warning could lead to serious errors that were hard to detect. `Nette\Object` caught all these cases and threw a `MemberAccessException` exception.
9191

9292
```php
93-
echo $obj->undeclared; // throw Nette\MemberAccessException
94-
$obj->undeclared = 1; // throw Nette\MemberAccessException
95-
$obj->unknownMethod(); // throw Nette\MemberAccessException
93+
echo $obj->undeclared; // throws Nette\MemberAccessException
94+
$obj->undeclared = 1; // throws Nette\MemberAccessException
95+
$obj->unknownMethod(); // throws Nette\MemberAccessException
9696
```
97-
Since PHP 7.0, PHP no longer causes not catchable fatal errors, and accessing undeclared members has been a bug since PHP 8.2.
97+
From PHP version 7.0 onwards, uncatchable fatal errors no longer occur, and accessing undeclared members becomes an error from PHP 8.2.
9898

9999

100100
Did you mean?
@@ -110,16 +110,16 @@ class Foo extends Nette\Object
110110
}
111111

112112
$foo = Foo::form($var);
113-
// throw Nette\MemberAccessException
113+
// throws Nette\MemberAccessException
114114
// "Call to undefined static method Foo::form(), did you mean from()?"
115115
```
116116

117-
Today's PHP may not have any form of "did you mean?", but [Tracy |tracy:] adds this addendum to errors. And it can even [fix |tracy:open-files-in-ide#toc-demos] such errors itself.
117+
While today's PHP doesn't have a "did you mean?" feature, this phrase can be added to errors by [Tracy|tracy:]. It can even [auto-correct such errors|tracy:open-files-in-ide#toc-demos].
118118

119119

120-
Extension methods
120+
Extension Methods
121121
-----------------
122-
Inspired by extension methods from C#. They gave the possibility to add new methods to existing classes. For example, you could add the `addDateTime()` method to a form to add your own DateTimePicker.
122+
Inspired by the extension methods from the C# language, they provided the ability to add new methods to existing classes. For instance, you could add a `addDateTime()` method to a form, which would introduce a custom DateTimePicker.
123123

124124
```php
125125
Form::extensionMethod(
@@ -131,15 +131,15 @@ $form = new Form;
131131
$form->addDateTime('date');
132132
```
133133

134-
Extension methods proved to be impractical because their names was not autocompleted by editors, instead they reported that the method did not exist. Therefore, their support was discontinued.
134+
Extension methods turned out to be impractical because their names were not suggested by editors; on the contrary, they reported that the method did not exist. Therefore, their support was discontinued.
135135

136136

137-
Getting the Class Name
138-
----------------------
137+
Determining the Class Name
138+
--------------------------
139139

140140
```php
141141
$class = $obj->getClass(); // using Nette\Object
142-
$class = $obj::class; // since PHP 8.0
142+
$class = $obj::class; // from PHP 8.0
143143
```
144144

145145

@@ -158,7 +158,7 @@ class Foo extends Nette\Object
158158

159159
$obj = new Foo;
160160
$reflection = $obj->getReflection();
161-
$reflection->getAnnotation('author'); // returns 'John Doe
161+
$reflection->getAnnotation('author'); // returns 'John Doe'
162162
```
163163

164164
As of PHP 8.0, it is possible to access meta-information in the form of attributes:
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```
@@ -229,7 +229,7 @@ foreach ($this->onChange as $callback) {
229229
}
230230
```
231231

232-
For the sake of clarity we recommend to avoid the magic method `$this->onChange()`. A practical substitute is the [Nette\Utils\Arrays::invoke |arrays#invoke] function:
232+
For clarity, we recommend avoiding the magic method `$this->onChange()`. A practical alternative is the [Nette\Utils\Arrays::invoke |arrays#invoke] function:
233233

234234
```php
235235
Nette\Utils\Arrays::invoke($this->onChange, $this, $radius);

utils/es/smartobject.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Foo extends Nette\Object
158158

159159
$obj = new Foo;
160160
$reflection = $obj->getReflection();
161-
$reflection->getAnnotation('author'); // returns 'John Doe
161+
$reflection->getAnnotation('author'); // returns 'John Doe'
162162
```
163163

164164
A partir de PHP 8.0, es posible acceder a meta-información en forma de atributos:
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```

utils/fr/smartobject.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Foo extends Nette\Object
158158

159159
$obj = new Foo;
160160
$reflection = $obj->getReflection();
161-
$reflection->getAnnotation('author'); // returns 'John Doe
161+
$reflection->getAnnotation('author'); // returns 'John Doe'
162162
```
163163

164164
Depuis PHP 8.0, il est possible d'accéder aux méta-informations sous forme d'attributs :
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```

utils/hu/smartobject.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Foo extends Nette\Object
158158

159159
$obj = new Foo;
160160
$reflection = $obj->getReflection();
161-
$reflection->getAnnotation('author'); // visszaadja 'John Doe'.
161+
$reflection->getAnnotation('author'); // visszaadja 'John Doe'
162162
```
163163

164164
A PHP 8.0-tól kezdve a metainformációkat attribútumok formájában is elérhetjük:
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```

utils/it/smartobject.texy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```

utils/pl/smartobject.texy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class Foo extends Nette\Object
158158

159159
$obj = new Foo;
160160
$reflection = $obj->getReflection();
161-
$reflection->getAnnotation('author'); // vrátí 'John Doe
161+
$reflection->getAnnotation('author'); // vrátí 'John Doe'
162162
```
163163

164164
Od PHP 8.0 możliwy jest dostęp do metainformacji w postaci atrybutów:
@@ -216,7 +216,7 @@ class Circle extends Nette\Object
216216
public function setRadius(float $radius): void
217217
{
218218
$this->onChange($this, $radius);
219-
$this->radius = $radius
219+
$this->radius = $radius;
220220
}
221221
}
222222
```

0 commit comments

Comments
 (0)