Skip to content

Commit 57b209a

Browse files
committed
Add missing 5.4 migration guide entries
- Component-alias/default-table collision warning - PSR-13 link support on Response - New collection helpers: keys(), values(), implode(), when(), unless()
1 parent 2554f33 commit 57b209a

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

docs/en/appendices/5-4-migration-guide.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ The default eager loading strategy for `HasMany` and `BelongsToMany` association
2727
has changed from `select` to `subquery`. If you need the previous behavior,
2828
explicitly set `'strategy' => 'select'` when defining associations.
2929

30+
### Controller
31+
32+
When loading a component that has the same alias as the controller's default table,
33+
CakePHP now triggers a warning. This helps identify situations where accessing
34+
`$this->ComponentAlias` returns the table instead of the component:
35+
36+
```php
37+
class PaymentsController extends AppController
38+
{
39+
public function initialize(): void
40+
{
41+
parent::initialize();
42+
// Triggers warning: Component alias `Payments` clashes with the default table name
43+
$this->loadComponent('Payments');
44+
}
45+
}
46+
```
47+
48+
To resolve this, either use a different component alias or set `Controller::$defaultTable`
49+
to an empty string if the controller doesn't use a table.
50+
3051
## Deprecations
3152

3253
- WIP
@@ -60,12 +81,60 @@ explicitly set `'strategy' => 'select'` when defining associations.
6081
nested array format matching `contain()` syntax.
6182
See [Converting Request Data into Entities](../orm/saving-data#converting-request-data-into-entities).
6283

84+
### Http
85+
86+
- Added PSR-13 Link implementation with `Cake\Http\Link\Link` and `Cake\Http\Link\LinkProvider`
87+
classes for hypermedia link support. Links added to responses are automatically emitted
88+
as HTTP `Link` headers.
89+
90+
```php
91+
use Cake\Http\Link\Link;
92+
93+
// Add links to a response
94+
$response = $response->withLink(new Link('/api/users', 'self'));
95+
$response = $response->withLink(
96+
(new Link('/api/users?page=2'))
97+
->withRel('next')
98+
->withAttribute('type', 'application/json'),
99+
);
100+
101+
// Preload resources
102+
$response = $response->withLink(
103+
(new Link('/css/app.css'))
104+
->withRel('preload')
105+
->withAttribute('as', 'style'),
106+
);
107+
```
108+
63109
### Utility
64110

65111
- Added `Cake\Utility\Fs\Finder` class for fluent file discovery with pattern matching,
66112
depth control, and custom filters. Added `Cake\Utility\Fs\Path` for cross-platform
67113
path manipulation.
68114

115+
### Collection
116+
117+
- Added `keys()` method to return a collection containing only the keys.
118+
- Added `values()` method to return a collection of values re-indexed with consecutive integers.
119+
- Added `implode()` method to concatenate elements into a string, with optional path extraction.
120+
- Added `when()` and `unless()` methods for conditional method chaining.
121+
122+
```php
123+
// keys() and values()
124+
$collection = new Collection(['a' => 1, 'b' => 2]);
125+
$collection->keys()->toList(); // ['a', 'b']
126+
$collection->values()->toList(); // [1, 2]
127+
128+
// implode() with path extraction
129+
$collection = new Collection([['name' => 'foo'], ['name' => 'bar']]);
130+
$collection->implode(', ', 'name'); // 'foo, bar'
131+
132+
// Conditional chaining with when() and unless()
133+
$collection = new Collection($items)
134+
->when($shouldFilter, fn($c) => $c->filter(fn($v) => $v['active']))
135+
->unless($hasDefaults, fn($c) => $c->append($defaults));
136+
```
137+
69138
### View
70139

71140
- Added `{{inputId}}` template variable to `inputContainer` and `error` templates

0 commit comments

Comments
 (0)