Skip to content

Commit

Permalink
Merge branch '5.x' into 5.next
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Oct 20, 2024
2 parents 822f373 + 8af2578 commit c5dc9cb
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 15 deletions.
4 changes: 2 additions & 2 deletions en/console-commands/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ the ``modified`` column to the current time.
Remember, ``exec()`` will take the same string you type into your CLI, so you
can include options and arguments in your command string.

Testing Interactive Shells
--------------------------
Testing Interactive Commands
----------------------------

Consoles are often interactive. Testing interactive commands with the
``Cake\TestSuite\ConsoleIntegrationTestTrait`` trait only requires passing the
Expand Down
7 changes: 2 additions & 5 deletions en/controllers/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,8 @@ in your controller, you could access it like so::
properties they share the same 'namespace'. Be sure to not give a
component and a model the same name.

.. warning::

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

.. _creating-a-component:

Expand Down
5 changes: 2 additions & 3 deletions en/controllers/request-response.rst
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,8 @@ with content types that are not built into Response, you can map them with
$this->response = $this->response->withType('vcf');

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

.. _cake-response-file:

Expand Down
41 changes: 39 additions & 2 deletions en/development/dependency-injection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ CakePHP will use the :term:`DI container` in the following situations:

* Constructing controllers.
* Calling actions on your controllers.
* Constructing Components.
* Constructing Console Commands.
* Constructing Middleware by classname.

A short example would be::
Controller Example
==================

::

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

Here is an example of an injected service inside a command::
Command Example
===============

::

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

Component Example
=================

::

// In src/Controller/Component/SearchComponent.php
class SearchComponent extends Command
{
public function __construct(
ComponentRegistry $registry,
private UserService $users
) {
parent::__construct($registry, []);
}

public function something()
{
$valid = $this->users->check('all');
}
}

// In src/Application.php
public function services(ContainerInterface $container): void
{
$container->add(SearchComponent::class)
->addArgument(ComponentRegistry::class)
->addArgument(UsersService::class);
$container->add(UsersService::class);
}

Adding Services
===============

Expand Down
8 changes: 8 additions & 0 deletions en/orm/behaviors/counter-cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ then updates the counter of the *previously* associated item.
behavior to the ``CommentsTable`` in order to generate ``comment_count`` for
Articles table.

.. versionchanged:: 5.1.2

As of CakePHP 5.1.2, the counter cache values are updated using a single
query using sub-queries, instead of separate queries, to fetch the count and
update a record. If required you can disable the use of sub-queries by
setting `useSubQuery` key to `false` in the config
`['Articles' => ['comment_count' => ['useSubQuery' => false]]`

Belongs to many Usage
=====================

Expand Down
2 changes: 1 addition & 1 deletion en/orm/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class::
// In a table class
public function buildRules(RulesChecker $rules): RulesChecker
{
// Add a rule that is applied for create and update operations
// Add a rule that is applied for create, update and delete operations
$rules->add(function ($entity, $options) {
// Return a boolean to indicate pass/failure
}, 'ruleName');
Expand Down
7 changes: 5 additions & 2 deletions en/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,17 @@ Plugins offer several hooks that allow a plugin to inject itself into the
appropriate parts of your application. The hooks are:

* ``bootstrap`` Used to load plugin default configuration files, define
constants and other global functions.
constants and other global functions. The ``bootstrap`` method is passed the
current ``Application`` instance giving you broad access to the DI container
and configuration.
* ``routes`` Used to load routes for a plugin. Fired after application routes
are loaded.
* ``middleware`` Used to add plugin middleware to an application's middleware
queue.
* ``console`` Used to add console commands to an application's command
collection.
* ``services`` Used to register application container services
* ``services`` Used to register application container service. This is a good
opportunity to setup additional objects that need acccess to the container.

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

0 comments on commit c5dc9cb

Please sign in to comment.