Skip to content

Commit 3ffbdcc

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
Conflicts: user_guide_src/source/libraries/validation.rst
2 parents 22906b3 + 2118d11 commit 3ffbdcc

File tree

13 files changed

+101
-32
lines changed

13 files changed

+101
-32
lines changed

phpstan-baseline.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@
5656
'count' => 1,
5757
'path' => __DIR__ . '/system/BaseModel.php',
5858
];
59-
$ignoreErrors[] = [
60-
'message' => '#^Only booleans are allowed in &&, string given on the right side\\.$#',
61-
'count' => 7,
62-
'path' => __DIR__ . '/system/BaseModel.php',
63-
];
6459
$ignoreErrors[] = [
6560
'message' => '#^Only booleans are allowed in a ternary operator condition, array\\|null given\\.$#',
6661
'count' => 1,
@@ -2573,7 +2568,7 @@
25732568
];
25742569
$ignoreErrors[] = [
25752570
'message' => '#^Only booleans are allowed in &&, string given on the right side\\.$#',
2576-
'count' => 3,
2571+
'count' => 2,
25772572
'path' => __DIR__ . '/system/Model.php',
25782573
];
25792574
$ignoreErrors[] = [

system/BaseModel.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,11 @@ public function insert($data = null, bool $returnID = true)
750750
// Set created_at and updated_at with same time
751751
$date = $this->setDate();
752752

753-
if ($this->useTimestamps && $this->createdField && ! array_key_exists($this->createdField, $data)) {
753+
if ($this->useTimestamps && $this->createdField !== '' && ! array_key_exists($this->createdField, $data)) {
754754
$data[$this->createdField] = $date;
755755
}
756756

757-
if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $data)) {
757+
if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, $data)) {
758758
$data[$this->updatedField] = $date;
759759
}
760760

@@ -837,11 +837,11 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
837837
// Set created_at and updated_at with same time
838838
$date = $this->setDate();
839839

840-
if ($this->useTimestamps && $this->createdField && ! array_key_exists($this->createdField, $row)) {
840+
if ($this->useTimestamps && $this->createdField !== '' && ! array_key_exists($this->createdField, $row)) {
841841
$row[$this->createdField] = $date;
842842
}
843843

844-
if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $row)) {
844+
if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, $row)) {
845845
$row[$this->updatedField] = $date;
846846
}
847847
}
@@ -909,7 +909,7 @@ public function update($id = null, $data = null): bool
909909
throw DataException::forEmptyDataset('update');
910910
}
911911

912-
if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $data)) {
912+
if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, $data)) {
913913
$data[$this->updatedField] = $this->setDate();
914914
}
915915

@@ -994,7 +994,7 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
994994
$row[$index] = $updateIndex;
995995
}
996996

997-
if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $row)) {
997+
if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, $row)) {
998998
$row[$this->updatedField] = $this->setDate();
999999
}
10001000
}
@@ -1127,7 +1127,7 @@ public function replace(?array $data = null, bool $returnSQL = false)
11271127
return false;
11281128
}
11291129

1130-
if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, (array) $data)) {
1130+
if ($this->useTimestamps && $this->updatedField !== '' && ! array_key_exists($this->updatedField, (array) $data)) {
11311131
$data[$this->updatedField] = $this->setDate();
11321132
}
11331133

system/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ protected function doDelete($id = null, bool $purge = false)
432432

433433
$set[$this->deletedField] = $this->setDate();
434434

435-
if ($this->useTimestamps && $this->updatedField) {
435+
if ($this->useTimestamps && $this->updatedField !== '') {
436436
$set[$this->updatedField] = $this->setDate();
437437
}
438438

user_guide_src/source/extending/core_classes.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,41 @@ System Class List
2222
The following is a list of the core system classes that are invoked every time CodeIgniter runs:
2323

2424
* ``CodeIgniter\Autoloader\Autoloader``
25+
* ``CodeIgniter\Autoloader\FileLocator``
26+
* ``CodeIgniter\Cache\CacheFactory``
27+
* ``CodeIgniter\Cache\Handlers\BaseHandler``
28+
* ``CodeIgniter\Cache\Handlers\FileHandler``
29+
* ``CodeIgniter\Cache\ResponseCache``
2530
* ``CodeIgniter\CodeIgniter``
31+
* ``CodeIgniter\Config\BaseService``
2632
* ``CodeIgniter\Config\DotEnv``
33+
* ``CodeIgniter\Config\Factories``
2734
* ``CodeIgniter\Config\Services``
2835
* ``CodeIgniter\Controller``
36+
* ``CodeIgniter\Cookie\Cookie``
37+
* ``CodeIgniter\Cookie\CookieStore``
2938
* ``CodeIgniter\Debug\Exceptions``
3039
* ``CodeIgniter\Debug\Timer``
3140
* ``CodeIgniter\Events\Events``
3241
* ``CodeIgniter\Filters\Filters``
33-
* ``CodeIgniter\HTTP\ContentSecurityPolicy``
3442
* ``CodeIgniter\HTTP\CLIRequest`` (if launched from command line only)
43+
* ``CodeIgniter\HTTP\ContentSecurityPolicy``
44+
* ``CodeIgniter\HTTP\Header``
3545
* ``CodeIgniter\HTTP\IncomingRequest`` (if launched over HTTP)
46+
* ``CodeIgniter\HTTP\Message``
47+
* ``CodeIgniter\HTTP\OutgoingRequest``
3648
* ``CodeIgniter\HTTP\Request``
3749
* ``CodeIgniter\HTTP\Response``
38-
* ``CodeIgniter\HTTP\Message``
50+
* ``CodeIgniter\HTTP\SiteURI``
51+
* ``CodeIgniter\HTTP\SiteURIFactory``
3952
* ``CodeIgniter\HTTP\URI``
53+
* ``CodeIgniter\HTTP\UserAgent`` (if launched over HTTP)
4054
* ``CodeIgniter\Log\Logger``
4155
* ``CodeIgniter\Log\Handlers\BaseHandler``
4256
* ``CodeIgniter\Log\Handlers\FileHandler``
4357
* ``CodeIgniter\Router\RouteCollection``
4458
* ``CodeIgniter\Router\Router``
59+
* ``CodeIgniter\Superglobals``
4560
* ``CodeIgniter\View\View``
4661

4762
Replacing Core Classes

user_guide_src/source/helpers/cookie_helper.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ The following functions are available:
4242
a description of its use, as this function is an alias for
4343
:php:meth:`CodeIgniter\\HTTP\\Response::setCookie()`.
4444

45+
.. note:: This helper function just sets browser cookies to the global response
46+
instance that ``Services::response()`` returns. So, if you create and
47+
return another response instance (e.g., if you call :php:func:`redirect()`),
48+
the cookies set here will not be sent automatically.
49+
4550
.. php:function:: get_cookie($index[, $xssClean = false[, $prefix = '']])
4651
4752
:param string $index: Cookie name
@@ -78,6 +83,9 @@ The following functions are available:
7883
This function is otherwise identical to :php:func:`set_cookie()`, except that it
7984
does not have the ``value`` and ``expire`` parameters.
8085

86+
This also just sets browser cookies for deleting the cookies to the global
87+
response instance that ``Services::response()`` returns.
88+
8189
.. note:: When you use :php:func:`set_cookie()`,
8290
if the ``value`` is set to empty string and the ``expire`` is set to ``0``, the cookie will be deleted.
8391
If the ``value`` is set to non-empty string and the ``expire`` is set to ``0``, the cookie will only last as long as the browser is open.
@@ -95,4 +103,6 @@ The following functions are available:
95103
:param string $prefix: Cookie prefix
96104
:rtype: bool
97105

98-
Checks if a cookie exists by name. This is an alias of ``Response::hasCookie()``.
106+
Checks if a cookie exists by name in the global response instance that
107+
``Services::response()`` returns. This is an alias of
108+
:php:meth:`CodeIgniter\\HTTP\\Response::hasCookie()`.

user_guide_src/source/incoming/controllers.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ CodeIgniter also permits you to map your URIs using its :ref:`Defined Route Rout
422422
Auto Routing (Legacy)
423423
*********************
424424

425+
.. important:: This feature exists only for backward compatibility. Do not use it
426+
in new projects. Even if you are already using it, we recommend that you use
427+
the :ref:`auto-routing-improved` instead.
428+
425429
This section describes the functionality of Auto Routing (Legacy) that is a routing system from CodeIgniter 3.
426430
It automatically routes an HTTP request, and executes the corresponding controller method
427431
without route definitions. The auto-routing is disabled by default.

user_guide_src/source/incoming/filters.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ filter:check
224224

225225
.. versionadded:: 4.3.0
226226

227-
Check the filters for the route ``/`` with **GET** method:
227+
For example, check the filters for the route ``/`` with **GET** method:
228228

229229
.. code-block:: console
230230
@@ -240,8 +240,9 @@ The output is like the following:
240240
| GET | / | | toolbar |
241241
+--------+-------+----------------+---------------+
242242
243-
You can also see the routes and filters by the ``spark routes`` command.
244-
See :ref:`URI Routing <routing-spark-routes>`.
243+
You can also see the routes and filters by the ``spark routes`` command,
244+
but it might not show accurate filters when you use regular expressions for routes.
245+
See :ref:`URI Routing <routing-spark-routes>` for details.
245246

246247
****************
247248
Provided Filters

user_guide_src/source/incoming/routing.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,10 @@ will be routed to ``Acme\Blog\Controllers\Foo::getBar()``.
817817
Auto Routing (Legacy)
818818
*********************
819819

820+
.. important:: This feature exists only for backward compatibility. Do not use it
821+
in new projects. Even if you are already using it, we recommend that you use
822+
the :ref:`auto-routing-improved` instead.
823+
820824
Auto Routing (Legacy) is a routing system from CodeIgniter 3.
821825
It can automatically route HTTP requests based on conventions and execute the corresponding controller methods.
822826

@@ -931,7 +935,13 @@ The *Route* column shows the route path to match. The route of a defined route i
931935

932936
Since v4.3.0, the *Name* column shows the route name. ``»`` indicates the name is the same as the route path.
933937

934-
.. important:: The system is not perfect. If you use Custom Placeholders, *Filters* might not be correct. If you want to check filters for a route, you can use :ref:`spark filter:check <spark-filter-check>` command.
938+
.. important:: The system is not perfect.
939+
For routes containing regular expression patterns like ``([^/]+)`` or ``{locale}``,
940+
the *Filters* displayed might not be correct (if you set complicated URI pattern
941+
for the filters in **app/Config/Filters.php**), or it is displayed as ``<unknown>``.
942+
943+
The :ref:`spark filter:check <spark-filter-check>` command can be used to check
944+
for 100% accurate filters.
935945

936946
Auto Routing (Improved)
937947
-----------------------

user_guide_src/source/installation/upgrade_4xx.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ Helpers
142142
- In CI4, ``redirect()`` is completely changed from CI3's.
143143
- `redirect() Documentation CodeIgniter 3.X <https://codeigniter.com/userguide3/helpers/url_helper.html#redirect>`_
144144
- `redirect() Documentation CodeIgniter 4.X <../general/common_functions.html#redirect>`_
145-
- In CI4, ``redirect()`` returns a ``RedirectResponse`` instance instead of redirecting and terminating script execution. You must return it.
145+
- In CI4, :php:func:`redirect()` returns a ``RedirectResponse`` instance instead of
146+
redirecting and terminating script execution. You must return it from Controllers
147+
or Controller Filters.
148+
- Cookies and Headers you set before calling ``redirect()`` are not automatically
149+
carried over to a ``RedirectResponse``. You need to call ``withCookies()``
150+
or ``withHeaders()`` manually if you want to send them.
146151
- You need to change CI3's ``redirect('login/form')`` to ``return redirect()->to('login/form')``.
147152

148153
Hooks

user_guide_src/source/libraries/curlrequest.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ Config for CURLRequest
2828
Sharing Options
2929
===============
3030

31-
.. note:: Since v4.4.0, the default value has been changed to ``false``. This
32-
setting exists only for backward compatibility. New users do not need to
33-
change the setting.
31+
.. important:: This setting exists only for backward compatibility. Do not use it
32+
in new projects. Even if you are already using it, we recommend that you disable
33+
it.
34+
35+
.. note:: Since v4.4.0, the default value has been changed to ``false``.
3436

3537
If you want to share all the options between requests, set ``$shareOptions`` to
3638
``true`` in **app/Config/CURLRequest.php**:

user_guide_src/source/libraries/validation.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ The **Strict Rules** don't use implicit type conversion.
234234
Traditional Rules
235235
-----------------
236236

237+
.. important:: Traditional Rules exist only for backward compatibility. Do not
238+
use them in new projects. Even if you are already using them, we recommend
239+
switching to Strict Rules.
240+
237241
.. warning:: When validating data that contains non-string values, such as JSON data,
238242
you should use **Strict Rules**.
239243

user_guide_src/source/models/model.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ $createdField
180180
^^^^^^^^^^^^^
181181

182182
Specifies which database field to use for data record create timestamp.
183-
Leave it empty to avoid updating it (even if ``$useTimestamps`` is enabled).
183+
Leave it empty (``''``) to avoid updating it (even if ``$useTimestamps`` is enabled).
184184

185185
$updatedField
186186
^^^^^^^^^^^^^
187187

188188
Specifies which database field should use for keep data record update timestamp.
189-
Leave it empty to avoid update it (even ``$useTimestamps`` is enabled).
189+
Leave it empty (``''``) to avoid updating it (even ``$useTimestamps`` is enabled).
190190

191191
$deletedField
192192
^^^^^^^^^^^^^

user_guide_src/source/outgoing/response.rst

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ a server responding to the client that called it.
1212
Working with the Response
1313
=========================
1414

15-
A Response class is instantiated for you and passed into your controllers. It can be accessed through
16-
``$this->response``. Many times you will not need to touch the class directly, since CodeIgniter takes care of
15+
A Response class is instantiated for you and passed into your controllers. It can
16+
be accessed through ``$this->response``. It is the same instance that
17+
``Services::response()`` returns. We call it the global response instance.
18+
19+
Many times you will not need to touch the class directly, since CodeIgniter takes care of
1720
sending the headers and the body for you. This is great if the page successfully created the content it was asked to.
1821
When things go wrong, or you need to send very specific status codes back, or even take advantage of the
1922
powerful HTTP caching, it's there for you.
@@ -40,20 +43,36 @@ You can set format an array into either JSON or XML and set the content type hea
4043
Setting Headers
4144
---------------
4245

46+
setHeader()
47+
^^^^^^^^^^^
48+
4349
Often, you will need to set headers to be set for the response. The Response class makes this very simple to do,
44-
with the ``setHeader()`` method. The first parameter is the name of the header. The second parameter is the value,
50+
with the ``setHeader()`` method.
51+
52+
The first parameter is the name of the header. The second parameter is the value,
4553
which can be either a string or an array of values that will be combined correctly when sent to the client.
54+
55+
.. literalinclude:: response/004.php
56+
4657
Using these functions instead of using the native PHP functions allows you to ensure that no headers are sent
4758
prematurely, causing errors, and makes testing possible.
4859

49-
.. literalinclude:: response/004.php
60+
.. note:: This method just sets headers to the response instance. So, if you create
61+
and return another response instance (e.g., if you call :php:func:`redirect()`),
62+
the headers set here will not be sent automatically.
63+
64+
appendHeader()
65+
^^^^^^^^^^^^^^
5066

5167
If the header exists and can have more than one value, you may use the ``appendHeader()`` and ``prependHeader()``
5268
methods to add the value to the end or beginning of the values list, respectively. The first parameter is the name
5369
of the header, while the second is the value to append or prepend.
5470

5571
.. literalinclude:: response/005.php
5672

73+
removeHeader()
74+
^^^^^^^^^^^^^^
75+
5776
Headers can be removed from the response with the ``removeHeader()`` method, which takes the header name as the only
5877
parameter. This is not case-sensitive.
5978

@@ -384,7 +403,9 @@ The methods provided by the parent class that are available are:
384403
.. note:: Prior to v4.2.7, the default values of ``$secure`` and ``$httponly`` were ``false``
385404
due to a bug, and these values from **app/Config/Cookie.php** were never used.
386405

387-
Sets a cookie containing the values you specify. There are two ways to
406+
Sets a cookie containing the values you specify to the Response instance.
407+
408+
There are two ways to
388409
pass information to this method so that a cookie can be set: Array
389410
Method, and Discrete Parameters:
390411

@@ -439,6 +460,8 @@ The methods provided by the parent class that are available are:
439460

440461
Delete an existing cookie.
441462

463+
.. note:: This also just sets browser cookie for deleting the cookie.
464+
442465
Only the ``name`` is required.
443466

444467
The ``prefix`` is only needed if you need to avoid name collisions with

0 commit comments

Comments
 (0)