Skip to content

Commit c7b880e

Browse files
committed
Merge branch '5.x' into 5.next
2 parents 3be4980 + b535c9b commit c7b880e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+439
-427
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ Global
2828
- Type declarations were added to all class properties where possible. These also include some fixes for
2929
incorrect annotations.
3030
- The ``SECOND``, ``MINUTE``, ``HOUR``, ``DAY``, ``WEEK``, ``MONTH``, ``YEAR`` constants were removed.
31-
- Global functions are now opt-in. If your application uses global function
32-
aliases be sure to add ``require CAKE . 'functions.php'`` to you application's
33-
``config/bootstrap.php``.
31+
- Use of ``#[\AllowDynamicProperties]`` removed everywhere. It was used for the following classes:
32+
- ``Command/Command``
33+
- ``Console/Shell``
34+
- ``Controller/Component``
35+
- ``Controller/Controller``
36+
- ``Mailer/Mailer``
37+
- ``View/Cell``
38+
- ``View/Helper``
39+
- ``View/View``
3440
- The supported database engine versions were updated:
35-
- MySQL (5.7 or higher)
36-
- MariaDB (10.1 or higher)
37-
- PostgreSQL (9.6 or higher)
38-
- Microsoft SQL Server (2012 or higher)
39-
- SQLite 3
41+
- MySQL (5.7 or higher)
42+
- MariaDB (10.1 or higher)
43+
- PostgreSQL (9.6 or higher)
44+
- Microsoft SQL Server (2012 or higher)
45+
- SQLite 3
4046

4147
Auth
4248
----
@@ -123,6 +129,8 @@ Database
123129
``QueryExpression::case()`` or ``CaseStatementExpression``
124130
- ``Connection::connect()`` has been removed. Use
125131
``$connection->getDriver()->connect()`` instead.
132+
- ``Connection::disconnect()`` has been removed. Use
133+
``$connection->getDriver()->disconnect()`` instead.
126134
- ``cake.database.queries`` has been added as an alternative to the ``queriesLog`` scope
127135

128136
Datasource
@@ -385,7 +393,7 @@ A similar change has been applied to the ``RepositoryInterface::get()`` method::
385393
{
386394
$author = $this->Authors->get($id, [
387395
'contain' => ['Books'],
388-
'finder' => 'latest'
396+
'finder' => 'latest',
389397
]);
390398
}
391399

en/console-commands/commands.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ simple Hello world command. In your application's **src/Command** directory crea
2727
public function execute(Arguments $args, ConsoleIo $io): int
2828
{
2929
$io->out('Hello world.');
30-
30+
3131
return static::CODE_SUCCESS;
3232
}
3333
}
@@ -60,7 +60,7 @@ command line::
6060
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
6161
{
6262
$parser->addArgument('name', [
63-
'help' => 'What is your name'
63+
'help' => 'What is your name',
6464
]);
6565
return $parser;
6666
}
@@ -69,7 +69,7 @@ command line::
6969
{
7070
$name = $args->getArgument('name');
7171
$io->out("Hello {$name}.");
72-
72+
7373
return static::CODE_SUCCESS;
7474
}
7575
}
@@ -111,11 +111,11 @@ add a ``yell`` option to our ``HelloCommand``::
111111
{
112112
$parser
113113
->addArgument('name', [
114-
'help' => 'What is your name'
114+
'help' => 'What is your name',
115115
])
116116
->addOption('yell', [
117117
'help' => 'Shout the name',
118-
'boolean' => true
118+
'boolean' => true,
119119
]);
120120

121121
return $parser;
@@ -128,7 +128,7 @@ add a ``yell`` option to our ``HelloCommand``::
128128
$name = mb_strtoupper($name);
129129
}
130130
$io->out("Hello {$name}.");
131-
131+
132132
return static::CODE_SUCCESS;
133133
}
134134

@@ -202,7 +202,7 @@ to terminate execution::
202202
$io->error('Name must be at least 4 characters long.');
203203
$this->abort();
204204
}
205-
205+
206206
return static::CODE_SUCCESS;
207207
}
208208

@@ -215,7 +215,7 @@ You can also use ``abort()`` on the ``$io`` object to emit a message and code::
215215
// Halt execution, output to stderr, and set exit code to 99
216216
$io->abort('Name must be at least 4 characters long.', 99);
217217
}
218-
218+
219219
return static::CODE_SUCCESS;
220220
}
221221

@@ -376,7 +376,7 @@ conventions. Let's continue by adding more logic to our command::
376376
'modified' => new DateTime()
377377
])
378378
->execute();
379-
379+
380380
return static::CODE_SUCCESS;
381381
}
382382
}
@@ -397,7 +397,7 @@ Modify your test case to the following snippet of code::
397397

398398
protected $fixtures = [
399399
// assumes you have a UsersFixture
400-
'app.Users'
400+
'app.Users',
401401
];
402402

403403
public function testDescriptionOutput()
@@ -477,7 +477,7 @@ Update the command class to the following::
477477
'modified' => new DateTime()
478478
])
479479
->execute();
480-
480+
481481
return static::CODE_SUCCESS;
482482
}
483483
}

en/console-commands/option-parsers.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ If you have an array with multiple arguments you can use
7474

7575
$parser->addArguments([
7676
'node' => ['help' => 'The node to create', 'required' => true],
77-
'parent' => ['help' => 'The parent node', 'required' => true]
77+
'parent' => ['help' => 'The parent node', 'required' => true],
7878
]);
7979

8080
As with all the builder methods on ConsoleOptionParser, addArguments
@@ -91,7 +91,7 @@ valid choices::
9191
$parser->addArgument('type', [
9292
'help' => 'The type of node to interact with.',
9393
'required' => true,
94-
'choices' => ['aro', 'aco']
94+
'choices' => ['aro', 'aco'],
9595
]);
9696

9797
The above will create an argument that is required and has validation on the
@@ -101,7 +101,7 @@ will be raised and the shell will be stopped.
101101
Using Options
102102
=============
103103

104-
.. php:method:: addOption($name, $options = [])
104+
.. php:method:: addOption($name, array $options = [])
105105
106106
Options or flags are used in command line tools to provide unordered key/value
107107
arguments for your commands. Options can define both verbose and short aliases.
@@ -154,7 +154,7 @@ to add multiple options at once. ::
154154

155155
$parser->addOptions([
156156
'node' => ['short' => 'n', 'help' => 'The node to create'],
157-
'parent' => ['short' => 'p', 'help' => 'The parent node']
157+
'parent' => ['short' => 'p', 'help' => 'The parent node'],
158158
]);
159159

160160
As with all the builder methods on ConsoleOptionParser, addOptions can be used
@@ -169,7 +169,7 @@ for an option. All other values will raise an ``InvalidArgumentException``::
169169

170170
$parser->addOption('accept', [
171171
'help' => 'What version to accept.',
172-
'choices' => ['working', 'theirs', 'mine']
172+
'choices' => ['working', 'theirs', 'mine'],
173173
]);
174174

175175
Using Boolean Options
@@ -204,14 +204,14 @@ subcommand parsers easier, as everything is an array::
204204
'description' => [
205205
__("Use this command to grant ACL permissions. Once executed, the "),
206206
__("ARO specified (and its children, if any) will have ALLOW access "),
207-
__("to the specified ACO action (and the ACO's children, if any).")
207+
__("to the specified ACO action (and the ACO's children, if any)."),
208208
],
209209
'arguments' => [
210210
'aro' => ['help' => __('ARO to check.'), 'required' => true],
211211
'aco' => ['help' => __('ACO to check.'), 'required' => true],
212-
'action' => ['help' => __('Action to check')]
213-
]
214-
]
212+
'action' => ['help' => __('Action to check')],
213+
],
214+
],
215215
]);
216216

217217
Inside the parser spec, you can define keys for ``arguments``, ``options``,
@@ -232,8 +232,8 @@ use buildFromArray on its own, to build an option parser::
232232
'arguments' => [
233233
'aro' => ['help' => __('ARO to check.'), 'required' => true],
234234
'aco' => ['help' => __('ACO to check.'), 'required' => true],
235-
'action' => ['help' => __('Action to check')]
236-
]
235+
'action' => ['help' => __('Action to check')],
236+
],
237237
]);
238238
}
239239

en/controllers.rst

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ This would render **plugins/Users/templates/UserDetails/custom_file.php**
282282
Content Type Negotiation
283283
========================
284284

285-
.. php:method:: viewClasses()
285+
.. php:method:: addViewClasses()
286286
287287
Controllers can define a list of view classes they support. After the
288288
controller's action is complete CakePHP will use the view list to perform
289-
content-type negotiation with either :ref:`file-extensions` or ``Content-Type``
289+
content-type negotiation with either :ref:`file-extensions` or ``Accept``
290290
headers. This enables your application to re-use the same controller action to
291291
render an HTML view or render a JSON or XML response. To define the list of
292-
supported view classes for a controller is done with the ``viewClasses()``
292+
supported view classes for a controller is done with the ``addViewClasses()``
293293
method::
294294

295295
namespace App\Controller;
@@ -299,25 +299,25 @@ method::
299299

300300
class PostsController extends AppController
301301
{
302-
public function viewClasses(): array
302+
public function initialize(): void
303303
{
304-
return [JsonView::class, XmlView::class];
304+
parent::initialize();
305+
306+
$this->addViewClasses([JsonView::class, XmlView::class]);
305307
}
306308
}
307309

308310
The application's ``View`` class is automatically used as a fallback when no
309311
other view can be selected based on the request's ``Accept`` header or routing
310312
extension. If your application only supports content types for a specific
311-
actions, you can define that logic within ``viewClasses()``::
313+
actions, you can call ``addClasses()`` within your action too::
312314

313-
public function viewClasses(): array
315+
public function export(): void
314316
{
315-
if ($this->request->getParam('action') === 'export') {
316-
// Use a custom CSV view for data exports.
317-
return [CsvView::class];
318-
}
317+
// Use a custom CSV view for data exports.
318+
$this->addViewClasses([CsvView::class]);
319319

320-
return [JsonView::class];
320+
// Rest of the action code
321321
}
322322

323323
If within your controller actions you need to process request or load data
@@ -331,9 +331,9 @@ differently based on the controller action you can use
331331
$query->contain('Authors');
332332
}
333333

334-
You can also set your controllers' supported view classes
335-
using the ``addViewClasses()`` method which will merge the provided views with
336-
those held in the ``viewClasses`` property.
334+
In case your app need more complex logic to decide which view classes to use
335+
then you can override the ``Controller::viewClasses()`` method and return
336+
an array of view classes as required.
337337

338338
.. note::
339339
View classes must implement the static ``contentType()`` hook method to
@@ -344,13 +344,15 @@ Content Type Negotiation Fallbacks
344344

345345
If no View can be matched with the request's content type preferences, CakePHP
346346
will use the base ``View`` class. If you want to require content-type
347-
negotiation, you can use the ``NegotiationRequiredView`` which sets a 406 status
347+
negotiation, you can use the ``NegotiationRequiredView`` which sets a ``406`` status
348348
code::
349349

350-
public function viewClasses(): array
350+
public function initialize(): void
351351
{
352+
parent::initialize();
353+
352354
// Require Accept header negotiation or return a 406 response.
353-
return [JsonView::class, NegotiationRequiredView::class];
355+
$this->addViewClasses([JsonView::class, NegotiationRequiredView::class]);
354356
}
355357

356358
You can use the ``TYPE_MATCH_ALL`` content type value to build your own fallback
@@ -372,6 +374,22 @@ view logic::
372374
It is important to remember that match-all views are applied only *after*
373375
content-type negotiation is attempted.
374376

377+
Using AjaxView
378+
==============
379+
380+
In applications that use hypermedia or AJAX clients, you often need to render
381+
view contents without the wrapping layout. You can use the ``AjaxView`` that
382+
is bundled with the application skeleton::
383+
384+
// In a controller action, or in beforeRender.
385+
if ($this->request->is('ajax')) {
386+
$this->viewBuilder()->setClassName('Ajax');
387+
}
388+
389+
``AjaxView`` will respond as ``text/html`` and use the ``ajax`` layout.
390+
Generally this layout is minimal or contains client specific markup. This
391+
replaces usage of ``RequestHandlerComponent`` automatically using the
392+
``AjaxView`` in 4.x.
375393

376394
Redirecting to Other Pages
377395
==========================
@@ -476,8 +494,8 @@ behaves::
476494
{
477495
protected array $paginate = [
478496
'Articles' => [
479-
'conditions' => ['published' => 1]
480-
]
497+
'conditions' => ['published' => 1],
498+
],
481499
];
482500
}
483501

en/controllers/components.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ implementation::
7878
public function initialize(): void
7979
{
8080
$this->loadComponent('Flash', [
81-
'className' => 'MyFlash'
81+
'className' => 'MyFlash',
8282
]);
8383
}
8484
}
@@ -212,7 +212,7 @@ the Component::
212212
parent::initialize();
213213
$this->loadComponent('Math', [
214214
'precision' => 2,
215-
'randomGenerator' => 'srand'
215+
'randomGenerator' => 'srand',
216216
]);
217217
$this->loadComponent('Csrf');
218218
}
@@ -234,7 +234,7 @@ You can load other components by adding them to the `$components` property::
234234
class CustomComponent extends Component
235235
{
236236
// The other component your component uses
237-
protected $components = ['Existing'];
237+
protected array $components = ['Existing'];
238238

239239
// Execute any other additional setup for your component.
240240
public function initialize(array $config): void

en/controllers/components/flash.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ An example of using these options::
5757
'clear' => true,
5858
'params' => [
5959
'name' => $user->name,
60-
'email' => $user->email
61-
]
60+
'email' => $user->email,
61+
],
6262
]);
6363

6464
// In your View

en/controllers/pagination.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ from the URL::
4545
protected array $paginate = [
4646
'limit' => 25,
4747
'order' => [
48-
'Articles.title' => 'asc'
49-
]
48+
'Articles.title' => 'asc',
49+
],
5050
];
5151
}
5252

@@ -215,8 +215,8 @@ pagination query::
215215

216216
protected array $paginate = [
217217
'sortableFields' => [
218-
'id', 'title', 'Users.username', 'created'
219-
]
218+
'id', 'title', 'Users.username', 'created',
219+
],
220220
];
221221

222222
Any requests that attempt to sort on fields not in the allowed list will be

0 commit comments

Comments
 (0)