Skip to content

Commit 0d8418e

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into 4.5
2 parents 4ef8619 + f7492e5 commit 0d8418e

File tree

12 files changed

+177
-35
lines changed

12 files changed

+177
-35
lines changed

system/Autoloader/Autoloader.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,13 @@ protected function loadInNamespace(string $class)
281281
}
282282

283283
foreach ($this->prefixes as $namespace => $directories) {
284-
foreach ($directories as $directory) {
285-
$directory = rtrim($directory, '\\/');
284+
if (strpos($class, $namespace) === 0) {
285+
$relativeClassPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace)));
286286

287-
if (strpos($class, $namespace) === 0) {
288-
$filePath = $directory . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace))) . '.php';
287+
foreach ($directories as $directory) {
288+
$directory = rtrim($directory, '\\/');
289+
290+
$filePath = $directory . $relativeClassPath . '.php';
289291
$filename = $this->includeFile($filePath);
290292

291293
if ($filename) {

system/I18n/TimeTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ public static function createFromFormat($format, $datetime, $timezone = null)
268268
public static function createFromTimestamp(int $timestamp, $timezone = null, ?string $locale = null)
269269
{
270270
$time = new self(gmdate('Y-m-d H:i:s', $timestamp), 'UTC', $locale);
271-
$timezone ??= 'UTC';
271+
272+
$timezone ??= date_default_timezone_get();
272273

273274
return $time->setTimezone($timezone);
274275
}

tests/system/I18n/TimeTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,21 @@ public function testCreateFromFormatWithInvalidFormat(): void
261261

262262
public function testCreateFromTimestamp(): void
263263
{
264-
// Set the timezone temporarily to UTC to make sure the test timestamp is correct
264+
// Save the current timezone.
265265
$tz = date_default_timezone_get();
266-
date_default_timezone_set('UTC');
267266

268-
$timestamp = strtotime('2017-03-18 midnight');
267+
// Change the timezone other than UTC.
268+
date_default_timezone_set('Asia/Tokyo'); // +09:00
269269

270-
date_default_timezone_set($tz);
270+
$timestamp = strtotime('2017-03-18 midnight');
271271

272272
$time = Time::createFromTimestamp($timestamp);
273273

274-
$this->assertSame(date('2017-03-18 00:00:00'), $time->toDateTimeString());
274+
$this->assertSame('Asia/Tokyo', $time->getTimezone()->getName());
275+
$this->assertSame('2017-03-18 00:00:00', $time->format('Y-m-d H:i:s'));
276+
277+
// Restore timezone.
278+
date_default_timezone_set($tz);
275279
}
276280

277281
public function testCreateFromTimestampWithTimezone(): void

user_guide_src/source/changelogs/v4.4.6.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ Release Date: Unreleased
1414
BREAKING
1515
********
1616

17+
Time::createFromTimestamp()
18+
===========================
19+
20+
A bug that caused :ref:`Time::createFromTimestamp() <time-createfromtimestamp>`
21+
to return a Time instance with a timezone of UTC has been fixed.
22+
23+
Starting with this version, when you do not specify a timezone, a Time instance
24+
with the app's timezone is returned by default.
25+
1726
***************
1827
Message Changes
1928
***************

user_guide_src/source/database/events.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ uses this to collect the queries to display in the Toolbar.
1515
The Events
1616
**********
1717

18+
.. _database-events-dbquery:
19+
1820
DBQuery
1921
=======
2022

21-
This event is triggered whenever a new query has been run, whether successful or not. The only parameter is
22-
a :doc:`Query </database/queries>` instance of the current query. You could use this to display all queries
23-
in STDOUT, or logging to a file, or even creating tools to do automatic query analysis to help you spot
24-
potentially missing indexes, slow queries, etc.
23+
This event is triggered whenever a new query has been run, whether successful or
24+
not. The only parameter is a :doc:`Query </database/queries>` instance of the
25+
current query.
26+
27+
You could use this to display all queries in STDOUT, or logging to a file, or
28+
even creating tools to do automatic query analysis to help you spot potentially
29+
missing indexes, slow queries, etc.
2530

26-
An example usage might be:
31+
An example to log all queries:
2732

2833
.. literalinclude:: events/001.php

user_guide_src/source/installation/running.rst

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,85 @@ Setting Environment
426426

427427
See :ref:`Handling Multiple Environments <environment-nginx>`.
428428

429+
430+
.. _deployment-to-shared-hosting-services:
431+
432+
*************************************
433+
Deployment to Shared Hosting Services
434+
*************************************
435+
436+
.. important::
437+
**index.php** is no longer in the root of the project! It has been moved inside
438+
the **public** folder, for better security and separation of components.
439+
440+
This means that you should configure your web server to "point" to your project's
441+
**public** folder, and not to the project root.
442+
443+
Specifying the Document Root
444+
============================
445+
446+
The best way is to set the document root to the **public** folder in the server
447+
configuration::
448+
449+
└── example.com/ (project folder)
450+
└── public/ (document root)
451+
452+
Check with your hosting service provider to see if you can change the document root.
453+
Unfortunately, if you cannot change the document root, go to the next way.
454+
455+
Using Two Directories
456+
=====================
457+
458+
The second way is to use two directories, and adjust the path.
459+
One is for the application and the other is the default document root.
460+
461+
Upload the contents of the **public** folder to **public_html** (the default
462+
document root) and the other files to the directory for the application::
463+
464+
├── example.com/ (for the application)
465+
│ ├── app/
466+
│ ├── vendor/ (or system/)
467+
│ └── writable/
468+
└── public_html/ (the default document root)
469+
├── .htaccess
470+
├── favicon.ico
471+
├── index.php
472+
└── robots.txt
473+
474+
See
475+
`Install CodeIgniter 4 on Shared Hosting (cPanel) <https://forum.codeigniter.com/showthread.php?tid=76779>`_
476+
for details.
477+
478+
Adding .htaccess
479+
================
480+
481+
The last resort is to add **.htaccess** to the project root.
482+
483+
It is not recommended that you place the project folder in the document root.
484+
However, if you have no other choice, you can use this.
485+
486+
Place your project folder as follows, where **public_html** is the document root,
487+
and create the **.htaccess** file::
488+
489+
└── public_html/ (the default document root)
490+
└── example.com/ (project folder)
491+
├── .htaccess
492+
└── public/
493+
494+
And edit **.htaccess** as follows:
495+
496+
.. code-block:: apache
497+
498+
<IfModule mod_rewrite.c>
499+
RewriteEngine On
500+
RewriteRule ^(.*)$ public/$1 [L]
501+
</IfModule>
502+
503+
<FilesMatch "^\.">
504+
Require all denied
505+
Satisfy All
506+
</FilesMatch>
507+
429508
*********************
430509
Bootstrapping the App
431510
*********************

user_guide_src/source/installation/troubleshooting.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,4 @@ After that, reload the page. You will see the error and the back trace.
102102
CodeIgniter Error Logs
103103
----------------------
104104

105-
CodeIgniter logs error messages, according to the settings in **app/Config/Logger.php**.
106-
107-
You can adjust the error threshold to see more or fewer messages. See :ref:`Logging <logging-configuration>` for details.
108-
109-
The default configuration has daily log files stored in **writable/logs**.
110-
It would be a good idea to check them if things aren't working the way you expect!
105+
See :ref:`codeigniter-error-logs`.

user_guide_src/source/installation/upgrade_446.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ Mandatory File Changes
2020
Breaking Changes
2121
****************
2222

23+
Time::createFromTimestamp() Timezone Change
24+
===========================================
25+
26+
When you do not specify a timezone, now
27+
:ref:`Time::createFromTimestamp() <time-createfromtimestamp>` returns a Time
28+
instance with the app's timezone is returned.
29+
30+
If you want to keep the timezone UTC, you need to call ``setTimezone('UTC')``::
31+
32+
use CodeIgniter\I18n\Time;
33+
34+
$time = Time::createFromTimestamp(1501821586)->setTimezone('UTC');
35+
36+
2337
*********************
2438
Breaking Enhancements
2539
*********************

user_guide_src/source/libraries/cookies/004.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
$cookie->getName(); // 'remember_token'
2323
$cookie->getPrefix(); // '__Secure-'
2424
$cookie->getPrefixedName(); // '__Secure-remember_token'
25-
$cookie->getExpiresTimestamp(); // Unix timestamp
25+
$cookie->getExpiresTimestamp(); // UNIX timestamp
2626
$cookie->getExpiresString(); // 'Fri, 14-Feb-2025 00:00:00 GMT'
2727
$cookie->isExpired(); // false
2828
$cookie->getMaxAge(); // the difference from time() to expires

user_guide_src/source/libraries/time.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,18 @@ and returns a ``Time`` instance, instead of DateTimeImmutable:
114114

115115
.. literalinclude:: time/011.php
116116

117+
.. _time-createfromtimestamp:
118+
117119
createFromTimestamp()
118120
=====================
119121

120122
This method takes a UNIX timestamp and, optionally, the timezone and locale, to create a new Time instance:
121123

122124
.. literalinclude:: time/012.php
123125

126+
.. note:: Due to a bug, prior to v4.4.6, this method returned a Time instance
127+
in timezone UTC when you do not specify a timezone.
128+
124129
createFromInstance()
125130
====================
126131

user_guide_src/source/models/model.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ $dateFormat
209209

210210
This value works with `$useTimestamps`_ and `$useSoftDeletes`_ to ensure that the correct type of
211211
date value gets inserted into the database. By default, this creates DATETIME values, but
212-
valid options are: ``'datetime'``, ``'date'``, or ``'int'`` (a PHP timestamp). Using `$useSoftDeletes`_ or
212+
valid options are: ``'datetime'``, ``'date'``, or ``'int'`` (a UNIX timestamp). Using `$useSoftDeletes`_ or
213213
`$useTimestamps`_ with an invalid or missing `$dateFormat`_ will cause an exception.
214214

215215
$createdField

user_guide_src/source/testing/debugging.rst

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,46 @@
1-
**************************
1+
##########################
22
Debugging Your Application
3-
**************************
3+
##########################
44

55
.. contents::
66
:local:
77
:depth: 2
88

9-
================
10-
Replace var_dump
11-
================
9+
*************
10+
Checking Logs
11+
*************
1212

13-
While using XDebug and a good IDE can be indispensable to debug your application, sometimes a quick ``var_dump()`` is
14-
all you need. CodeIgniter makes that even better by bundling in the excellent `Kint <https://kint-php.github.io/kint/>`_
15-
debugging tool for PHP. This goes way beyond your usual tool, providing many alternate pieces of data, like formatting
16-
timestamps into recognizable dates, showing you hexcodes as colors, display array data like a table for easy reading,
17-
and much, much more.
13+
.. _codeigniter-error-logs:
14+
15+
CodeIgniter Error Logs
16+
======================
17+
18+
CodeIgniter logs error messages, according to the settings in **app/Config/Logger.php**.
19+
20+
The default configuration has daily log files stored in **writable/logs**.
21+
It would be a good idea to check them if things aren't working the way you expect!
22+
23+
You can adjust the error threshold to see more or fewer messages. See
24+
:ref:`Logging <logging-configuration>` for details.
25+
26+
Logging All SQL Queries
27+
=======================
28+
29+
All SQL queries issued by CodeIgniter can be logged.
30+
See :ref:`Database Events <database-events-dbquery>` for details.
31+
32+
********************
33+
Replacing var_dump()
34+
********************
35+
36+
While using Xdebug and a good IDE can be indispensable to debug your application,
37+
sometimes a quick ``var_dump()`` is all you need. CodeIgniter makes that even
38+
better by bundling in the excellent `Kint <https://kint-php.github.io/kint/>`_
39+
debugging tool for PHP.
40+
41+
This goes way beyond your usual tool, providing many alternate pieces of data,
42+
like formatting timestamps into recognizable dates, showing you hexcodes as colors,
43+
display array data like a table for easy reading, and much, much more.
1844

1945
Enabling Kint
2046
=============
@@ -33,6 +59,7 @@ The ``d()`` method dumps all of the data it knows about the contents passed as t
3359
allows the script to continue executing:
3460

3561
.. literalinclude:: debugging/001.php
62+
:lines: 2-
3663

3764
dd()
3865
----
@@ -45,14 +72,15 @@ trace()
4572
This provides a backtrace to the current execution point, with Kint's own unique spin:
4673

4774
.. literalinclude:: debugging/002.php
75+
:lines: 2-
4876

4977
For more information, see `Kint's page <https://kint-php.github.io/kint//>`_.
5078

5179
.. _the-debug-toolbar:
5280

53-
=================
81+
*****************
5482
The Debug Toolbar
55-
=================
83+
*****************
5684

5785
The Debug Toolbar provides at-a-glance information about the current page request, including benchmark results,
5886
queries you have run, request and response data, and more. This can all prove very useful during development

0 commit comments

Comments
 (0)