Skip to content

Commit 6015bfc

Browse files
committed
Merge branch '5.x' into 5.next
2 parents a2c2ab2 + 97d83e1 commit 6015bfc

File tree

14 files changed

+143
-197
lines changed

14 files changed

+143
-197
lines changed

en/controllers/request-response.rst

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,24 @@ replace all possibly existing uploaded files::
251251
PUT, PATCH or DELETE Data
252252
-------------------------
253253

254-
.. php:method:: input($callback, [$options])
254+
.. php:method:: getBody()
255255
256256
When building REST services, you often accept request data on ``PUT`` and
257257
``DELETE`` requests. Any ``application/x-www-form-urlencoded`` request body data
258-
will automatically be parsed and set to ``$this->data`` for ``PUT`` and
259-
``DELETE`` requests. If you are accepting JSON or XML data, see below for how
260-
you can access those request bodies.
258+
will automatically be parsed and available via ``$request->getData()`` for ``PUT`` and
259+
``DELETE`` requests. If you are accepting JSON or XML data, you can
260+
access the raw data with ``getBody()``::
261261

262-
When accessing the input data, you can decode it with an optional function.
263-
This is useful when interacting with XML or JSON request body content.
264-
Additional parameters for the decoding function can be passed as arguments to
265-
``input()``::
262+
// Get the stream wrapper on the request body
263+
$body = $request->getBody();
266264

267-
$jsonData = $this->request->input('json_decode');
265+
// Get the request body as a string
266+
$bodyString = (string)$request->getBody();
267+
268+
If your requests contain XML or JSON request content, you should consider using
269+
:ref:`body-parser-middleware` to have CakePHP automatically parse those content
270+
types making the parsed data available in ``$request->getData()`` and
271+
``$request->getParsedBody()``.
268272

269273
Environment Variables (from $_SERVER and $_ENV)
270274
-----------------------------------------------
@@ -953,7 +957,7 @@ that uniquely identifies the requested resource, as a checksum does for a file,
953957
in order to determine whether it matches a cached resource.
954958

955959
To take advantage of this header, you must either call the
956-
``checkNotModified()`` method manually or include the
960+
``isNotModified()`` method manually or include the
957961
:doc:`/controllers/components/check-http-cache` in your controller::
958962

959963
public function index()
@@ -966,7 +970,7 @@ To take advantage of this header, you must either call the
966970
$checksum = md5(json_encode($articles));
967971

968972
$response = $this->response->withEtag($checksum);
969-
if ($response->checkNotModified($this->request)) {
973+
if ($response->isNotModified($this->request)) {
970974
return $response;
971975
}
972976

@@ -990,14 +994,14 @@ last time. Setting this header helps CakePHP tell caching clients whether the
990994
response was modified or not based on their cache.
991995

992996
To take advantage of this header, you must either call the
993-
``checkNotModified()`` method manually or include the
997+
``isNotModified()`` method manually or include the
994998
:doc:`/controllers/components/check-http-cache` in your controller::
995999

9961000
public function view()
9971001
{
9981002
$article = $this->Articles->find()->first();
9991003
$response = $this->response->withModified($article->modified);
1000-
if ($response->checkNotModified($this->request)) {
1004+
if ($response->isNotModified($this->request)) {
10011005
return $response;
10021006
}
10031007
$this->response;
@@ -1021,14 +1025,14 @@ header::
10211025
Sending Not-Modified Responses
10221026
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10231027

1024-
.. php:method:: checkNotModified(Request $request)
1028+
.. php:method:: isNotModified(Request $request)
10251029
10261030
Compares the cache headers for the request object with the cache header from the
10271031
response and determines whether it can still be considered fresh. If so, deletes
10281032
the response content, and sends the `304 Not Modified` header::
10291033

10301034
// In a controller action.
1031-
if ($this->response->checkNotModified($this->request)) {
1035+
if ($this->response->isNotModified($this->request)) {
10321036
return $this->response;
10331037
}
10341038

en/core-libraries/time.rst

Lines changed: 17 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,18 @@ use the ``DateTime`` class::
3131

3232
Under the hood, CakePHP uses `Chronos <https://github.com/cakephp/chronos>`_
3333
to power its ``DateTime`` utility. Anything you can do with ``Chronos`` and
34-
PHP's ``DateTime``, you can do with ``DateTime`` and ``Date``.
34+
PHP's ``DateTimeImmutable``, you can do with ``DateTime``.
3535

3636
For more details on Chronos please see `the API documentation
37-
<https://api.cakephp.org/chronos/1.0/>`_.
37+
<https://api.cakephp.org/chronos/>`_.
3838

3939
.. start-time
4040
4141
Creating DateTime Instances
42-
=============================
42+
===========================
4343

44-
``DateTime`` are immutable objects that are useful when you want to prevent
45-
accidental changes to data, or when you want to avoid order based dependency
46-
issues.
44+
``DateTime`` are immutable objects as immutability prevents accidental changes
45+
to data, and avoids order based dependency issues.
4746

4847
There are a few ways to create ``DateTime`` instances::
4948

@@ -407,85 +406,25 @@ You can also compare a ``DateTime`` instance within a range in the past::
407406
Date
408407
====
409408

410-
.. php:class: Date
411-
412-
The immutable ``Date`` class in CakePHP implements a similar API and methods as
413-
:php:class:`Cake\\I18n\\DateTime` does. The main difference between ``DateTime``
414-
and ``Date`` is that ``Date`` does not track time components. As an example::
415-
416-
use Cake\I18n\Date;
417-
418-
$date = new Date('2021-01-31');
419-
420-
$newDate = $date->modify('+2 hours');
421-
// Outputs '2021-01-31 00:00:00'
422-
echo $newDate->format('Y-m-d H:i:s');
423-
424-
$newDate = $date->addHours(36);
425-
// Outputs '2021-01-31 00:00:00'
426-
echo $newDate->format('Y-m-d H:i:s');
427-
428-
$newDate = $date->addDays(10);
429-
// Outputs '2021-02-10 00:00:00'
430-
echo $newDate->format('Y-m-d H:i:s');
431-
432-
433-
Attempts to modify the timezone on a ``Date`` instance are also ignored::
434-
435-
use Cake\I18n\Date;
436-
$date = new Date('2021-01-31', new \DateTimeZone('America/New_York'));
437-
$newDate = $date->setTimezone(new \DateTimeZone('Europe/Berlin'));
438-
439-
// Outputs 'America/New_York'
440-
echo $newDate->format('e');
441-
442-
.. _mutable-time:
443-
444-
Mutable Dates and Times
445-
=======================
446-
447-
.. php:class:: Time
448409
.. php:class:: Date
449410
450-
CakePHP uses mutable date and time classes that implement the same interface
451-
as their immutable siblings. Immutable objects are useful when you want to prevent
452-
accidental changes to data, or when you want to avoid order based dependency
453-
issues. Take the following code::
454-
455-
use Cake\I18n\Time;
456-
$time = new Time('2015-06-15 08:23:45');
457-
$time->modify('+2 hours');
458-
459-
// This method also modifies the $time instance
460-
$this->someOtherFunction($time);
461-
462-
// Output here is unknown.
463-
echo $time->format('Y-m-d H:i:s');
464-
465-
If the method call was re-ordered, or if ``someOtherFunction`` changed the
466-
output could be unexpected. The mutability of our object creates temporal
467-
coupling. If we were to use immutable objects, we could avoid this issue::
411+
The immutable ``Date`` class in CakePHP represents calendar dates unaffected by
412+
time and timezones. The ``Date`` class wraps the ``Cake\\Chronos\\ChronosDate`` class.
468413

469-
use Cake\I18n\DateTime;
470-
$time = new DateTime('2015-06-15 08:23:45');
471-
$time = $time->modify('+2 hours');
472-
473-
// This method's modifications don't change $time
474-
$this->someOtherFunction($time);
414+
.. note::
475415

476-
// Output here is known.
477-
echo $time->format('Y-m-d H:i:s');
416+
Unlike the ``DateTime`` class, ``Date`` does not extends the ``DateTimeInterface``.
417+
So you cannot cannot directly compare a ``Date`` instance with a ``DateTime`` instance.
418+
But you can do comparisons like ``$dateTime->toNative() > $date->toNative()``.
478419

479-
Immutable dates and times are useful in entities as they prevent
480-
accidental modifications, and force changes to be explicit. Using
481-
immutable objects helps the ORM to more easily track changes, and ensure that
482-
date and datetime columns are persisted correctly::
420+
Time
421+
====
483422

484-
// This change will be lost when the article is saved.
485-
$article->updated->modify('+1 hour');
423+
.. php:class:: Time
486424
487-
// By replacing the time object the property will be saved.
488-
$article->updated = $article->updated->modify('+1 hour');
425+
The ``Time`` class represents clock times independent of date or time zones
426+
Similar to the ``DateTime`` and ```Date`` classes, the ``Time`` class is also immutable.
427+
It wraps the ``Cake\\Chronos\\ChronosTime`` class.
489428

490429
Accepting Localized Request Data
491430
================================

en/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CakePHP 5 is a web development framework running on PHP |phpversion| (min. PHP
55
|minphpversion|). Read :doc:`CakePHP at a Glance </intro>` to get an
66
introduction to the fundamentals of CakePHP.
77

8-
The CakePHP cookbook is an openly developed and community editable documentation
8+
The CakePHP book is an openly developed and community editable documentation
99
project. Notice the pencil icon button fixated against the right wall; it will
1010
direct you to the GitHub online editor of the active page, allowing you to
1111
contribute any additions, deletions, or corrections to the documentation.
@@ -16,7 +16,7 @@ contribute any additions, deletions, or corrections to the documentation.
1616

1717
.. image:: /_static/img/read-the-book.jpg
1818

19-
Enjoy the CakePHP cookbook almost anywhere. Available as both a PDF and
19+
Enjoy the CakePHP book almost anywhere. Available as both a PDF and
2020
EPUB, you can now read it on more devices, as well as offline.
2121

2222
- `PDF <../_downloads/en/CakePHPBook.pdf>`_
@@ -53,5 +53,5 @@ elements in a CakePHP application:
5353
validation, and domain logic within your application.
5454

5555
.. meta::
56-
:title lang=en: .. CakePHP Cookbook documentation master file, created by
57-
:keywords lang=en: doc models,documentation master,presentation layer,documentation project,quickstart,original source,sphinx,liking,cookbook,validity,conventions,validation,cakephp,accuracy,storage and retrieval,heart,blog,project hope
56+
:title lang=en: .. CakePHP book documentation master file, created by
57+
:keywords lang=en: doc models,documentation master,presentation layer,documentation project,quickstart,original source,sphinx,liking,book,validity,conventions,validation,cakephp,accuracy,storage and retrieval,heart,blog,project hope

en/tutorials-and-examples/cms/articles-model.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ look like this::
5959
class Article extends Entity
6060
{
6161
protected array $_accessible = [
62+
'user_id' => true,
6263
'title' => true,
64+
'slug' => true,
6365
'body' => true,
6466
'published' => true,
6567
'created' => true,
6668
'modified' => true,
67-
'users' => true,
69+
'user' => true,
70+
'tags' => true,
6871
];
6972
}
7073

0 commit comments

Comments
 (0)