Nette DI 3.1: transition release

about a year ago by David Grudl  

Transition releases do not bring new features, but are intended to point out via notices anything that will work differently in the new major version and to advise you on how to update. This was the case for example with Latte 2.11 or the newly released Nette DI 3.1.

The first change fixes the autowiring behavior, which no longer automatically passes null to nullable parameters without default value so the argument needs to be explicitly specified (or the default value needs to be added):

class Foo
{
	public function __construct(?string $foo)
	{}
}

Configuration:

-	- Foo
+	- Foo(null)

In addition, support for @return annotations ends:

class FooFactory
{
-	/** @return Foo */
+	public function create(): Foo
	{
	}
}

If the annotation is used in third-party code, add the type in the configuration:

services:
	-
		create: FooFactory::create
		type: Foo

Inside the auto-generated factory definitions are deprecated parameters keys. Also deprecated are the dynamic (replace with imported) and class keys where type should be used:

services:
-	class: MyService
+	type: MyService
-	dynamic: yes
+	imported: yes

Furthermore, the symbol ... representing the omitted argument is changed to _:

services:
-	- MyService(..., 123)
+	- MyService(_, 123)

In NEON files it is no longer necessary to escaping the @ character at the beginning of the string:

services:
-	- MyService('@@example.com')
+	- MyService('@example.com')

Deprecated is the method Nette\DI\Config\Loader::save(), if you want to export the configuration, use directly the adapter method Nette\DI\Config\Adapters\NeonAdapter::dump().