Skip to content

Commit c5dc9cb

Browse files
committed
Merge branch '5.x' into 5.next
2 parents 822f373 + 8af2578 commit c5dc9cb

File tree

7 files changed

+59
-15
lines changed

7 files changed

+59
-15
lines changed

en/console-commands/commands.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ the ``modified`` column to the current time.
433433
Remember, ``exec()`` will take the same string you type into your CLI, so you
434434
can include options and arguments in your command string.
435435

436-
Testing Interactive Shells
437-
--------------------------
436+
Testing Interactive Commands
437+
----------------------------
438438

439439
Consoles are often interactive. Testing interactive commands with the
440440
``Cake\TestSuite\ConsoleIntegrationTestTrait`` trait only requires passing the

en/controllers/components.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,8 @@ in your controller, you could access it like so::
147147
properties they share the same 'namespace'. Be sure to not give a
148148
component and a model the same name.
149149

150-
.. warning::
151-
152-
Component methods **don't** have access to :doc:`/development/dependency-injection`
153-
like Controller actions have. Use a service class inside your controller actions
154-
instead of a component if you need this functionality.
150+
.. versionchanged:: 5.1.0
151+
Components are able to use :doc:`/development/dependency-injection` to receive services.
155152

156153
.. _creating-a-component:
157154

en/controllers/request-response.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,8 @@ with content types that are not built into Response, you can map them with
675675
$this->response = $this->response->withType('vcf');
676676

677677
Usually, you'll want to map additional content types in your controller's
678-
:php:meth:`~Controller::beforeFilter()` callback, so you can leverage the
679-
automatic view switching features of :php:class:`RequestHandlerComponent` if you
680-
are using it.
678+
:php:meth:`~Controller::beforeFilter()` callback, so you can benefit from
679+
automatic view switching provided by :ref:`controller-viewclasses`.
681680

682681
.. _cake-response-file:
683682

en/development/dependency-injection.rst

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ CakePHP will use the :term:`DI container` in the following situations:
1414

1515
* Constructing controllers.
1616
* Calling actions on your controllers.
17+
* Constructing Components.
1718
* Constructing Console Commands.
1819
* Constructing Middleware by classname.
1920

20-
A short example would be::
21+
Controller Example
22+
==================
23+
24+
::
2125

2226
// In src/Controller/UsersController.php
2327
class UsersController extends AppController
@@ -45,7 +49,10 @@ database. Because this service is injected into our controller, we can easily
4549
swap the implementation out with a mock object or a dummy sub-class when
4650
testing.
4751

48-
Here is an example of an injected service inside a command::
52+
Command Example
53+
===============
54+
55+
::
4956

5057
// In src/Command/CheckUsersCommand.php
5158
class CheckUsersCommand extends Command
@@ -76,6 +83,36 @@ a whole to the Container and add the ``UsersService`` as an argument.
7683
With that you can then access that service inside the constructor
7784
of the command.
7885

86+
Component Example
87+
=================
88+
89+
::
90+
91+
// In src/Controller/Component/SearchComponent.php
92+
class SearchComponent extends Command
93+
{
94+
public function __construct(
95+
ComponentRegistry $registry,
96+
private UserService $users
97+
) {
98+
parent::__construct($registry, []);
99+
}
100+
101+
public function something()
102+
{
103+
$valid = $this->users->check('all');
104+
}
105+
}
106+
107+
// In src/Application.php
108+
public function services(ContainerInterface $container): void
109+
{
110+
$container->add(SearchComponent::class)
111+
->addArgument(ComponentRegistry::class)
112+
->addArgument(UsersService::class);
113+
$container->add(UsersService::class);
114+
}
115+
79116
Adding Services
80117
===============
81118

en/orm/behaviors/counter-cache.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ then updates the counter of the *previously* associated item.
131131
behavior to the ``CommentsTable`` in order to generate ``comment_count`` for
132132
Articles table.
133133

134+
.. versionchanged:: 5.1.2
135+
136+
As of CakePHP 5.1.2, the counter cache values are updated using a single
137+
query using sub-queries, instead of separate queries, to fetch the count and
138+
update a record. If required you can disable the use of sub-queries by
139+
setting `useSubQuery` key to `false` in the config
140+
`['Articles' => ['comment_count' => ['useSubQuery' => false]]`
141+
134142
Belongs to many Usage
135143
=====================
136144

en/orm/validation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class::
297297
// In a table class
298298
public function buildRules(RulesChecker $rules): RulesChecker
299299
{
300-
// Add a rule that is applied for create and update operations
300+
// Add a rule that is applied for create, update and delete operations
301301
$rules->add(function ($entity, $options) {
302302
// Return a boolean to indicate pass/failure
303303
}, 'ruleName');

en/plugins.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,17 @@ Plugins offer several hooks that allow a plugin to inject itself into the
107107
appropriate parts of your application. The hooks are:
108108

109109
* ``bootstrap`` Used to load plugin default configuration files, define
110-
constants and other global functions.
110+
constants and other global functions. The ``bootstrap`` method is passed the
111+
current ``Application`` instance giving you broad access to the DI container
112+
and configuration.
111113
* ``routes`` Used to load routes for a plugin. Fired after application routes
112114
are loaded.
113115
* ``middleware`` Used to add plugin middleware to an application's middleware
114116
queue.
115117
* ``console`` Used to add console commands to an application's command
116118
collection.
117-
* ``services`` Used to register application container services
119+
* ``services`` Used to register application container service. This is a good
120+
opportunity to setup additional objects that need acccess to the container.
118121

119122
By default all plugins hooks are enabled. You can disable hooks by using the
120123
related options of the ``plugin load`` command:

0 commit comments

Comments
 (0)