Skip to content

Commit da40248

Browse files
authored
Merge pull request #8095 from cakephp/container-attribute
Add migration notes for Configure attribute
2 parents ef6598c + fb70334 commit da40248

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

en/appendices/5-3-migration-guide.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ ORM
6565
New Features
6666
============
6767

68+
Cache
69+
-----
70+
71+
- Added Redis Cluster support to ``RedisEngine``. Configure the ``cluster`` option
72+
with an array of server addresses to enable cluster mode.
73+
6874
Command
6975
-------
7076

@@ -74,18 +80,18 @@ Command
7480
- ``cake server`` now supports a ``--frankenphp`` option that will start the
7581
development server with `FrankenPHP <https://frankenphp.dev/>`__.
7682

77-
Cache
78-
-----
79-
80-
- Added Redis Cluster support to ``RedisEngine``. Configure the ``cluster`` option
81-
with an array of server addresses to enable cluster mode.
82-
8383
Console
8484
-------
8585

8686
- Added ``TreeHelper`` which outputs an array as a tree such as an array of filesystem
8787
directories as array keys and files as lists under each directory.
8888

89+
Core
90+
----
91+
92+
- Added ``Configure`` attribute to support injecting ``Configure`` values into
93+
constructor arguments. See ref:`configure-dependency-injection`.
94+
8995
Database
9096
--------
9197

en/development/dependency-injection.rst

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,28 @@ services like in a reporting system::
213213
return new ReportAggregate($container->get('reports'));
214214
});
215215

216+
.. _configure-dependency-injection:
217+
216218
Using Configuration Data
217219
------------------------
218220

219-
Often you'll need configuration data in your services. While you could add
220-
all the configuration keys your service needs into the container, that can be
221-
tedious. To make configuration easier to work with CakePHP includes an
222-
injectable configuration reader::
221+
Often you'll need configuration data in your services. If you need a specific value,
222+
you can inject it as a constructor argument using the ``Cake\Core\Attribute\Configure``
223+
attribute::
224+
225+
use Cake\Core\Attribute\Configure;
226+
227+
class InjectedService
228+
{
229+
public function __construct(
230+
#[Configure('MyService.apiKey')] protected string $apiKey,
231+
) { }
232+
}
233+
234+
.. versionadded:: 5.3.0
235+
236+
If you want to inject a copy of all configuration data, CakePHP includes
237+
an injectable configuration reader::
223238

224239
use Cake\Core\ServiceConfig;
225240

0 commit comments

Comments
 (0)