Skip to content

Commit fe3de30

Browse files
committed
Add missing 5.3 feature documentation to topic pages
Several 5.3 features were only documented in the migration guide without corresponding coverage in their topic pages. This adds documentation with examples and version annotations for: - Validation: ipOrRange() rule, existsInNullable() application rule - Database: TypeFactory::getMapped(), Query::getDriver(), Entra auth - Console: TreeHelper, CommandCollection::replace() - Routing: RedirectTrait for custom redirect route classes - I18n: DateTimePeriod, DatePeriod, Date::getTimestamp() - View: ViewBuilder::setConfigMergeStrategy()
1 parent b263076 commit fe3de30

File tree

8 files changed

+215
-0
lines changed

8 files changed

+215
-0
lines changed

docs/en/console-commands/commands.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,56 @@ class CleanupCommand extends Command
313313
Custom grouping support was added.
314314
:::
315315

316+
## Replacing Commands
317+
318+
`CommandCollection::replace()` allows you to replace an existing command in the
319+
collection without needing to remove and re-add it. This is particularly useful
320+
when using `autoDiscover` and you want to replace a command with a customized
321+
version:
322+
323+
``` php
324+
// In your Application::console() method
325+
public function console(CommandCollection $commands): CommandCollection
326+
{
327+
$commands = parent::console($commands);
328+
$commands->replace('some_plugin_command', MyCustomCommand::class);
329+
330+
return $commands;
331+
}
332+
```
333+
334+
::: info Added in version 5.3.0
335+
`CommandCollection::replace()` was added.
336+
:::
337+
338+
## Tree Output Helper
339+
340+
The `TreeHelper` outputs an array as a tree structure. This is useful for
341+
displaying filesystem directories or any hierarchical data:
342+
343+
``` php
344+
public function execute(Arguments $args, ConsoleIo $io): int
345+
{
346+
$helper = $io->helper('Tree');
347+
$helper->output([
348+
'src' => [
349+
'Controller',
350+
'Model',
351+
'View',
352+
],
353+
'tests' => [
354+
'TestCase',
355+
],
356+
]);
357+
358+
return static::CODE_SUCCESS;
359+
}
360+
```
361+
362+
::: info Added in version 5.3.0
363+
The `TreeHelper` was added.
364+
:::
365+
316366
<a id="console-integration-testing"></a>
317367

318368
## Testing Commands

docs/en/controllers.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,31 @@ $this->viewBuilder()
202202
The above shows how you can load custom helpers, set the theme and use a custom
203203
view class.
204204

205+
#### Config Merge Strategy
206+
207+
By default, view options set via `ViewBuilder` are deep-merged with the View
208+
class's default configuration. You can control this behavior using
209+
`setConfigMergeStrategy()`:
210+
211+
``` php
212+
use Cake\View\ViewBuilder;
213+
214+
$this->viewBuilder()
215+
->setConfigMergeStrategy(ViewBuilder::MERGE_SHALLOW)
216+
->setOption('customArray', ['a', 'b', 'c']);
217+
```
218+
219+
Available strategies are:
220+
221+
- `ViewBuilder::MERGE_DEEP` - Recursive merge (default). Nested arrays are merged together.
222+
- `ViewBuilder::MERGE_SHALLOW` - Simple array merge. Array values are replaced rather than deep-merged.
223+
224+
You can retrieve the current strategy using `getConfigMergeStrategy()`.
225+
226+
::: info Added in version 5.3.0
227+
`ViewBuilder::setConfigMergeStrategy()` and `ViewBuilder::getConfigMergeStrategy()` were added.
228+
:::
229+
205230
### Rendering a View
206231

207232
`method` Cake\\Controller\\Controller::**render**(string $view, string $layout): Response

docs/en/core-libraries/time.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,50 @@ time and timezones. The `Date` class wraps the `Cake\Chronos\ChronosDate` class.
495495
> So you cannot cannot directly compare a `Date` instance with a `DateTime` instance.
496496
> But you can do comparisons like `$dateTime->toNative() > $date->toNative()`.
497497
498+
### Date::getTimestamp()
499+
500+
`method` Cake\\I18n\\Date::**getTimestamp**(): int
501+
502+
Returns an integer timestamp for the date:
503+
504+
``` php
505+
$date = new Date('2021-01-31');
506+
echo $date->getTimestamp();
507+
```
508+
509+
::: info Added in version 5.3.0
510+
`Date::getTimestamp()` was added.
511+
:::
512+
513+
## DateTimePeriod and DatePeriod
514+
515+
`class` Cake\\I18n\\**DateTimePeriod**
516+
517+
`class` Cake\\I18n\\**DatePeriod**
518+
519+
CakePHP provides `DateTimePeriod` and `DatePeriod` classes that wrap PHP's
520+
`DatePeriod`. When iterating, `DateTimePeriod` returns `DateTime` instances
521+
and `DatePeriod` returns `Date` instances:
522+
523+
``` php
524+
use Cake\I18n\DateTime;
525+
use Cake\I18n\DateTimePeriod;
526+
527+
$start = new DateTime('2021-01-01');
528+
$end = new DateTime('2021-01-05');
529+
$interval = new \DateInterval('P1D');
530+
531+
$period = new DateTimePeriod($start, $interval, $end);
532+
foreach ($period as $date) {
533+
// $date is a Cake\I18n\DateTime instance
534+
echo $date->i18nFormat('yyyy-MM-dd');
535+
}
536+
```
537+
538+
::: info Added in version 5.3.0
539+
`DateTimePeriod` and `DatePeriod` were added.
540+
:::
541+
498542
## Time
499543

500544
`class` Cake\\I18n\\**Time**

docs/en/core-libraries/validation.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,3 +675,19 @@ $validator
675675
Core rules that take additional parameters should have an array for the
676676
`rule` key that contains the rule as the first element, and the additional
677677
parameters as the remaining parameters.
678+
679+
### IP and Range Validation
680+
681+
You can validate that a value is a valid IP address or an IP range (subnet)
682+
using the `ipOrRange()` rule:
683+
684+
``` php
685+
$validator->add('ip_address', 'validRange', [
686+
'rule' => 'ipOrRange',
687+
'message' => 'Please provide a valid IP or IP range.',
688+
]);
689+
```
690+
691+
::: info Added in version 5.3.0
692+
The `ipOrRange()` validation rule was added.
693+
:::

docs/en/development/routing.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,28 @@ Router::url(['_name' => 'articles:view', '_entity' => $article]);
17791779
This will extract both the `id` property and the `slug` property out of the
17801780
provided entity.
17811781

1782+
### Redirect Trait
1783+
1784+
CakePHP provides a `RedirectTrait` that can be used to create custom redirect
1785+
route classes. If you need redirect behavior with custom logic, you can create
1786+
a route class that uses this trait:
1787+
1788+
``` php
1789+
namespace App\Routing\Route;
1790+
1791+
use Cake\Routing\Route\RedirectTrait;
1792+
use Cake\Routing\Route\Route;
1793+
1794+
class MyRedirectRoute extends Route
1795+
{
1796+
use RedirectTrait;
1797+
}
1798+
```
1799+
1800+
::: info Added in version 5.3.0
1801+
`RedirectTrait` was added.
1802+
:::
1803+
17821804
<a id="custom-route-classes"></a>
17831805

17841806
## Custom Route Classes

docs/en/orm/database-basics.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,16 @@ The `cache` flag to send to SQLite.
279279
mode
280280
The `mode` flag value to send to SQLite.
281281

282+
### SqlServer Entra Authentication
283+
284+
The SqlServer driver supports Entra authentication (formerly Azure Active
285+
Directory authentication). This allows you to authenticate using Azure-managed
286+
identities instead of traditional username/password credentials.
287+
288+
::: info Added in version 5.3.0
289+
Entra authentication support was added to the SqlServer driver.
290+
:::
291+
282292
At this point, you might want to take a look at the
283293
[CakePHP Conventions](../intro/conventions). The correct naming for your tables (and the addition
284294
of some columns) can score you some free functionality and help you avoid
@@ -648,6 +658,21 @@ Geospatial schema types were added.
648658

649659
`static` Cake\\Database\\TypeFactory::**map**(string $name, string $class): void
650660

661+
`static` Cake\\Database\\TypeFactory::**getMapped**(string $type): ?string
662+
663+
You can retrieve the mapped class name for a specific type using `getMapped()`:
664+
665+
``` php
666+
use Cake\Database\TypeFactory;
667+
668+
// Returns the class name mapped to the 'datetime' type
669+
$className = TypeFactory::getMapped('datetime');
670+
```
671+
672+
::: info Added in version 5.3.0
673+
`TypeFactory::getMapped()` was added.
674+
:::
675+
651676
If you need to use vendor specific types that are not built into CakePHP you can
652677
add additional new types to CakePHP's type system. Type classes are expected to
653678
implement the following methods:

docs/en/orm/query-builder.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,20 @@ extension).
16201620
`Query::optimizerHint()` was added.
16211621
:::
16221622

1623+
### Getting the Driver
1624+
1625+
`method` Cake\\Database\\Query::**getDriver**(): Driver
1626+
1627+
You can get the `Driver` instance for the current connection role from a query:
1628+
1629+
``` php
1630+
$driver = $query->getDriver();
1631+
```
1632+
1633+
::: info Added in version 5.3.0
1634+
`Query::getDriver()` was added.
1635+
:::
1636+
16231637
## Getting Results
16241638

16251639
Once you've made your query, you'll want to retrieve rows from it. There are

docs/en/orm/validation.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,25 @@ $rules->add($rules->existsIn(
433433
$rules->add($rules->existsIn(['site_id'], 'Sites'));
434434
```
435435

436+
You can also use `existsInNullable()` for nullable composite foreign keys.
437+
This rule allows `null` values in nullable foreign key columns, which is
438+
semantically correct for optional relationships:
439+
440+
``` php
441+
// Allow null values in nullable composite foreign keys.
442+
$rules->add($rules->existsInNullable(
443+
['author_id', 'site_id'],
444+
'SiteAuthors',
445+
));
446+
```
447+
448+
Use `existsInNullable()` instead of `existsIn()` when you want to permit null
449+
values in foreign keys without requiring the `allowNullableNulls` option.
450+
451+
::: info Added in version 5.3.0
452+
The `existsInNullable()` rule was added.
453+
:::
454+
436455
In most SQL databases multi-column `UNIQUE` indexes allow multiple null values
437456
to exist as `NULL` is not equal to itself. While, allowing multiple null
438457
values is the default behavior of CakePHP, you can include null values in your

0 commit comments

Comments
 (0)