Upgrading
Upgrading to Version 3.3
- requires PHP 8.3 or newer
- what earlier versions only reported as deprecated now throws an exception:
- the
%parameters%parameter; use@container::getParameters() - arguments passed to a service reference, such as
@service(args); pass them where the service is defined - the old symbol
...for an omitted argument; write_
- the
- the type of a service is no longer read from the
@returnannotation of its factory method; declare a native return type - the
@injectannotation is deprecated; mark the property with the#[Inject]attribute and declare its type natively, e.g.public Cache $cache, see Inject
For Compiler Extension Authors
- an extension can attach any of its methods to a phase of compilation using the
#[Hook]attribute, see Hooks; the methodsloadConfiguration(),beforeCompile()andafterCompile()keep working - the built-in extensions do their work in such methods, so calling
loadConfiguration(),beforeCompile()orafterCompile()on them no longer does anything - the classes
Nette\DI\Resolver,PhpGenerator,AutowiringandDependencyCheckermoved to the namespaceNette\DI\Compiler, andNette\DI\Definitions\Referenceis nowNette\DI\Expressions\Reference; the old names keep working ServiceDefinition::getCreator()returnsNette\DI\Expression; a value ofcreate:written as a first-class callable, e.g.create: foo(...), is not aStatement, so testinstanceof Statementbefore reading its entity or argumentsDefinition::generateMethod()is deprecated; implementgenerateCode(), which returns the body of the method
Upgrading to Version 3.1
- autowiring no longer passes
nullto a nullable parameter without a default value; pass the argument explicitly, or give the parameter a default value - support for the
@returnannotation was dropped; use a return type, or state the type in the service definition usingtype: - the key
dynamicwas renamed toimportedandclasstotype - the symbol for an omitted argument changed from
...to_, e.g.MyService(_, 123) - in NEON files, the
@character at the beginning of a string no longer needs to be escaped - the
parameterskey inside definitions of generated factories is deprecated - the method
Nette\DI\Config\Loader::save()is deprecated; export the configuration usingNette\DI\Config\Adapters\NeonAdapter::dump()
Version 3.1 is a transition release: it does not bring new features, but it warns with notices about everything that will work differently later. See the article Nette DI 3.1: transition release.
Upgrading to Version 3.0
- support for INI files has been removed
- direct writing of PHP code into the configuration using question marks (e.g.
"$service->onError[] = ?"(...)) was removed; use the array syntax'$onError[]' = [...]instead - in configuration files, use
factory: PDO(...)instead ofclass: PDO(...) - the
nette.presentertag is no longer used for presenters
For Compiler Extension Authors
While Nette 2.4 internally described every service as Nette\DI\ServiceDefinition, there are now several
definition types: Nette\DI\Definitions\ImportedDefinition for imported (dynamic) services,
Nette\DI\Definitions\FactoryDefinition for generated interface-based factories,
Nette\DI\Definitions\AccessorDefinition for generated accessors, and
Nette\DI\Definitions\ServiceDefinition for common services.
Therefore, in addition to ContainerBuilder::addDefinition(), there are several other methods for creating a new
definition: addFactoryDefinition(), addAccessorDefinition(), and
addImportedDefinition().
Upgrading to Version 2.4
- configuration sections (e.g. production, development) in a single config file are deprecated; use a pair of files
config.neonandconfig.local.neon - inheritance of service definitions is deprecated
Statement::setEntity()is deprecated
Upgrading to Version 2.3
- support for placing services inside the extension section of the configuration file was removed
- support for dynamically added extensions was removed
- when replacing a service dynamically (via
removeService(),addService()), the new service must be an instance of the same interface/class as the original