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 type of a service is no longer read from the @return annotation of its factory method; declare a native return type
  • the @inject annotation 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 methods loadConfiguration(), beforeCompile() and afterCompile() keep working
  • the built-in extensions do their work in such methods, so calling loadConfiguration(), beforeCompile() or afterCompile() on them no longer does anything
  • the classes Nette\DI\Resolver, PhpGenerator, Autowiring and DependencyChecker moved to the namespace Nette\DI\Compiler, and Nette\DI\Definitions\Reference is now Nette\DI\Expressions\Reference; the old names keep working
  • ServiceDefinition::getCreator() returns Nette\DI\Expression; a value of create: written as a first-class callable, e.g. create: foo(...), is not a Statement, so test instanceof Statement before reading its entity or arguments
  • Definition::generateMethod() is deprecated; implement generateCode(), which returns the body of the method

Upgrading to Version 3.1

  • autowiring no longer passes null to a nullable parameter without a default value; pass the argument explicitly, or give the parameter a default value
  • support for the @return annotation was dropped; use a return type, or state the type in the service definition using type:
  • the key dynamic was renamed to imported and class to type
  • 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 parameters key inside definitions of generated factories is deprecated
  • the method Nette\DI\Config\Loader::save() is deprecated; export the configuration using Nette\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 of class: PDO(...)
  • the nette.presenter tag 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.neon and config.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
version: 3.x