-
-
Notifications
You must be signed in to change notification settings - Fork 281
/
to-3-0.texy
130 lines (83 loc) 路 5.09 KB
/
to-3-0.texy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Migrating to Version 3.0
************************
Minimum required PHP version is 7.1.
Nette 3.0 means that you have these packages installed in version 3.0.*:
```json
"require": {
"nette/application": "3.0.*",
"nette/bootstrap": "3.0.*",
"nette/di": "3.0.*",
"nette/forms": "3.0.*",
"nette/http": "3.0.*",
"nette/security": "3.0.*",
},
```
Warning: for other packages, install the latest version that Composer will allow! They may have different versioning. Try `"*"` and see what version Composer installs.
PHP 7.1 Type Hints
------------------
Nette 3.0 uses typehints for parameters and return values of methods. If you inherit from a Nette class and override any of the methods that are now typehinted, PHP throws an error similar to this:
```
Fatal error: Declaration of Nette\Application\UI\Component::attached($presenter) must be compatible with
Nette\ComponentModel\Component::attached(Nette\ComponentModel\IComponent $obj): void
```
It is necessary to add the same typehints to the rewritten method. You can use the tool to automatically add missing typehints - "Nette TypeFixer":https://github.com/nette/type-fixer. Simply call in the project directory (where the `/vendor` and `/app` folders are):
```shell
typefixer --fix my-project-dir
```
Of course, back up everything first.
Forms
-----
All form elements are optional by default now. This change was introduced in Nette 2.4. Now you can remove `setRequired(false)`.
Be sure to update `netteForms.js` to version 3! You can install it with npm:
```shell
npm install nette-forms
```
The `ChoiceControl::$checkAllowedValues` and `MultiChoiceControl::$checkAllowedValues` has been replaced with method `checkDefaultValue()`.
Presenters & Components
-----------------------
Constructor of `Nette\ComponentModel\Component` has not been used for years and was removed in version 3.0. It's a BC break. If you call parent constructor in your component or presenter inheriting from `Nette\Application\UI\Presenter`, you must remove it.
Interface `Nette\Application\IRouter` has been changed, see "old":https://github.com/nette/application/blob/v2.4.0/src/Application/IRouter.php and "new":https://github.com/nette/routing/blob/v3.0.0/src/Routing/Router.php.
Now method `match()` returns and `constructUrl()` accepts array of parameters instead of object `Nette\Application\Request`.
Nette now checks if each signal is sent from the same origin (ie. from the same domain and subdomain). The same-origin policy is a critical security mechanism that helps reduce possible attack vectors.
If you want to allow another origins, add the annotation `@crossOrigin` to the handle method:
```php
/**
* @crossOrigin
*/
function handleXy()
{
}
```
This also applies to the submission of forms. If you want to allow submission from another origins, do it this way:
```php
$form = new Nette\Application\UI\Form;
$form->allowCrossOrigin();
```
Dependency Injection
--------------------
Support for INI files has been removed.
Direct writing of PHP code to the configuration using question marks was removed. E.g:
```neon
setup:
- "$service->onError[] = ?"([@Some\Logger, logApplicationError])
```
can be replaced by:
```neon
setup:
- '$onError[]' = [@Some\Logger, logApplicationError]
```
In your configuration files, you should use `factory: PDO(...)` instead of `class: PDO(...)`.
Tag `nette.presenter` is not used for presenters anymore.
DI for Compiler Extensions Autors
---------------------------------
While Nette 2.4 internally described each service as `Nette\DI\ServiceDefinition`, there are several definitions today, such as `Nette\DI\Definitions\ImportedDefinition` for imported or dynamic services, `Nette\DI\Definitions\FactoryDefinition` for generated inteface-based factories, `Nette\DI\Definitions\AccessorDefinition` for generated accessors, and `Nette\DI\Definitions\ServiceDefinition` for common services.
So there are several other methods to create a new definition in addition to `ContainerBuilder::addDefinition()`: `addFactoryDefinition()`, `addAccessorDefinition()`, `addImportedDefinition()`.
Others
------
The `Nette\Security\Passwords` class is now used as an object, ie the methods are no longer static.
Some methods, especially from Nette Database, such as `fetch()` or `fetchField()`, return NULL instead of FALSE in case of an error (ie when there is no other row).
Interface `Nette\Localization\ITranslator` has been changed, see "old":https://github.com/nette/utils/blob/v2.5.0/src/Utils/ITranslator.php and "new":https://github.com/nette/utils/blob/v3.0.0/src/Utils/ITranslator.php.
The `Nette\Http\UrlScript` object, which is returned for example by `Nette\Http\Request::getUrl()`, is now immutable.
In `new Nette\Http\Url('abcd')`, the `abcd` represents path, not the domain. Since version 3.0, `(new Nette\Http\Url('abcd'))->setScheme('http')` correctly generates `http:abcd` instead of the previous `http://abcd`.
Nette\Object is deprecated since Nette 2.4 and removed from Nette 3.0, however it still exists under new name `Nette\LegacyObject` (name `object` cannot be used in PHP 7.1) in "nette/deprecated":https://github.com/nette/deprecated package.
{{priority: -5}}