Skip to content

Commit 336e078

Browse files
committed
Release v4.5.4
1 parent be27314 commit 336e078

Some content is hidden

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

44 files changed

+134
-96
lines changed

app/Config/Events.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Events::on('create', [$myInstance, 'myMethod']);
2424
*/
2525

26-
Events::on('pre_system', static function () {
26+
Events::on('pre_system', static function (): void {
2727
if (ENVIRONMENT !== 'testing') {
2828
if (ini_get('zlib.output_compression')) {
2929
throw FrameworkException::forEnabledZlibOutputCompression();
@@ -47,7 +47,7 @@
4747
Services::toolbar()->respond();
4848
// Hot Reload route - for framework use on the hot reloader.
4949
if (ENVIRONMENT === 'development') {
50-
Services::routes()->get('__hot-reload', static function () {
50+
Services::routes()->get('__hot-reload', static function (): void {
5151
(new HotReloader())->run();
5252
});
5353
}

system/Autoloader/Autoloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ private function autoloadKint(): void
507507
{
508508
// If we have KINT_DIR it means it's already loaded via composer
509509
if (! defined('KINT_DIR')) {
510-
spl_autoload_register(function ($class) {
510+
spl_autoload_register(function ($class): void {
511511
$class = explode('\\', $class);
512512

513513
if (array_shift($class) !== 'Kint') {

system/CLI/BaseCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function showHelp()
163163
if ($this->arguments !== []) {
164164
CLI::newLine();
165165
CLI::write(lang('CLI.helpArguments'), 'yellow');
166-
$length = max(array_map('strlen', array_keys($this->arguments)));
166+
$length = max(array_map(strlen(...), array_keys($this->arguments)));
167167

168168
foreach ($this->arguments as $argument => $description) {
169169
CLI::write(CLI::color($this->setPad($argument, $length, 2, 2), 'green') . $description);
@@ -173,7 +173,7 @@ public function showHelp()
173173
if ($this->options !== []) {
174174
CLI::newLine();
175175
CLI::write(lang('CLI.helpOptions'), 'yellow');
176-
$length = max(array_map('strlen', array_keys($this->options)));
176+
$length = max(array_map(strlen(...), array_keys($this->options)));
177177

178178
foreach ($this->options as $option => $description) {
179179
CLI::write(CLI::color($this->setPad($option, $length, 2, 2), 'green') . $description);

system/CLI/CLI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ private static function isZeroOptions(array $options): void
393393
private static function printKeysAndValues(array $options): void
394394
{
395395
// +2 for the square brackets around the key
396-
$keyMaxLength = max(array_map('mb_strwidth', array_keys($options))) + 2;
396+
$keyMaxLength = max(array_map(mb_strwidth(...), array_keys($options))) + 2;
397397

398398
foreach ($options as $key => $description) {
399399
$name = str_pad(' [' . $key . '] ', $keyMaxLength + 4, ' ');
@@ -857,7 +857,7 @@ public static function wrap(?string $string = null, int $max = 0, int $padLeft =
857857

858858
$first = true;
859859

860-
array_walk($lines, static function (&$line) use ($padLeft, &$first) {
860+
array_walk($lines, static function (&$line) use ($padLeft, &$first): void {
861861
if (! $first) {
862862
$line = str_repeat(' ', $padLeft) . $line;
863863
} else {

system/CLI/GeneratorTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ private function normalizeInputClassName(): string
325325
implode(
326326
'\\',
327327
array_map(
328-
'pascalize',
328+
pascalize(...),
329329
explode('\\', str_replace('/', '\\', trim($class)))
330330
)
331331
),

system/CodeIgniter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class CodeIgniter
5656
/**
5757
* The current version of CodeIgniter Framework
5858
*/
59-
public const CI_VERSION = '4.5.3';
59+
public const CI_VERSION = '4.5.4';
6060

6161
/**
6262
* App startup time.
@@ -253,7 +253,7 @@ private function autoloadKint(): void
253253
{
254254
// If we have KINT_DIR it means it's already loaded via composer
255255
if (! defined('KINT_DIR')) {
256-
spl_autoload_register(function ($class) {
256+
spl_autoload_register(function ($class): void {
257257
$class = explode('\\', $class);
258258

259259
if (array_shift($class) !== 'Kint') {

system/Commands/ListCommands.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function listFull(array $commands)
101101
$groups[$command['group']][$title] = $command;
102102
}
103103

104-
$length = max(array_map('strlen', array_keys($commands)));
104+
$length = max(array_map(strlen(...), array_keys($commands)));
105105

106106
ksort($groups);
107107

system/Commands/Utilities/Routes.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public function run(array $params)
119119
$route['route'],
120120
$routeName,
121121
$route['handler'],
122-
implode(' ', array_map('class_basename', $filters['before'])),
123-
implode(' ', array_map('class_basename', $filters['after'])),
122+
implode(' ', array_map(class_basename(...), $filters['before'])),
123+
implode(' ', array_map(class_basename(...), $filters['after'])),
124124
];
125125
}
126126

@@ -166,8 +166,8 @@ public function run(array $params)
166166
// There is no `AUTO` method, but it is intentional not to get route filters.
167167
$filters = $filterCollector->get('AUTO', $uriGenerator->get($routes[1]));
168168

169-
$routes[] = implode(' ', array_map('class_basename', $filters['before']));
170-
$routes[] = implode(' ', array_map('class_basename', $filters['after']));
169+
$routes[] = implode(' ', array_map(class_basename(...), $filters['before']));
170+
$routes[] = implode(' ', array_map(class_basename(...), $filters['after']));
171171
}
172172
}
173173

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ private function addFilters($routes)
125125
$filters['before'] = array_intersect($filtersLongest['before'], $filtersShortest['before']);
126126
$filters['after'] = array_intersect($filtersLongest['after'], $filtersShortest['after']);
127127

128-
$route['before'] = implode(' ', array_map('class_basename', $filters['before']));
129-
$route['after'] = implode(' ', array_map('class_basename', $filters['after']));
128+
$route['before'] = implode(' ', array_map(class_basename(...), $filters['before']));
129+
$route['after'] = implode(' ', array_map(class_basename(...), $filters['after']));
130130
}
131131

132132
return $routes;

system/Common.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,10 +766,8 @@ function lang(string $line, array $args = [], ?string $locale = null)
766766
* - notice
767767
* - info
768768
* - debug
769-
*
770-
* @return void
771769
*/
772-
function log_message(string $level, string $message, array $context = [])
770+
function log_message(string $level, string $message, array $context = []): void
773771
{
774772
// When running tests, we want to always ensure that the
775773
// TestLogger is running, which provides utilities for

system/Config/BaseService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
use Config\Optimize;
7676
use Config\Pager as ConfigPager;
7777
use Config\Services as AppServices;
78+
use Config\Session as ConfigSession;
7879
use Config\Toolbar as ConfigToolbar;
7980
use Config\Validation as ConfigValidation;
8081
use Config\View as ConfigView;
@@ -130,7 +131,7 @@
130131
* @method static Router router(RouteCollectionInterface $routes = null, Request $request = null, $getShared = true)
131132
* @method static RouteCollection routes($getShared = true)
132133
* @method static Security security(App $config = null, $getShared = true)
133-
* @method static Session session(App $config = null, $getShared = true)
134+
* @method static Session session(ConfigSession $config = null, $getShared = true)
134135
* @method static SiteURIFactory siteurifactory(App $config = null, Superglobals $superglobals = null, $getShared = true)
135136
* @method static Superglobals superglobals(array $server = null, array $get = null, bool $getShared = true)
136137
* @method static Throttler throttler($getShared = true)

system/Config/Services.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use CodeIgniter\Router\RouteCollectionInterface;
5252
use CodeIgniter\Router\Router;
5353
use CodeIgniter\Security\Security;
54+
use CodeIgniter\Session\Handlers\BaseHandler as SessionBaseHandler;
5455
use CodeIgniter\Session\Handlers\Database\MySQLiHandler;
5556
use CodeIgniter\Session\Handlers\Database\PostgreHandler;
5657
use CodeIgniter\Session\Handlers\DatabaseHandler;
@@ -88,6 +89,7 @@
8889
use Config\Toolbar as ToolbarConfig;
8990
use Config\Validation as ValidationConfig;
9091
use Config\View as ViewConfig;
92+
use InvalidArgumentException;
9193
use Locale;
9294

9395
/**
@@ -674,17 +676,24 @@ public static function session(?SessionConfig $config = null, bool $getShared =
674676

675677
if ($driverName === DatabaseHandler::class) {
676678
$DBGroup = $config->DBGroup ?? config(Database::class)->defaultGroup;
677-
$db = Database::connect($DBGroup);
678679

679-
$driver = $db->getPlatform();
680+
$driverPlatform = Database::connect($DBGroup)->getPlatform();
680681

681-
if ($driver === 'MySQLi') {
682+
if ($driverPlatform === 'MySQLi') {
682683
$driverName = MySQLiHandler::class;
683-
} elseif ($driver === 'Postgre') {
684+
} elseif ($driverPlatform === 'Postgre') {
684685
$driverName = PostgreHandler::class;
685686
}
686687
}
687688

689+
if (! class_exists($driverName) || ! is_a($driverName, SessionBaseHandler::class, true)) {
690+
throw new InvalidArgumentException(sprintf(
691+
'Invalid session handler "%s" provided.',
692+
$driverName
693+
));
694+
}
695+
696+
/** @var SessionBaseHandler $driver */
688697
$driver = new $driverName($config, AppServices::get('request')->getIPAddress());
689698
$driver->setLogger($logger);
690699

system/Cookie/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function getPrefixedName(): string
283283
$name .= $this->getName();
284284
} else {
285285
$search = str_split(self::$reservedCharsList);
286-
$replace = array_map('rawurlencode', $search);
286+
$replace = array_map(rawurlencode(...), $search);
287287

288288
$name .= str_replace($search, $replace, $this->getName());
289289
}

system/DataCaster/DataCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function castAs(mixed $value, string $field, string $method = 'get'): mix
156156
// type[param, param2,param3]
157157
if (preg_match('/\A(.+)\[(.+)\]\z/', $type, $matches)) {
158158
$type = $matches[1];
159-
$params = array_map('trim', explode(',', $matches[2]));
159+
$params = array_map(trim(...), explode(',', $matches[2]));
160160
}
161161

162162
if ($isNullable && ! $this->strict) {

system/DataConverter/DataConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function reconstruct(string $classname, array $row): object
140140
return $classObj;
141141
}
142142

143-
$classSet = Closure::bind(function ($key, $value) {
143+
$classSet = Closure::bind(function ($key, $value): void {
144144
$this->{$key} = $value;
145145
}, $classObj, $classname);
146146

system/Database/BaseBuilder.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ class BaseBuilder
124124
protected array $QBUnion = [];
125125

126126
/**
127-
* QB NO ESCAPE data
127+
* Whether to protect identifiers in SELECT
128128
*
129-
* @var array
129+
* @var list<bool|null> true=protect, false=not protect
130130
*/
131131
public $QBNoEscape = [];
132132

@@ -390,7 +390,8 @@ public function ignore(bool $ignore = true)
390390
/**
391391
* Generates the SELECT portion of the query
392392
*
393-
* @param array|RawSql|string $select
393+
* @param list<RawSql|string>|RawSql|string $select
394+
* @param bool|null $escape Whether to protect identifiers
394395
*
395396
* @return $this
396397
*/
@@ -402,16 +403,21 @@ public function select($select = '*', ?bool $escape = null)
402403
}
403404

404405
if ($select instanceof RawSql) {
405-
$this->QBSelect[] = $select;
406-
407-
return $this;
406+
$select = [$select];
408407
}
409408

410409
if (is_string($select)) {
411-
$select = $escape === false ? [$select] : explode(',', $select);
410+
$select = ($escape === false) ? [$select] : explode(',', $select);
412411
}
413412

414413
foreach ($select as $val) {
414+
if ($val instanceof RawSql) {
415+
$this->QBSelect[] = $val;
416+
$this->QBNoEscape[] = false;
417+
418+
continue;
419+
}
420+
415421
$val = trim($val);
416422

417423
if ($val !== '') {
@@ -424,8 +430,10 @@ public function select($select = '*', ?bool $escape = null)
424430
* This prevents NULL being escaped
425431
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1169
426432
*/
427-
if (mb_stripos(trim($val), 'NULL') === 0) {
428-
$escape = false;
433+
if (mb_stripos($val, 'NULL') === 0) {
434+
$this->QBNoEscape[] = false;
435+
436+
continue;
429437
}
430438

431439
$this->QBNoEscape[] = $escape;
@@ -3054,15 +3062,17 @@ protected function compileSelect($selectOverride = false): string
30543062

30553063
if (empty($this->QBSelect)) {
30563064
$sql .= '*';
3057-
} elseif ($this->QBSelect[0] instanceof RawSql) {
3058-
$sql .= (string) $this->QBSelect[0];
30593065
} else {
30603066
// Cycle through the "select" portion of the query and prep each column name.
30613067
// The reason we protect identifiers here rather than in the select() function
30623068
// is because until the user calls the from() function we don't know if there are aliases
30633069
foreach ($this->QBSelect as $key => $val) {
3064-
$noEscape = $this->QBNoEscape[$key] ?? null;
3065-
$this->QBSelect[$key] = $this->db->protectIdentifiers($val, false, $noEscape);
3070+
if ($val instanceof RawSql) {
3071+
$this->QBSelect[$key] = (string) $val;
3072+
} else {
3073+
$protect = $this->QBNoEscape[$key] ?? null;
3074+
$this->QBSelect[$key] = $this->db->protectIdentifiers($val, false, $protect);
3075+
}
30663076
}
30673077

30683078
$sql .= implode(', ', $this->QBSelect);

system/Database/BaseConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ public function tableExists(string $tableName, bool $cached = true): bool
15191519
if (! empty($this->dataCache['table_names'])) {
15201520
$key = array_search(
15211521
strtolower($tableName),
1522-
array_map('strtolower', $this->dataCache['table_names']),
1522+
array_map(strtolower(...), $this->dataCache['table_names']),
15231523
true
15241524
);
15251525

system/Database/Forge.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function dropDatabase(string $dbName): bool
306306
if (! empty($this->db->dataCache['db_names'])) {
307307
$key = array_search(
308308
strtolower($dbName),
309-
array_map('strtolower', $this->db->dataCache['db_names']),
309+
array_map(strtolower(...), $this->db->dataCache['db_names']),
310310
true
311311
);
312312
if ($key !== false) {
@@ -667,7 +667,7 @@ public function dropTable(string $tableName, bool $ifExists = false, bool $casca
667667
if ($query && ! empty($this->db->dataCache['table_names'])) {
668668
$key = array_search(
669669
strtolower($this->db->DBPrefix . $tableName),
670-
array_map('strtolower', $this->db->dataCache['table_names']),
670+
array_map(strtolower(...), $this->db->dataCache['table_names']),
671671
true
672672
);
673673

@@ -729,7 +729,7 @@ public function renameTable(string $tableName, string $newTableName)
729729
if ($result && ! empty($this->db->dataCache['table_names'])) {
730730
$key = array_search(
731731
strtolower($this->db->DBPrefix . $tableName),
732-
array_map('strtolower', $this->db->dataCache['table_names']),
732+
array_map(strtolower(...), $this->db->dataCache['table_names']),
733733
true
734734
);
735735

system/Database/MigrationRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ public function getBatches(): array
686686
->get()
687687
->getResultArray();
688688

689-
return array_map('intval', array_column($batches, 'batch'));
689+
return array_map(intval(...), array_column($batches, 'batch'));
690690
}
691691

692692
/**

system/Database/OCI8/Connection.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,24 @@ class Connection extends BaseConnection
5353
];
5454

5555
protected $validDSNs = [
56-
'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS
57-
// Easy Connect string (Oracle 10g+)
58-
'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i',
59-
'in' => '/^[a-z0-9$_]+$/i', // Instance name (defined in tnsnames.ora)
56+
// TNS
57+
'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/',
58+
// Easy Connect string (Oracle 10g+).
59+
// https://docs.oracle.com/en/database/oracle/oracle-database/23/netag/configuring-naming-methods.html#GUID-36F3A17D-843C-490A-8A23-FB0FE005F8E8
60+
// [//]host[:port][/[service_name][:server_type][/instance_name]]
61+
'ec' => '/^
62+
(\/\/)?
63+
(\[)?[a-z0-9.:_-]+(\])? # Host or IP address
64+
(:[1-9][0-9]{0,4})? # Port
65+
(
66+
(\/)
67+
([a-z0-9.$_]+)? # Service name
68+
(:[a-z]+)? # Server type
69+
(\/[a-z0-9$_]+)? # Instance name
70+
)?
71+
$/ix',
72+
// Instance name (defined in tnsnames.ora)
73+
'in' => '/^[a-z0-9$_]+$/i',
6074
];
6175

6276
/**

system/Database/OCI8/Forge.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ protected function _processColumn(array $processedField): string
202202
$constraint = ' CHECK(' . $this->db->escapeIdentifiers($processedField['name'])
203203
. ' IN ' . $processedField['length'] . ')';
204204

205-
$processedField['length'] = '(' . max(array_map('mb_strlen', explode("','", mb_substr($processedField['length'], 2, -2)))) . ')' . $constraint;
205+
$processedField['length'] = '(' . max(array_map(mb_strlen(...), explode("','", mb_substr($processedField['length'], 2, -2)))) . ')' . $constraint;
206206
} elseif (isset($this->primaryKeys['fields']) && count($this->primaryKeys['fields']) === 1 && $processedField['name'] === $this->primaryKeys['fields'][0]) {
207207
$processedField['unique'] = '';
208208
}

0 commit comments

Comments
 (0)