Skip to content

Commit

Permalink
Release v4.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jul 27, 2024
1 parent be27314 commit 336e078
Show file tree
Hide file tree
Showing 44 changed files with 134 additions and 96 deletions.
4 changes: 2 additions & 2 deletions app/Config/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Events::on('create', [$myInstance, 'myMethod']);
*/

Events::on('pre_system', static function () {
Events::on('pre_system', static function (): void {
if (ENVIRONMENT !== 'testing') {
if (ini_get('zlib.output_compression')) {
throw FrameworkException::forEnabledZlibOutputCompression();
Expand All @@ -47,7 +47,7 @@
Services::toolbar()->respond();
// Hot Reload route - for framework use on the hot reloader.
if (ENVIRONMENT === 'development') {
Services::routes()->get('__hot-reload', static function () {
Services::routes()->get('__hot-reload', static function (): void {
(new HotReloader())->run();
});
}
Expand Down
2 changes: 1 addition & 1 deletion system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ private function autoloadKint(): void
{
// If we have KINT_DIR it means it's already loaded via composer
if (! defined('KINT_DIR')) {
spl_autoload_register(function ($class) {
spl_autoload_register(function ($class): void {
$class = explode('\\', $class);

if (array_shift($class) !== 'Kint') {
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function showHelp()
if ($this->arguments !== []) {
CLI::newLine();
CLI::write(lang('CLI.helpArguments'), 'yellow');
$length = max(array_map('strlen', array_keys($this->arguments)));
$length = max(array_map(strlen(...), array_keys($this->arguments)));

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

foreach ($this->options as $option => $description) {
CLI::write(CLI::color($this->setPad($option, $length, 2, 2), 'green') . $description);
Expand Down
4 changes: 2 additions & 2 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private static function isZeroOptions(array $options): void
private static function printKeysAndValues(array $options): void
{
// +2 for the square brackets around the key
$keyMaxLength = max(array_map('mb_strwidth', array_keys($options))) + 2;
$keyMaxLength = max(array_map(mb_strwidth(...), array_keys($options))) + 2;

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

$first = true;

array_walk($lines, static function (&$line) use ($padLeft, &$first) {
array_walk($lines, static function (&$line) use ($padLeft, &$first): void {
if (! $first) {
$line = str_repeat(' ', $padLeft) . $line;
} else {
Expand Down
2 changes: 1 addition & 1 deletion system/CLI/GeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private function normalizeInputClassName(): string
implode(
'\\',
array_map(
'pascalize',
pascalize(...),
explode('\\', str_replace('/', '\\', trim($class)))
)
),
Expand Down
4 changes: 2 additions & 2 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CodeIgniter
/**
* The current version of CodeIgniter Framework
*/
public const CI_VERSION = '4.5.3';
public const CI_VERSION = '4.5.4';

/**
* App startup time.
Expand Down Expand Up @@ -253,7 +253,7 @@ private function autoloadKint(): void
{
// If we have KINT_DIR it means it's already loaded via composer
if (! defined('KINT_DIR')) {
spl_autoload_register(function ($class) {
spl_autoload_register(function ($class): void {
$class = explode('\\', $class);

if (array_shift($class) !== 'Kint') {
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function listFull(array $commands)
$groups[$command['group']][$title] = $command;
}

$length = max(array_map('strlen', array_keys($commands)));
$length = max(array_map(strlen(...), array_keys($commands)));

ksort($groups);

Expand Down
8 changes: 4 additions & 4 deletions system/Commands/Utilities/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public function run(array $params)
$route['route'],
$routeName,
$route['handler'],
implode(' ', array_map('class_basename', $filters['before'])),
implode(' ', array_map('class_basename', $filters['after'])),
implode(' ', array_map(class_basename(...), $filters['before'])),
implode(' ', array_map(class_basename(...), $filters['after'])),
];
}

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

$routes[] = implode(' ', array_map('class_basename', $filters['before']));
$routes[] = implode(' ', array_map('class_basename', $filters['after']));
$routes[] = implode(' ', array_map(class_basename(...), $filters['before']));
$routes[] = implode(' ', array_map(class_basename(...), $filters['after']));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ private function addFilters($routes)
$filters['before'] = array_intersect($filtersLongest['before'], $filtersShortest['before']);
$filters['after'] = array_intersect($filtersLongest['after'], $filtersShortest['after']);

$route['before'] = implode(' ', array_map('class_basename', $filters['before']));
$route['after'] = implode(' ', array_map('class_basename', $filters['after']));
$route['before'] = implode(' ', array_map(class_basename(...), $filters['before']));
$route['after'] = implode(' ', array_map(class_basename(...), $filters['after']));
}

return $routes;
Expand Down
4 changes: 1 addition & 3 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,8 @@ function lang(string $line, array $args = [], ?string $locale = null)
* - notice
* - info
* - debug
*
* @return void
*/
function log_message(string $level, string $message, array $context = [])
function log_message(string $level, string $message, array $context = []): void
{
// When running tests, we want to always ensure that the
// TestLogger is running, which provides utilities for
Expand Down
3 changes: 2 additions & 1 deletion system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
use Config\Optimize;
use Config\Pager as ConfigPager;
use Config\Services as AppServices;
use Config\Session as ConfigSession;
use Config\Toolbar as ConfigToolbar;
use Config\Validation as ConfigValidation;
use Config\View as ConfigView;
Expand Down Expand Up @@ -130,7 +131,7 @@
* @method static Router router(RouteCollectionInterface $routes = null, Request $request = null, $getShared = true)
* @method static RouteCollection routes($getShared = true)
* @method static Security security(App $config = null, $getShared = true)
* @method static Session session(App $config = null, $getShared = true)
* @method static Session session(ConfigSession $config = null, $getShared = true)
* @method static SiteURIFactory siteurifactory(App $config = null, Superglobals $superglobals = null, $getShared = true)
* @method static Superglobals superglobals(array $server = null, array $get = null, bool $getShared = true)
* @method static Throttler throttler($getShared = true)
Expand Down
17 changes: 13 additions & 4 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use CodeIgniter\Router\RouteCollectionInterface;
use CodeIgniter\Router\Router;
use CodeIgniter\Security\Security;
use CodeIgniter\Session\Handlers\BaseHandler as SessionBaseHandler;
use CodeIgniter\Session\Handlers\Database\MySQLiHandler;
use CodeIgniter\Session\Handlers\Database\PostgreHandler;
use CodeIgniter\Session\Handlers\DatabaseHandler;
Expand Down Expand Up @@ -88,6 +89,7 @@
use Config\Toolbar as ToolbarConfig;
use Config\Validation as ValidationConfig;
use Config\View as ViewConfig;
use InvalidArgumentException;
use Locale;

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

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

$driver = $db->getPlatform();
$driverPlatform = Database::connect($DBGroup)->getPlatform();

if ($driver === 'MySQLi') {
if ($driverPlatform === 'MySQLi') {
$driverName = MySQLiHandler::class;
} elseif ($driver === 'Postgre') {
} elseif ($driverPlatform === 'Postgre') {
$driverName = PostgreHandler::class;
}
}

if (! class_exists($driverName) || ! is_a($driverName, SessionBaseHandler::class, true)) {
throw new InvalidArgumentException(sprintf(
'Invalid session handler "%s" provided.',
$driverName
));
}

/** @var SessionBaseHandler $driver */
$driver = new $driverName($config, AppServices::get('request')->getIPAddress());
$driver->setLogger($logger);

Expand Down
2 changes: 1 addition & 1 deletion system/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function getPrefixedName(): string
$name .= $this->getName();
} else {
$search = str_split(self::$reservedCharsList);
$replace = array_map('rawurlencode', $search);
$replace = array_map(rawurlencode(...), $search);

$name .= str_replace($search, $replace, $this->getName());
}
Expand Down
2 changes: 1 addition & 1 deletion system/DataCaster/DataCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function castAs(mixed $value, string $field, string $method = 'get'): mix
// type[param, param2,param3]
if (preg_match('/\A(.+)\[(.+)\]\z/', $type, $matches)) {
$type = $matches[1];
$params = array_map('trim', explode(',', $matches[2]));
$params = array_map(trim(...), explode(',', $matches[2]));
}

if ($isNullable && ! $this->strict) {
Expand Down
2 changes: 1 addition & 1 deletion system/DataConverter/DataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function reconstruct(string $classname, array $row): object
return $classObj;
}

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

Expand Down
36 changes: 23 additions & 13 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ class BaseBuilder
protected array $QBUnion = [];

/**
* QB NO ESCAPE data
* Whether to protect identifiers in SELECT
*
* @var array
* @var list<bool|null> true=protect, false=not protect
*/
public $QBNoEscape = [];

Expand Down Expand Up @@ -390,7 +390,8 @@ public function ignore(bool $ignore = true)
/**
* Generates the SELECT portion of the query
*
* @param array|RawSql|string $select
* @param list<RawSql|string>|RawSql|string $select
* @param bool|null $escape Whether to protect identifiers
*
* @return $this
*/
Expand All @@ -402,16 +403,21 @@ public function select($select = '*', ?bool $escape = null)
}

if ($select instanceof RawSql) {
$this->QBSelect[] = $select;

return $this;
$select = [$select];
}

if (is_string($select)) {
$select = $escape === false ? [$select] : explode(',', $select);
$select = ($escape === false) ? [$select] : explode(',', $select);
}

foreach ($select as $val) {
if ($val instanceof RawSql) {
$this->QBSelect[] = $val;
$this->QBNoEscape[] = false;

continue;
}

$val = trim($val);

if ($val !== '') {
Expand All @@ -424,8 +430,10 @@ public function select($select = '*', ?bool $escape = null)
* This prevents NULL being escaped
* @see https://github.com/codeigniter4/CodeIgniter4/issues/1169
*/
if (mb_stripos(trim($val), 'NULL') === 0) {
$escape = false;
if (mb_stripos($val, 'NULL') === 0) {
$this->QBNoEscape[] = false;

continue;
}

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

if (empty($this->QBSelect)) {
$sql .= '*';
} elseif ($this->QBSelect[0] instanceof RawSql) {
$sql .= (string) $this->QBSelect[0];
} else {
// Cycle through the "select" portion of the query and prep each column name.
// The reason we protect identifiers here rather than in the select() function
// is because until the user calls the from() function we don't know if there are aliases
foreach ($this->QBSelect as $key => $val) {
$noEscape = $this->QBNoEscape[$key] ?? null;
$this->QBSelect[$key] = $this->db->protectIdentifiers($val, false, $noEscape);
if ($val instanceof RawSql) {
$this->QBSelect[$key] = (string) $val;
} else {
$protect = $this->QBNoEscape[$key] ?? null;
$this->QBSelect[$key] = $this->db->protectIdentifiers($val, false, $protect);
}
}

$sql .= implode(', ', $this->QBSelect);
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ public function tableExists(string $tableName, bool $cached = true): bool
if (! empty($this->dataCache['table_names'])) {
$key = array_search(
strtolower($tableName),
array_map('strtolower', $this->dataCache['table_names']),
array_map(strtolower(...), $this->dataCache['table_names']),
true
);

Expand Down
6 changes: 3 additions & 3 deletions system/Database/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function dropDatabase(string $dbName): bool
if (! empty($this->db->dataCache['db_names'])) {
$key = array_search(
strtolower($dbName),
array_map('strtolower', $this->db->dataCache['db_names']),
array_map(strtolower(...), $this->db->dataCache['db_names']),
true
);
if ($key !== false) {
Expand Down Expand Up @@ -667,7 +667,7 @@ public function dropTable(string $tableName, bool $ifExists = false, bool $casca
if ($query && ! empty($this->db->dataCache['table_names'])) {
$key = array_search(
strtolower($this->db->DBPrefix . $tableName),
array_map('strtolower', $this->db->dataCache['table_names']),
array_map(strtolower(...), $this->db->dataCache['table_names']),
true
);

Expand Down Expand Up @@ -729,7 +729,7 @@ public function renameTable(string $tableName, string $newTableName)
if ($result && ! empty($this->db->dataCache['table_names'])) {
$key = array_search(
strtolower($this->db->DBPrefix . $tableName),
array_map('strtolower', $this->db->dataCache['table_names']),
array_map(strtolower(...), $this->db->dataCache['table_names']),
true
);

Expand Down
2 changes: 1 addition & 1 deletion system/Database/MigrationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ public function getBatches(): array
->get()
->getResultArray();

return array_map('intval', array_column($batches, 'batch'));
return array_map(intval(...), array_column($batches, 'batch'));
}

/**
Expand Down
22 changes: 18 additions & 4 deletions system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,24 @@ class Connection extends BaseConnection
];

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

/**
Expand Down
2 changes: 1 addition & 1 deletion system/Database/OCI8/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected function _processColumn(array $processedField): string
$constraint = ' CHECK(' . $this->db->escapeIdentifiers($processedField['name'])
. ' IN ' . $processedField['length'] . ')';

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

0 comments on commit 336e078

Please sign in to comment.