Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ permissions:

jobs:
testsuite:
uses: ADmad/.github/.github/workflows/testsuite-with-db.yml@master
uses: ADmad/.github/.github/workflows/testsuite-with-db.yml@cake6
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

cs-stan:
uses: ADmad/.github/.github/workflows/cs-stan.yml@master
uses: ADmad/.github/.github/workflows/cs-stan.yml@cake6
secrets: inherit
2 changes: 1 addition & 1 deletion .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="2.1.17" installed="2.1.17" location="./tools/phpstan" copy="false"/>
<phar name="phpstan" version="2.3.1" installed="2.3.1" location="./tools/phpstan" copy="false"/>
</phive>
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
}
],
"require": {
"php": ">=8.1",
"cakephp/cakephp": "^5.0"
"php": ">=8.5",
"cakephp/cakephp": "^6.0@dev"
},
"require-dev": {
"friendsofcake/cakephp-test-utilities": "^3.0",
"friendsofcake/search": "^7.0",
"phpunit/phpunit": "^10.5.58 || ^11.5.3 || ^12.4",
"cakephp/cakephp-codesniffer": "^5.3"
"friendsofcake/cakephp-test-utilities": "dev-cake6",
"friendsofcake/search": "dev-cake6",
"phpunit/phpunit": "^13.0",
"cakephp/cakephp-codesniffer": "^6.0@dev"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -85,5 +85,7 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
20 changes: 10 additions & 10 deletions docs/_code/action_index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ class Index extends BaseAction
*
* @return \Cake\Http\Response|null
*/
protected function _handle(): ?Response
protected function handleRequest(): ?Response
{
[$finder, $options] = $this->_extractFinder();
$query = $this->_model()->find($finder, ...$options);
$subject = $this->_subject(['success' => true, 'query' => $query]);
[$finder, $options] = $this->extractFinder();
$query = $this->model()->find($finder, ...$options);
$subject = $this->subject(['success' => true, 'query' => $query]);

$this->_trigger('beforePaginate', $subject);
$this->trigger('beforePaginate', $subject);
try {
$items = $this->_controller()->paginate($subject->query);
$items = $this->controller()->paginate($subject->query);
} catch (NotFoundException $e) {
/** @var \Cake\Core\Exception\CakeException $previous */
$previous = $e->getPrevious();
$pagingParams = $previous->getAttributes()['pagingParams'];

$url = Router::reverseToArray($this->_request());
$url = Router::reverseToArray($this->request());
$url['?']['page'] = $pagingParams['pageCount'];

return $this->_controller()->redirect($url);
return $this->controller()->redirect($url);
}

$subject->set(['entities' => $items]);

$this->_trigger('afterPaginate', $subject);
$this->_trigger('beforeRender', $subject);
$this->trigger('afterPaginate', $subject);
$this->trigger('beforeRender', $subject);

return null;
}
Expand Down
3 changes: 2 additions & 1 deletion docs/_code/listener_example.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function implementedEvents(): array
*/
public function beforeRender(\Cake\Event\EventInterface $event)
{
$this->_response()->header('X-Powered-By', 'CRUD 4.0');
$response = $this->response()->withHeader('X-Powered-By', 'CRUD 4.0');
$this->controller()->setResponse($response);
}

}
4 changes: 2 additions & 2 deletions docs/_partials/events/after_bulk.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Crud.afterBulk
^^^^^^^^^^^^^^

This event is emitted after calling ``_bulk()`` on a Bulk Crud action.
This event is emitted after calling ``bulk()`` on a Bulk Crud action.

The :ref:`Crud Subject <crud-subject>` contains two keys:

- **success** if ``true`` the ``_bulk()`` call succeeded, ``false`` otherwise
- **success** if ``true`` the ``bulk()`` call succeeded, ``false`` otherwise
- **ids** A list of ids of entities, from the request data
- **repository** An instance of the ``Repository`` (``Table``) which the query will be executed against.
- **query** A ``Query`` object from the ``Repository`` where ``$PrimaryKey => $IdFromRequest`` is already added to the conditions.
Expand Down
2 changes: 1 addition & 1 deletion docs/_partials/events/before_bulk.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Crud.beforeBulk
^^^^^^^^^^^^^^^

This event is emitted before ``_bulk()`` is called on a Bulk Crud action.
This event is emitted before ``bulk()`` is called on a Bulk Crud action.

The :ref:`Crud Subject <crud-subject>` contains the following keys:

Expand Down
22 changes: 11 additions & 11 deletions docs/actions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ namespace your action class accordingly.
Request Methods
---------------

Next is the method ``_handle``. A Crud Action can respond to any HTTP verb
Next is the method ``handleRequest``. A Crud Action can respond to any HTTP verb
(``GET``, ``POST``, ``PUT``, ``DELETE``).
Each HTTP verb can be implemented as method, e.g. ``_get()`` for HTTP GET,
``_post()`` for HTTP POST and ``_put()`` for HTTP PUT.
Each HTTP verb can be implemented as method, e.g. ``handleGet()`` for HTTP GET,
``handlePost()`` for HTTP POST and ``handlePut()`` for HTTP PUT.

If no HTTP verb specific method is found in the class, ``_handle()`` will be
If no HTTP verb specific method is found in the class, ``handleRequest()`` will be
executed.

.. literalinclude:: _code/action_index.php
:language: php
:linenos:
:emphasize-lines: 6-10

You can treat the ``_handle()`` method as a catch-all, if your crud action
You can treat the ``handleRequest()`` method as a catch-all, if your crud action
wants to process all possible HTTP verbs.

An advantage of this setup is that you can separate the logic on a request type
level instead of mixing all of the logic into one big block of code.

For example the :doc:`Edit Crud Action<actions/edit>` implements ``_get()``,
``_post()`` and ``_put()`` methods. The ``_get()`` method simply reads the entity
from the database and passes it to the form, while ``_put()`` handles validation
For example the :doc:`Edit Crud Action<actions/edit>` implements ``handleGet()``,
``handlePost()`` and ``handlePut()`` methods. The ``handleGet()`` method simply reads the entity
from the database and passes it to the form, while ``handlePut()`` handles validation
and saving the entity back to the database.

Events & Subject
Expand All @@ -87,10 +87,10 @@ change its state between emitted events. This object is a ``Crud\Event\Subject``

The real beauty of Crud is the events and the flexibility they provide.

All calls to ``_trigger()`` emit an event, that you as a developer can listen to and inject your own application logic.
All calls to ``trigger()`` emit an event, that you as a developer can listen to and inject your own application logic.
These events are in no way magical, they are simply normal
`CakePHP events <http://book.cakephp.org/5/en/core-libraries/events.html>`_, dispatched like all
other `events in CakePHP <http://book.cakephp.org/5/en/core-libraries/events.html>`_.
`CakePHP events <http://book.cakephp.org/6.x/en/core-libraries/events.html>`_, dispatched like all
other `events in CakePHP <http://book.cakephp.org/6.x/en/core-libraries/events.html>`_.

You can for example listen for the ``beforePaginate`` event and add conditions to your pagination query, just with a
few lines of code. Those few lines of code is what makes your application unique. The rest of the code you would
Expand Down
10 changes: 5 additions & 5 deletions docs/actions/bulk.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Three BulkAction classes exist in the core:
- :doc:`SetValue</actions/bulk-set-value>`: Sets a field to a value for a set of entities
- :doc:`Toggle</actions/bulk-toggle>`: Toggles the value of a boolean field for a set of entities

To create your own BulkAction, simply create a new action class with a ``_bulk``
method. This method takes a CakePHP ``Query`` object as its first argument
To create your own BulkAction, simply create a new action class with a ``bulk``
method. This method takes a ``Cake\Database\Query`` object as its first argument

.. code-block:: phpinline

<?php
namespace App\Crud\Action;

use Cake\ORM\Query;
use Cake\Database\Query;
use Crud\Action\Bulk\BaseAction;

class ApproveAction extends BaseAction
Expand All @@ -27,10 +27,10 @@ method. This method takes a CakePHP ``Query`` object as its first argument
* Set the value of the approved field to true
* for a set of entities
*
* @param \Cake\ORM\Query $query The query to act upon
* @param \Cake\Database\Query $query The query to act upon
* @return boolean
*/
protected function _bulk(Query $query)
protected function bulk(Query $query)
{
$query->update()->set(['approved' => true]);
$statement = $query->execute();
Expand Down
14 changes: 7 additions & 7 deletions docs/actions/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Custom Action Classes
If you need to customize an action for any reason, you can create your own custom Crud action class.

A Crud Action can respond to any ``HTTP`` verb (``GET``, ``POST``, ``PUT``, ``DELETE``).
Each HTTP verb can be implemented as method, e.g. ``_get()`` for HTTP ``GET``,
``_post()`` for HTTP ``POST`` and ``_put()`` for HTTP ``PUT``.
Each HTTP verb can be implemented as method, e.g. ``handleGet()`` for HTTP ``GET``,
``handlePost()`` for HTTP ``POST`` and ``handlePut()`` for HTTP ``PUT``.

If no HTTP verb specific method is found in the class, ``_handle()`` will be executed.
If no HTTP verb specific method is found in the class, ``handleRequest()`` will be executed.

A default custom index action might be as simple as the following:

Expand All @@ -27,7 +27,7 @@ A default custom index action might be as simple as the following:
*
* @var array<string, mixed>
*/
protected array $_defaultConfig = [
protected array $defaultConfig = [
'enabled' => true,
'scope' => 'table',
'findMethod' => 'all',
Expand All @@ -49,10 +49,10 @@ A default custom index action might be as simple as the following:
*
* @return void
*/
protected function _handle(): void
protected function handleRequest(): void
{
$query = $this->_table()->find($this->findMethod());
$items = $this->_controller()->paginate($query);
$query = $this->model()->find($this->findMethod());
$items = $this->controller()->paginate($query);
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ The easiest way to achieve this is to create an ``AppController`` for the prefix
extend from that one. Then you can configure Crud in your prefixes ``AppController``.

Let's look at an example, using an ``api`` prefix. For this example, we'll assume your
`prefix routing <http://book.cakephp.org/5/en/development/routing.html#prefix-routing>`_ is already configured.
`prefix routing <http://book.cakephp.org/6.x/en/development/routing.html#prefix-routing>`_ is already configured.

First step is to create your new ``ApiAppController`` which should be in ``src/Controller/Api/``.

Expand Down
4 changes: 2 additions & 2 deletions docs/listeners.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The Anatomy Of A Listener
=========================

The listener system is simply the
`Events System <http://book.cakephp.org/5/en/core-libraries/events.html>`_ from
`Events System <http://book.cakephp.org/6.x/en/core-libraries/events.html>`_ from
CakePHP, and all the official documentation and usage also applies to Crud.

The Crud event system uses two methods ``trigger()`` and ``on()`` to interface
Expand Down Expand Up @@ -47,7 +47,7 @@ as an action creator.
Implemented Events
------------------

As documented in the `CakePHP Events System <http://book.cakephp.org/5/en/core-libraries/events.html>`_
As documented in the `CakePHP Events System <http://book.cakephp.org/6.x/en/core-libraries/events.html>`_
all listeners must contain a ``implementedEvents`` method.

In this example, we simply request that ``beforeRender`` in our class is executed
Expand Down
2 changes: 1 addition & 1 deletion docs/listeners/api-pagination.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Configuration
-------------

Configure this listener by setting the
`CakePHP Pagination <http://book.cakephp.org/5/en/controllers/components/pagination.html>`_ options directly to the
`CakePHP Pagination <http://book.cakephp.org/6.x/en/controllers/components/pagination.html>`_ options directly to the
query object.

.. code-block:: php
Expand Down
2 changes: 1 addition & 1 deletion docs/listeners/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Setup
Routing
^^^^^^^

You need to tell the ``Router`` to `parse extensions <https://book.cakephp.org/5/en/development/routing.html#routing-file-extensions>`_ else it won't be able to process and render ``json`` and ``xml``
You need to tell the ``Router`` to `parse extensions <https://book.cakephp.org/6.x/en/development/routing.html#routing-file-extensions>`_ else it won't be able to process and render ``json`` and ``xml``
URL extension.

Controller
Expand Down
10 changes: 5 additions & 5 deletions docs/listeners/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Using a controller as a listener
--------------------------------

We override the ``implementedEvents()`` method in the controller, and bind
the ``Crud.beforeFind`` event to the ``_beforeFind()`` method in the controller.
the ``Crud.beforeFind`` event to the ``beforeFind()`` method in the controller.

.. code-block:: phpinline

Expand All @@ -19,11 +19,11 @@ the ``Crud.beforeFind`` event to the ``_beforeFind()`` method in the controller.
public function implementedEvents(): array
{
return parent::implementedEvents() + [
'Crud.beforeFind' => '_beforeFind'
'Crud.beforeFind' => 'beforeFind'
];
}

public function _beforeFind(\Cake\Event\EventInterface $event, \Cake\ORM\Query\SelectQuery $query): void
public function beforeFind(\Cake\Event\EventInterface $event, \Cake\ORM\Query\SelectQuery $query): void
{
...
}
Expand All @@ -48,11 +48,11 @@ Creating your own listener class is very similar to using a controller as a list
public function implementedEvents(): array
{
return [
'Crud.beforeFind' => '_beforeFind'
'Crud.beforeFind' => 'beforeFind'
];
}

public function _beforeFind(Event $event)
public function beforeFind(Event $event)
{
Log::debug('Inside the listener!');
}
Expand Down
2 changes: 1 addition & 1 deletion docs/listeners/related-models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ subject, which can be altered on the fly before any result is fetched

* ``name`` The name of the relation
* ``viewVar`` The name of the variable when set to the view
* ``query`` The ``\Cake\ORM\Query`` object used for the ``find('list')``
* ``query`` The ``\Cake\ORM\Query\SelectQuery`` object used for the ``find('list')``
* ``association`` The ``\Cake\ORM\Association`` object
* ``entity`` The ``Cake\ORM\Entity`` you are finding relations for

Expand Down
2 changes: 1 addition & 1 deletion docs/quick-start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ So, our new Blog needs a Posts controller to allow us to create, read, update an
This is all the code we need in the ``PostsController`` as Crud will scaffold the controller actions for us.

If you are not using `Crud-View <https://github.com/FriendsOfCake/crud-view>`_ then you will have
to `bake your templates <http://book.cakephp.org/5/en/bake/usage.html>`_.
to `bake your templates <http://book.cakephp.org/6.x/en/bake/usage.html>`_.

.. code-block:: sh

Expand Down
Loading
Loading