Please test Nette DI 3.3.0-RC1
- David Grudl
- founder | 8339
Hi,
I'd like to ask you to test nette/di 3.3.0-RC1. It's a big release: I've rewritten a large part of the compiler, extensions got a new phase system, and the configuration gained a few things I think you'll like. I'll cover the new features in a blog post; here the point is to find out whether everything still works for you after upgrading.
The rewrite is mainly about this: service definitions used to describe
everything with a single Statement class, whether it was creating
an object, calling a method, reading a property, or a function like
not(). Now each kind of expression has its own class
(Instantiation, Call, PropertyAccess,
PartialCall …) with the common parent
Nette\DI\Expression, and knows how to resolve its own type and
generate its own code. For backward compatibility most of them still extend
Statement, so code that checks instanceof Statement
works as before.
composer require nette/di:^3.3.0-RC1
It requires PHP 8.3 or newer. It works with the current nette/bootstrap 3.3.1, so you don't need to change anything else. If you also want to try the new parameter features (see below), add nette/bootstrap 3.3.2-RC1:
composer require nette/bootstrap:^3.3.2-RC1
How to test
Just delete temp/cache, run the application and ideally your
tests too. If the container builds and the app runs without new exceptions or
deprecation notices, you're done. I'm most interested in applications with lots
of third-party extensions, because those reach into the compiler internals, and
that's where most of the changes are.
What might break
Things earlier versions only reported as deprecated now throw an exception.
The service type is no longer read from the @return annotation of a
factory method; declare a native return type.
For extension authors:
- extensions now do their work in methods marked with the
#[Hook]attribute, which attach to compilation phases and replaceloadConfiguration(),beforeCompile()andafterCompile()(see the documentation and the thread New Phase System for Extensions); the old methods are deprecated, but of course they keep working unchanged - the built-in extensions (
DIExtension,InjectExtension,SearchExtension,DecoratorExtension,ParametersExtension) now do their work in#[Hook]methods, so if you extend one and call e.g.parent::beforeCompile(), nothing happens ServiceDefinition::getCreator()andgetFactory()now declareNette\DI\Expressionas their return type instead ofStatement. In practice they still return aStatement; the only exception is a service written ascreate: foo(...), which gives you aPartialCallthat doesn't extendStatement.Resolver,PhpGenerator,AutowiringandDependencyCheckermoved to theNette\DI\Compilernamespace,ReferencetoNette\DI\Expressions; the old names still work
The full list is in the upgrade guide.
What to look forward to
- Hooks for extensions: instead of three fixed methods, any
method marked with
#[Hook(Phase::Register)]does the work, and each extension declares its own order withbeforeandafter. - Spreading an array into arguments with
...(), just like...$arrayin PHP:- PDO(...(%pdoArgs%)) - Dynamic parameters without a separate method: wrap a value
in
Nette\DI\DynamicValue, pass it toaddParameters(), and it won't be compiled into the container (with nette/bootstrap 3.3.2-RC1). - Passwords and API keys: a file loaded with
addSecrets()never ends up in the generated container intemp(with nette/bootstrap 3.3.2-RC1).
A blog post with the details is coming, but you can read all about it in the documentation today: Extension Lifecycle, Dynamic Parameters and Passwords and API Keys.
If something stops working or you run into an unexpected exception or deprecation notice, please let me know. Thanks!