Skip to content

Commit f65a2cf

Browse files
committed
Release v4.2.1
1 parent 29f0e9e commit f65a2cf

File tree

23 files changed

+123
-58
lines changed

23 files changed

+123
-58
lines changed

app/Config/Mimes.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ class Mimes
102102
],
103103
'pptx' => [
104104
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
105-
'application/x-zip',
106-
'application/zip',
107105
],
108106
'wbxml' => 'application/wbxml',
109107
'wmlc' => 'application/wmlc',
@@ -512,20 +510,19 @@ public static function guessExtensionFromType(string $type, ?string $proposedExt
512510

513511
$proposedExtension = trim(strtolower($proposedExtension ?? ''));
514512

515-
if ($proposedExtension !== '') {
516-
if (array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true)) {
517-
// The detected mime type matches with the proposed extension.
518-
return $proposedExtension;
519-
}
520-
521-
// An extension was proposed, but the media type does not match the mime type list.
522-
return null;
513+
if (
514+
$proposedExtension !== ''
515+
&& array_key_exists($proposedExtension, static::$mimes)
516+
&& in_array($type, (array) static::$mimes[$proposedExtension], true)
517+
) {
518+
// The detected mime type matches with the proposed extension.
519+
return $proposedExtension;
523520
}
524521

525522
// Reverse check the mime type list if no extension was proposed.
526523
// This search is order sensitive!
527524
foreach (static::$mimes as $ext => $types) {
528-
if ((is_string($types) && $types === $type) || (is_array($types) && in_array($type, $types, true))) {
525+
if (in_array($type, (array) $types, true)) {
529526
return $ext;
530527
}
531528
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"mikey179/vfsstream": "^1.6",
2222
"nexusphp/cs-config": "^3.3",
2323
"phpunit/phpunit": "^9.1",
24-
"predis/predis": "^1.1"
24+
"predis/predis": "^1.1 || ^2.0"
2525
},
2626
"suggest": {
2727
"ext-fileinfo": "Improves mime type detection for files"

system/Cache/Handlers/MemcachedHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ public function initialize()
115115
} else {
116116
throw new CriticalError('Cache: Not support Memcache(d) extension.');
117117
}
118-
} catch (CriticalError $e) {
119-
throw $e;
120118
} catch (Exception $e) {
121119
throw new CriticalError('Cache: Memcache(d) connection refused (' . $e->getMessage() . ').');
122120
}

system/CodeIgniter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CodeIgniter
4747
/**
4848
* The current version of CodeIgniter Framework
4949
*/
50-
public const CI_VERSION = '4.2.0';
50+
public const CI_VERSION = '4.2.1';
5151

5252
private const MIN_PHP_VERSION = '7.4';
5353

@@ -256,9 +256,7 @@ protected function initializeKint()
256256
require_once SYSTEMPATH . 'ThirdParty/Kint/init.php';
257257
}
258258

259-
/**
260-
* Config\Kint
261-
*/
259+
/** @var \Config\Kint $config */
262260
$config = config(KintConfig::class);
263261

264262
Kint::$depth_limit = $config->maxDepth;

system/Commands/Utilities/Routes/AutoRouterImproved/AutoRouteCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function get(): array
6565

6666
foreach ($finder->find() as $class) {
6767
// Exclude controllers in Defined Routes.
68-
if (in_array($class, $this->protectedControllers, true)) {
68+
if (in_array('\\' . $class, $this->protectedControllers, true)) {
6969
continue;
7070
}
7171

system/Cookie/Cookie.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class Cookie implements ArrayAccess, CloneableCookieInterface
119119
* Set the default attributes to a Cookie instance by injecting
120120
* the values from the `CookieConfig` config or an array.
121121
*
122+
* This method is called from Response::__construct().
123+
*
122124
* @param array<string, mixed>|CookieConfig $config
123125
*
124126
* @return array<string, mixed> The old defaults array. Useful for resetting.
@@ -209,7 +211,7 @@ final public function __construct(string $name, string $value = '', array $optio
209211
}
210212

211213
// to preserve backward compatibility with array-based cookies in previous CI versions
212-
$prefix = $options['prefix'] ?: self::$defaults['prefix'];
214+
$prefix = ($options['prefix'] === '') ? self::$defaults['prefix'] : $options['prefix'];
213215
$path = $options['path'] ?: self::$defaults['path'];
214216
$domain = $options['domain'] ?: self::$defaults['domain'];
215217

system/Database/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ protected function validateInsert(): bool
19231923
{
19241924
if (empty($this->QBSet)) {
19251925
if (CI_DEBUG) {
1926-
throw new DatabaseException('You must use the "set" method to update an entry.');
1926+
throw new DatabaseException('You must use the "set" method to insert an entry.');
19271927
}
19281928

19291929
return false; // @codeCoverageIgnore

system/Database/BaseConnection.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Closure;
1515
use CodeIgniter\Database\Exceptions\DatabaseException;
1616
use CodeIgniter\Events\Events;
17+
use Exception;
1718
use stdClass;
1819
use Throwable;
1920

@@ -603,7 +604,14 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
603604
$this->lastQuery = $query;
604605

605606
// Run the query for real
606-
if (! $this->pretend && false === ($this->resultID = $this->simpleQuery($query->getQuery()))) {
607+
try {
608+
$exception = null;
609+
$this->resultID = $this->simpleQuery($query->getQuery());
610+
} catch (Exception $exception) {
611+
$this->resultID = false;
612+
}
613+
614+
if (! $this->pretend && $this->resultID === false) {
607615
$query->setDuration($startTime, $startTime);
608616

609617
// This will trigger a rollback if transactions are being used
@@ -626,6 +634,15 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
626634
}
627635
}
628636

637+
if (! $this->pretend) {
638+
// Let others do something with this query.
639+
Events::trigger('DBQuery', $query);
640+
}
641+
642+
if ($exception !== null) {
643+
throw $exception;
644+
}
645+
629646
return false;
630647
}
631648

system/Database/MigrationRunner.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ public function findMigrations(): array
402402
$migrations = [];
403403

404404
foreach ($namespaces as $namespace) {
405+
if (ENVIRONMENT !== 'testing' && $namespace === 'Tests\Support') {
406+
continue;
407+
}
408+
405409
foreach ($this->findNamespaceMigrations($namespace) as $migration) {
406410
$migrations[$migration->uid] = $migration;
407411
}

system/Debug/Toolbar/Views/toolbar.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@
303303
#debug-bar .ci-label img {
304304
margin: unset;
305305
}
306-
307306
.hide-sm {
308307
display: none !important;
309308
}
@@ -432,7 +431,6 @@
432431
#debug-icon a:visited {
433432
color: #DD8615;
434433
}
435-
436434
#debug-bar {
437435
background-color: #252525;
438436
color: #DFDFDF;
@@ -526,11 +524,9 @@
526524
#debug-bar .timeline .timer {
527525
background-color: #DD8615;
528526
}
529-
530527
.debug-view.show-view {
531528
border-color: #DD8615;
532529
}
533-
534530
.debug-view-path {
535531
background-color: #FDC894;
536532
color: #434343;

system/Email/Email.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,10 +1046,8 @@ public function wordWrap($str, $charlim = null)
10461046
$output .= $line . $this->newline;
10471047
}
10481048

1049-
if ($unwrap) {
1050-
foreach ($unwrap as $key => $val) {
1051-
$output = str_replace('{{unwrapped' . $key . '}}', $val, $output);
1052-
}
1049+
foreach ($unwrap as $key => $val) {
1050+
$output = str_replace('{{unwrapped' . $key . '}}', $val, $output);
10531051
}
10541052

10551053
return $output;

system/Files/File.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ public function getSizeByUnit(string $unit = 'b')
8989
*/
9090
public function guessExtension(): ?string
9191
{
92-
return Mimes::guessExtensionFromType($this->getMimeType());
92+
// naively get the path extension using pathinfo
93+
$pathinfo = pathinfo($this->getRealPath() ?: $this->__toString()) + ['extension' => ''];
94+
95+
$proposedExtension = $pathinfo['extension'];
96+
97+
return Mimes::guessExtensionFromType($this->getMimeType(), $proposedExtension);
9398
}
9499

95100
/**

system/HTTP/CLIRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,6 @@ protected function parseCommand()
212212
*/
213213
public function isCLI(): bool
214214
{
215-
return true;
215+
return is_cli();
216216
}
217217
}

system/HTTP/IncomingRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public function negotiate(string $type, array $supported, bool $strictMatch = fa
347347
*/
348348
public function isCLI(): bool
349349
{
350-
return false;
350+
return is_cli();
351351
}
352352

353353
/**

system/HTTP/ResponseTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ public function redirect(string $uri, string $method = 'auto', ?int $code = null
543543
* @param string $expire Cookie expiration time in seconds
544544
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
545545
* @param string $path Cookie path (default: '/')
546-
* @param string $prefix Cookie name prefix
546+
* @param string $prefix Cookie name prefix ('': the default prefix)
547547
* @param bool $secure Whether to only transfer cookies via SSL
548548
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
549549
* @param string|null $samesite
@@ -618,6 +618,9 @@ public function hasCookie(string $name, ?string $value = null, string $prefix =
618618
/**
619619
* Returns the cookie
620620
*
621+
* @param string $prefix Cookie prefix.
622+
* '': the default prefix
623+
*
621624
* @return Cookie|Cookie[]|null
622625
*/
623626
public function getCookie(?string $name = null, string $prefix = '')

system/Helpers/cookie_helper.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
use Config\App;
13+
use Config\Cookie;
1314
use Config\Services;
1415

1516
//=============================================================================
@@ -28,7 +29,7 @@
2829
* @param string $expire The number of seconds until expiration
2930
* @param string $domain For site-wide cookie. Usually: .yourdomain.com
3031
* @param string $path The cookie path
31-
* @param string $prefix The cookie prefix
32+
* @param string $prefix The cookie prefix ('': the default prefix)
3233
* @param bool $secure True makes the cookie secure
3334
* @param bool $httpOnly True makes the cookie accessible via http(s) only (no javascript)
3435
* @param string|null $sameSite The cookie SameSite value
@@ -55,15 +56,25 @@ function set_cookie(
5556
/**
5657
* Fetch an item from the $_COOKIE array
5758
*
58-
* @param string $index
59+
* @param string $index
60+
* @param string|null $prefix Cookie name prefix.
61+
* '': the prefix in Config\Cookie
62+
* null: no prefix
5963
*
60-
* @return mixed
64+
* @return array|string|null
6165
*
6266
* @see \CodeIgniter\HTTP\IncomingRequest::getCookie()
6367
*/
64-
function get_cookie($index, bool $xssClean = false)
68+
function get_cookie($index, bool $xssClean = false, ?string $prefix = '')
6569
{
66-
$prefix = isset($_COOKIE[$index]) ? '' : config(App::class)->cookiePrefix;
70+
if ($prefix === '') {
71+
/** @var Cookie|null $cookie */
72+
$cookie = config('Cookie');
73+
74+
// @TODO Remove Config\App fallback when deprecated `App` members are removed.
75+
$prefix = $cookie instanceof Cookie ? $cookie->prefix : config(App::class)->cookiePrefix;
76+
}
77+
6778
$request = Services::request();
6879
$filter = $xssClean ? FILTER_SANITIZE_FULL_SPECIAL_CHARS : FILTER_DEFAULT;
6980

system/I18n/Time.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __construct(?string $time = null, $timezone = null, ?string $loc
8282
// If a test instance has been provided, use it instead.
8383
if ($time === '' && static::$testNow instanceof self) {
8484
$timezone = $timezone ?: static::$testNow->getTimezone();
85-
$time = (string) static::$testNow->toDateTimeString();
85+
$time = static::$testNow->format('Y-m-d H:i:s');
8686
}
8787

8888
$timezone = $timezone ?: date_default_timezone_get();
@@ -1005,7 +1005,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
10051005
*/
10061006
public function humanize()
10071007
{
1008-
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTimeString());
1008+
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
10091009
$time = $this->getCalendar()->getTime();
10101010

10111011
$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
@@ -1106,7 +1106,7 @@ public function getUTCObject($time, ?string $timezone = null)
11061106
*/
11071107
public function getCalendar()
11081108
{
1109-
return IntlCalendar::fromDateTime($this->toDateTimeString());
1109+
return IntlCalendar::fromDateTime($this);
11101110
}
11111111

11121112
/**

system/Router/AutoRouterImproved.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,7 @@ private function scanControllers(array $segments): array
251251
$c = count($segments);
252252

253253
while ($c-- > 0) {
254-
$segmentConvert = ucfirst(
255-
$this->translateURIDashes === true
256-
? str_replace('-', '_', $segments[0])
257-
: $segments[0]
258-
);
254+
$segmentConvert = $this->translateURIDashes(ucfirst($segments[0]));
259255

260256
// as soon as we encounter any segment that is not PSR-4 compliant, stop searching
261257
if (! $this->isValidSegment($segmentConvert)) {

system/Router/RouteCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ public function reverseRoute(string $search, ...$params)
10081008
$namespace = trim($this->defaultNamespace, '\\') . '\\';
10091009
if (
10101010
substr($search, 0, 1) !== '\\'
1011-
|| substr($search, 0, strlen($namespace)) !== $namespace
1011+
&& substr($search, 0, strlen($namespace)) !== $namespace
10121012
) {
10131013
$search = $namespace . $search;
10141014
}

0 commit comments

Comments
 (0)