diff --git a/en/appendices/5-3-migration-guide.rst b/en/appendices/5-3-migration-guide.rst index b29df95c05..0ccc50a004 100644 --- a/en/appendices/5-3-migration-guide.rst +++ b/en/appendices/5-3-migration-guide.rst @@ -65,6 +65,12 @@ ORM New Features ============ +Cache +----- + +- Added Redis Cluster support to ``RedisEngine``. Configure the ``cluster`` option + with an array of server addresses to enable cluster mode. + Command ------- @@ -74,18 +80,18 @@ Command - ``cake server`` now supports a ``--frankenphp`` option that will start the development server with `FrankenPHP `__. -Cache ------ - -- Added Redis Cluster support to ``RedisEngine``. Configure the ``cluster`` option - with an array of server addresses to enable cluster mode. - Console ------- - Added ``TreeHelper`` which outputs an array as a tree such as an array of filesystem directories as array keys and files as lists under each directory. +Core +---- + +- Added ``Configure`` attribute to support injecting ``Configure`` values into + constructor arguments. See ref:`configure-dependency-injection`. + Database -------- diff --git a/en/development/dependency-injection.rst b/en/development/dependency-injection.rst index 1fcf43615b..6fe534eab9 100644 --- a/en/development/dependency-injection.rst +++ b/en/development/dependency-injection.rst @@ -213,13 +213,28 @@ services like in a reporting system:: return new ReportAggregate($container->get('reports')); }); +.. _configure-dependency-injection: + Using Configuration Data ------------------------ -Often you'll need configuration data in your services. While you could add -all the configuration keys your service needs into the container, that can be -tedious. To make configuration easier to work with CakePHP includes an -injectable configuration reader:: +Often you'll need configuration data in your services. If you need a specific value, +you can inject it as a constructor argument using the ``Cake\Core\Attribute\Configure`` +attribute:: + + use Cake\Core\Attribute\Configure; + + class InjectedService + { + public function __construct( + #[Configure('MyService.apiKey')] protected string $apiKey, + ) { } + } + +.. versionadded:: 5.3.0 + +If you want to inject a copy of all configuration data, CakePHP includes +an injectable configuration reader:: use Cake\Core\ServiceConfig;