Skip to content

Commit cdd5336

Browse files
committed
Merge branch '5.next' into 6.x
2 parents fe79712 + 7e9a68a commit cdd5336

10 files changed

Lines changed: 93 additions & 69 deletions

File tree

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ The 5.3.0 release is a backwards compatible with 5.0. It adds new functionality
55
and introduces new deprecations. Any functionality deprecated in 5.x will be
66
removed in 6.0.0.
77

8+
Upgrade to PHP 8.2
9+
==================
10+
11+
If you are not running on **PHP 8.2 or higher**, you will need to upgrade PHP before updating CakePHP.
12+
13+
.. note::
14+
CakePHP 5.3 requires **a minimum of PHP 8.2**.
15+
816
Behavior Changes
917
================
1018

@@ -17,14 +25,32 @@ View
1725
Deprecations
1826
============
1927

28+
Http
29+
----
30+
31+
- Using `$request->getParam('?')` to get the query params is deprecated.
32+
Use `$request->getQueryParams()` instead.
33+
2034
ORM
2135
---
2236

2337
- Calling behavior methods on table instances is now deprecated. To call
2438
a method of an attached behavior you need to use
2539
``$table->getBehavior('Sluggable')->slugify()`` instead of ``$table->slugify()``.
40+
- ``EntityTrait::isEmpty()`` is deprecated. Use ``hasValue()`` instead.
2641

2742
New Features
2843
============
2944

30-
TODO
45+
Routing
46+
-------
47+
48+
- ``EntityRoute`` now handles enum value conversions. This enables you to use
49+
enum backed properties as route parameters. When an enum backed property is
50+
used in routing, the enum's ``value`` or ``name`` will be used.
51+
52+
Validation
53+
----------
54+
55+
- ``ipOrRange()`` validation has has been added to check for an IP or a range (subnet).
56+

en/development/testing.rst

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ An example table would be::
510510
],
511511
],
512512
],
513-
// More tables.
513+
// More tables
514514
];
515515

516516
The options available to ``columns``, ``indexes`` and ``constraints`` match the
@@ -536,36 +536,6 @@ To load a SQL dump file you can use the following::
536536
At the beginning of each test run ``SchemaLoader`` will drop all tables in the
537537
connection and rebuild tables based on the provided schema file.
538538

539-
.. _fixture-state-management:
540-
541-
Fixture State Managers
542-
----------------------
543-
544-
By default CakePHP resets fixture state at the end of each test by truncating
545-
all the tables in the database. This operation can become expensive as your
546-
application grows. By using ``TransactionStrategy`` each test method will be run
547-
inside a transaction that is rolled back at the end of the test. This can yield
548-
improved performance but requires your tests not heavily rely on static fixture
549-
data, as auto-increment values are not reset before each test.
550-
551-
The fixture state management strategy can be defined within the test case::
552-
553-
use Cake\TestSuite\TestCase;
554-
use Cake\TestSuite\Fixture\FixtureStrategyInterface;
555-
use Cake\TestSuite\Fixture\TransactionStrategy;
556-
557-
class ArticlesTableTest extends TestCase
558-
{
559-
/**
560-
* Create the fixtures strategy used for this test case.
561-
* You can use a base class/trait to change multiple classes.
562-
*/
563-
protected function getFixtureStrategy(): FixtureStrategyInterface
564-
{
565-
return new TransactionStrategy();
566-
}
567-
}
568-
569539
Creating Fixtures
570540
-----------------
571541

@@ -744,6 +714,46 @@ You can also directly include fixtures by FQCN::
744714
}
745715

746716

717+
718+
.. _fixture-state-management:
719+
720+
Fixture State Managers
721+
----------------------
722+
723+
By default CakePHP resets fixture state at the end of each test by truncating
724+
all the tables in the database. This operation can become expensive as your
725+
application grows. By using ``TransactionStrategy`` each test method will be run
726+
inside a transaction that is rolled back at the end of the test. This can yield
727+
improved performance but requires your tests not heavily rely on static fixture
728+
data, as auto-increment values are not reset before each test.
729+
730+
The fixture state management strategy can be defined within the test case::
731+
732+
use Cake\TestSuite\TestCase;
733+
use Cake\TestSuite\Fixture\FixtureStrategyInterface;
734+
use Cake\TestSuite\Fixture\TransactionStrategy;
735+
736+
class ArticlesTableTest extends TestCase
737+
{
738+
/**
739+
* Create the fixtures strategy used for this test case.
740+
* You can use a base class/trait to change multiple classes.
741+
*/
742+
protected function getFixtureStrategy(): FixtureStrategyInterface
743+
{
744+
return new TransactionStrategy();
745+
}
746+
}
747+
748+
To switch out the general default strategy, use Configure key ``TestSuite.fixtureStrategy`` in your ``app.php``::
749+
750+
'TestSuite' => [
751+
'fixtureStrategy' => \Cake\TestSuite\Fixture\TransactionStrategy::class,
752+
],
753+
754+
755+
The recommended strategy for medium and large applications is the ``TransactionStrategy``, as using rollbacks to undo changes from tests is simpler to maintain, and reduces the chances of cross-contamination and side-effects between tests.
756+
747757
Fixture Factories
748758
-----------------
749759

en/orm/behaviors/counter-cache.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ for all records of one or all configured associations in batches. This can be us
173173
for example, to update the counter cache after importing data directly into the database.::
174174

175175
// Update the counter cache for all configured associations
176-
$table->updateCounterCache();
176+
$table->getBehavior('CounterCache')->updateCounterCache();
177177

178178
// Update the counter cache for a specific association, 200 records per batch
179-
$table->updateCounterCache('Articles', 200);
179+
$table->getBehavior('CounterCache')->updateCounterCache('Articles', 200);
180180

181181
// Update only the first page of records
182-
$table->updateCounterCache('Articles', page: 1);
182+
$table->getBehavior('CounterCache')->updateCounterCache('Articles', page: 1);
183183

184184
.. versionadded:: 5.2.0
185185

en/orm/behaviors/timestamp.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ changing any other properties. This is sometimes referred to as 'touching'
6565
a record. In CakePHP you can use the ``touch()`` method to do exactly this::
6666

6767
// Touch based on the Model.beforeSave event.
68-
$articles->touch($article);
68+
$articles->getBehavior('Timestamp')->touch($article);
6969

7070
// Touch based on a specific event.
71-
$orders->touch($order, 'Orders.completed');
71+
$orders->getBehavior('Timestamp')->touch($order, 'Orders.completed');
7272

7373
After you have saved the entity, the field is updated.
7474

en/orm/behaviors/translate.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ modifying the application's state. For these scenarios use the behavior's
350350
I18n::setLocale('en'); // reset for illustration
351351

352352
// specific locale.
353-
$this->Articles->setLocale('es');
353+
$this->Articles->getBehavior('Translate')->setLocale('es');
354354

355355
$article = $this->Articles->get(12);
356356
echo $article->title; // Echoes 'Un Artículo', yay piece of cake!
@@ -361,8 +361,8 @@ to call the method on each table, for example::
361361

362362
I18n::setLocale('en'); // reset for illustration
363363

364-
$this->Articles->setLocale('es');
365-
$this->Articles->Categories->setLocale('es');
364+
$this->Articles->getBehavior('Translate')->setLocale('es');
365+
$this->Articles->Categories->getBehavior('Translate')->setLocale('es');
366366

367367
$data = $this->Articles->find('all', contain: ['Categories']);
368368

@@ -375,9 +375,9 @@ Querying Translated Fields
375375
TranslateBehavior does not substitute find conditions by default. You need to use
376376
``translationField()`` method to compose find conditions on translated fields::
377377

378-
$this->Articles->setLocale('es');
378+
$this->Articles->getBehavior('Translate')->setLocale('es');
379379
$query = $this->Articles->find()->where([
380-
$this->Articles->translationField('title') => 'Otro Título'
380+
$this->Articles->getBehavior('Translate')->translationField('title') => 'Otro Título'
381381
]);
382382

383383
Saving in Another Language
@@ -442,7 +442,7 @@ default language directly to the table::
442442

443443
$article->title = 'Mi Primer Artículo';
444444

445-
$this->Articles->setLocale('es');
445+
$this->Articles->getBehavior('Translate')->setLocale('es');
446446
$this->Articles->save($article);
447447

448448
Setting the language directly in the table is useful when you need to both

en/orm/behaviors/tree.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ You can verify it works by getting any row from the table and asking for the
6161
count of descendants it has::
6262

6363
$node = $categories->get(1);
64-
echo $categories->childCount($node);
64+
echo $categories->getBehavior('Tree')->childCount($node);
6565

6666
Getting direct descendents
6767
--------------------------
@@ -179,13 +179,13 @@ having to change their parent::
179179
$node = $categories->get(5);
180180

181181
// Move the node so it shows up one position up when listing children.
182-
$categories->moveUp($node);
182+
$categories->getBehavior('Tree')->moveUp($node);
183183

184184
// Move the node to the top of the list inside the same level.
185-
$categories->moveUp($node, true);
185+
$categories->getBehavior('Tree')->moveUp($node, true);
186186

187187
// Move the node to the bottom.
188-
$categories->moveDown($node, true);
188+
$categories->getBehavior('Tree')->moveDown($node, true);
189189

190190
Configuration
191191
=============
@@ -237,12 +237,12 @@ In the previous example, all tree operations will be scoped to only the rows
237237
having the column ``country_name`` set to 'Brazil'. You can change the scoping
238238
on the fly by using the 'config' function::
239239

240-
$this->behaviors()->Tree->setConfig('scope', ['country_name' => 'France']);
240+
$this->getBehavior('Tree')->setConfig('scope', ['country_name' => 'France']);
241241

242242
Optionally, you can have a finer grain control of the scope by passing a closure
243243
as the scope::
244244

245-
$this->behaviors()->Tree->setConfig('scope', function ($query) {
245+
$this->getBehavior('Tree')->setConfig('scope', function ($query) {
246246
$country = $this->getConfigureContry(); // A made-up function
247247
return $query->where(['country_name' => $country]);
248248
});
@@ -311,7 +311,7 @@ is also possible to only delete one node and re-assign all children to the
311311
immediately superior parent node in the tree::
312312

313313
$aCategory = $categoriesTable->get(10);
314-
$categoriesTable->removeFromTree($aCategory);
314+
$categoriesTable->getBehavior('Tree')->removeFromTree($aCategory);
315315
$categoriesTable->delete($aCategory);
316316

317317
All children nodes will be kept and a new parent will be assigned to them.

en/orm/entities.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ You can check if fields are defined in your entities with ``has()``::
132132
$article->has('undefined'); // false
133133

134134
The ``has()`` method will return ``true`` if a field is defined. You can use
135-
``hasValue()`` to check if a field contains a 'non-empty'
136-
value::
135+
``hasValue()`` to check if a field contains a 'non-empty' value::
137136

138137
$article = new Article([
139138
'title' => 'First post',
@@ -567,7 +566,7 @@ field that should be exposed::
567566

568567
class User extends Entity
569568
{
570-
protected $_virtual = ['full_name'];
569+
protected array $_virtual = ['full_name'];
571570
}
572571

573572
This list can be modified at runtime using the ``setVirtual()`` method::

fr/orm/entities.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Vous pouvez vérifier si des champs sont définis dans vos entities avec
136136
$article->has('undefined'); // false.
137137

138138
La méthode ``has()`` va renvoyer ``true`` si un champ est défini est a une
139-
valeur non null. Vous pouvez utiliser ``isEmpty()`` et ``hasValue()`` pour
139+
valeur non null. Vous pouvez utiliser ``hasValue()`` pour
140140
vérifier si un champ contient une valeur 'non-empty'::
141141

142142
$article = new Article([
@@ -147,27 +147,21 @@ vérifier si un champ contient une valeur 'non-empty'::
147147
]);
148148
]);
149149
$article->has('title'); // true
150-
$article->isEmpty('title'); // false
151150
$article->hasValue('title'); // true
152151

153152
$article->has('user_id'); // true
154-
$article->isEmpty('user_id'); // true
155153
$article->hasValue('user_id'); // false
156154

157155
$article->has('text'); // true
158-
$article->isEmpty('text'); // true
159156
$article->hasValue('text'); // false
160157

161158
$article->has('links'); // true
162-
$article->isEmpty('links'); // true
163159
$article->hasValue('links'); // false
164160

165161
$article->has('text'); // true
166-
$article->isEmpty('text'); // true
167162
$article->hasValue('text'); // false
168163

169164
$article->has('links'); // true
170-
$article->isEmpty('links'); // true
171165
$article->hasValue('links'); // false
172166

173167
Accesseurs & Mutateurs
@@ -600,7 +594,7 @@ doivent être exposés::
600594

601595
class User extends Entity
602596
{
603-
protected $_virtual = ['full_name'];
597+
protected array $_virtual = ['full_name'];
604598
}
605599

606600
Cette liste peut être modifiée à la volée en utilisant la méthode

ja/orm/entities.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,14 @@ CakePHP の ORM を使うためにエンティティークラスを生成する
109109
$article->has('undefined'); // false.
110110

111111
``has()`` メソッドは、プロパティが定義されていてヌル以外の値を持つ場合、 ``true`` を返します。
112-
``isEmpty()`` と ``hasValue()`` を使って、プロパティに '空でない' 値が含まれているかどうかを
112+
``hasValue()`` を使って、プロパティに '空でない' 値が含まれているかどうかを
113113
調べることができます。 ::
114114

115115
$article = new Article([
116116
'title' => 'First post',
117117
'user_id' => null
118118
]);
119-
$article->isEmpty('title'); // false
120119
$article->hasValue('title'); // true
121-
122-
$article->isEmpty('user_id'); // true
123120
$article->hasValue('user_id'); // false
124121

125122
アクセサーとミューテーター
@@ -502,7 +499,7 @@ CakePHP では以下のように簡単にできます。 ::
502499

503500
class User extends Entity
504501
{
505-
protected $_virtual = ['full_name'];
502+
protected array $_virtual = ['full_name'];
506503
}
507504

508505
実行時に ``setVirtual()`` を使うことでこのリストを変更できます。 ::

pt/orm/entities.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,7 @@ virtuais que devem ser expostas::
496496

497497
class User extends Entity
498498
{
499-
500-
protected $_virtual = ['full_name'];
501-
499+
protected array $_virtual = ['full_name'];
502500
}
503501

504502
Esta lista pode ser modificada em tempo de execução usando o método

0 commit comments

Comments
 (0)