Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
Přechod na verzi 3.0 | ||
******************** | ||
|
||
Minimální požadovaná verze PHP je 7.1. | ||
|
||
Aktualizujte vždy postupně, takže nikoliv z Nette 2.3 na 3.0, ale nejprve na 2.4 a poté na 3.0. | ||
|
||
Před testováním nebo nasazováním doporučujeme nejprve vypnout hlášení chyb `E_USER_DEPRECATED` a povolit jej, až když vše bude fungovat: | ||
|
||
```php | ||
$configurator->enableDebugger(); | ||
error_reporting(~E_USER_DEPRECATED); // note ~ before E_USER_DEPRECATED | ||
``` | ||
|
||
PHP 7.1 type hints | ||
------------------ | ||
|
||
Nette 3.0 používá typehinty pro parametry a návratové hodnoty metod. Pokud dědíte od třídy z Nette a přepisujete některou z metod, u kterých jsou nyní typehinty, vyhodí PHP chybu podobnou této: | ||
|
||
``` | ||
Fatal error: Declaration of Nette\Application\UI\Component::attached($presenter) must be compatible with | ||
Nette\ComponentModel\Component::attached(Nette\ComponentModel\IComponent $obj): void | ||
``` | ||
|
||
Je potřeba stejné typehinty doplnit i do přepisované metody. K automatickému doplnění chybějících typehintů můžete použít nástroj "Nette TypeFixer":https://github.com/nette/type-fixer. Jednoduše ho zavoláte v projektu (tedy adresáři v němž jsou složky `/vendor` a `/app`): | ||
|
||
``` | ||
typefixer --fix my-project-dir | ||
``` | ||
|
||
Samozřejmě předtím vše raději zazálohujte. | ||
|
||
|
||
Formuláře | ||
--------- | ||
|
||
Všechny prvky formuláře jsou nyní ve výchozím nastavení volitelné. Tato změna byla zavedena v Nette 2.4. Nyní můžete odstranit `setRequired(false)`. | ||
|
||
Nezapomeňte aktualizovat soubor `netteForms.js` na verzi 3! Můžete jej nainstalovat pomocí npm: | ||
|
||
``` | ||
npm install nette-forms | ||
``` | ||
|
||
Proměnné `ChoiceControl::$checkAllowedValues` a `MultiChoiceControl::$checkAllowedValues` byly nahrazeny metodou `checkDefaultValue()`. | ||
|
||
|
||
Presentery & komponenty | ||
----------------------- | ||
|
||
Konstruktor `Nette\ComponentModel\Component` nebyl roky používán a byl odstraněn ve verzi 3.0. Je to BC break. Pokud voláte rodičovský konstruktor ve vaší komponentě nebo presenteru zděděném od `Nette\Application\UI\Presenter`, musíte volání odstranit. | ||
|
||
Rozhraní `Nette\Application\IRouter` bylo změněno, viz "původní":https://github.com/nette/application/blob/v2.4.0/src/Application/IRouter.php a "nové":https://github.com/nette/routing/blob/v3.0.0/src/Routing/Router.php. | ||
Nyní metoda `match()` vrací a `constructUrl()` přijímá pole parameterů namísto objektu `Nette\Application\Request`. | ||
|
||
Nette nyní zkontroluje, zda každý "signal":https://doc.nette.org/en/3.0/components#toc-signal-subrequest je odeslán ze stejného *originu* (tj. ze stejné domény a subdomény). Same-origin policy je kritický bezpečnostní mechanismus, který pomáhá redukovat možné vektory útoku. | ||
Pokud chcete povolit další *původy*, přidejte k metodě obsluhující signál anotaci `@crossOrigin`: | ||
|
||
```php | ||
/** | ||
* @crossOrigin | ||
*/ | ||
function handleXy() | ||
{ | ||
} | ||
``` | ||
|
||
To platí také pro předkládání formulářů. Pokud chcete povolit odesílání z jiného *původu*, postupujte takto: | ||
|
||
```php | ||
$form = new Nette\Application\UI\Form; | ||
$form->allowCrossOrigin(); | ||
``` | ||
|
||
|
||
Dependency Injection | ||
-------------------- | ||
|
||
Byla ostraněna podpora INI souborů. | ||
|
||
Byl odstraněn přímý zápis PHP kódu do konfigurace pomocí otazníků. Např: | ||
|
||
```neon | ||
setup: | ||
- "$service->onError[] = ?"([@Some\Logger, logApplicationError]) | ||
``` | ||
|
||
lze nahradit za: | ||
|
||
```neon | ||
setup: | ||
- '$service->onError[]' = [@Some\Logger, logApplicationError] | ||
``` | ||
|
||
V konfiguračních souborech byste místo `class: PDO(...)` měli použít `factory: PDO(...)`. | ||
|
||
Tag `nette.presenter` se pro presentery už nepoužívá. | ||
|
||
|
||
DI pro tvůrce Compiler Extensions | ||
--------------------------------- | ||
|
||
Zatímco v Nette 2.4 interně popisoval každou službu objekt `Nette\DI\ServiceDefinition`, dnes existuje definic vícero, například `Nette\DI\Definitions\ImportedDefinition ` pro importované neboli dynamic služby, `Nette\DI\Definitions\FactoryDefinition` | ||
pro generované továrničky na základě inteface, `Nette\DI\Definitions\AccessorDefinition` pro generované accessory a `Nette\DI\Definitions\ServiceDefinition` pro běžné služby. | ||
|
||
Pro vytvoření nové definice tak existuje kromě `ContainerBuilder::addDefinition()` několik dalších metod: `addFactoryDefinition()`, `addAccessorDefinition()`, `addImportedDefinition()`. | ||
|
||
|
||
Další | ||
----- | ||
|
||
Třída `Nette\Security\Passwords` se nyní používá jako objekt, tj. metody již nejsou statické. | ||
|
||
Některé metody zejména z Nette Database, jako `fetch()` nebo `fetchField()`, v případě chyby (tj. když není další záznam) vracejí NULL místo FALSE. | ||
|
||
Rozhraní `Nette\Localization\ITranslator` bylo změněno, viz "původní":https://github.com/nette/utils/blob/v2.5.0/src/Utils/ITranslator.php a "nové":https://github.com/nette/utils/blob/v3.0.0/src/Utils/ITranslator.php. | ||
|
||
Objekt `Nette\Http\UrlScript`, který vrací třeba `Nette\Http\Request::getUrl()`, je nyní immutable. | ||
|
||
`Nette\Object` je zastaralý od Nette 2.4 a odstraněný v Nette 3.0, stále však existuje pod novým názvem `Nette\LegacyObject` (jméno `object` nelze používat od PHP 7.1) v balíčku "nette/deprecated":https://github.com/nette/deprecated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
Migrating to Version 3.0 | ||
************************ | ||
|
||
Minimum required PHP version is 7.1. | ||
|
||
Always update gradually, so not from Nette 2.3 to 3.0, but first to 2.4 and then to 3.0. | ||
|
||
Before testing we recommend to disable reporting `E_USER_DEPRECATED` and allow it when everything will work: | ||
|
||
```php | ||
$configurator->enableDebugger(); | ||
error_reporting(~E_USER_DEPRECATED); // note ~ before E_USER_DEPRECATED | ||
``` | ||
|
||
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): | ||
|
||
``` | ||
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: | ||
|
||
``` | ||
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":https://doc.nette.org/en/3.0/components#toc-signal-subrequest 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: | ||
- '$service->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 retured for example by `Nette\Http\Request::getUrl()`, is now immutable. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters