Skip to content

Commit

Permalink
Release v4.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jun 25, 2024
1 parent 163f111 commit be27314
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 37 deletions.
2 changes: 1 addition & 1 deletion system/CLI/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function discoverCommands()
/** @var BaseCommand $class */
$class = new $className($this->logger, $this);

if (isset($class->group)) {
if (isset($class->group) && ! isset($this->commands[$class->name])) {
$this->commands[$class->name] = [
'class' => $className,
'file' => $file,
Expand Down
2 changes: 1 addition & 1 deletion system/CLI/GeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ protected function setEnabledSuffixing(bool $enabledSuffixing)
* Gets a single command-line option. Returns TRUE if the option exists,
* but doesn't have a value, and is simply acting as a flag.
*/
protected function getOption(string $name): string|bool|null
protected function getOption(string $name): bool|string|null
{
if (! array_key_exists($name, $this->params)) {
return CLI::getOption($name);
Expand Down
11 changes: 5 additions & 6 deletions system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,17 @@ public function delete(string $key)
*/
public function deleteMatching(string $pattern)
{
/** @var list<string> $matchedKeys */
$matchedKeys = [];
$pattern = static::validateKey($pattern, $this->prefix);
$iterator = null;

do {
// Scan for some keys
/** @var false|list<string>|Redis $keys */
$keys = $this->redis->scan($iterator, $pattern);

// Redis may return empty results, so protect against that
if ($keys !== false) {
foreach ($keys as $key) {
$matchedKeys[] = $key;
}
if (is_array($keys)) {
$matchedKeys = [...$matchedKeys, ...$keys];
}
} while ($iterator > 0);

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.2';
public const CI_VERSION = '4.5.3';

/**
* App startup time.
Expand Down Expand Up @@ -353,7 +353,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
} else {
try {
$this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse);
} catch (ResponsableInterface|DeprecatedRedirectException $e) {
} catch (DeprecatedRedirectException|ResponsableInterface $e) {
$this->outputBufferingEnd();
if ($e instanceof DeprecatedRedirectException) {
$e = new RedirectException($e->getMessage(), $e->getCode(), $e);
Expand Down
14 changes: 14 additions & 0 deletions system/Commands/Database/MigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use CodeIgniter\Database\MigrationRunner;
use Throwable;

/**
Expand Down Expand Up @@ -78,10 +79,23 @@ public function run(array $params)
// @codeCoverageIgnoreEnd
}

/** @var MigrationRunner $runner */
$runner = service('migrations');

try {
$batch = $params['b'] ?? CLI::getOption('b') ?? $runner->getLastBatch() - 1;

if (is_string($batch)) {
if (! ctype_digit($batch)) {
CLI::error('Invalid batch number: ' . $batch, 'light_gray', 'red');
CLI::newLine();

return EXIT_ERROR;
}

$batch = (int) $batch;
}

CLI::write(lang('Migrations.rollingBack') . ' ' . $batch, 'yellow');

if (! $runner->regress($batch)) {
Expand Down
24 changes: 24 additions & 0 deletions system/Commands/Database/ShowTableInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ private function restoreDBPrefix(): void
$this->db->setPrefix($this->DBPrefix);
}

/**
* Show Data of Table
*
* @return void
*/
private function showDataOfTable(string $tableName, int $limitRows, int $limitFieldValue)
{
CLI::write("Data of Table \"{$tableName}\":", 'black', 'yellow');
Expand All @@ -207,6 +212,13 @@ private function showDataOfTable(string $tableName, int $limitRows, int $limitFi
CLI::table($this->tbody, $thead);
}

/**
* Show All Tables
*
* @param list<string> $tables
*
* @return void
*/
private function showAllTables(array $tables)
{
CLI::write('The following is a list of the names of all database tables:', 'black', 'yellow');
Expand All @@ -219,6 +231,13 @@ private function showAllTables(array $tables)
CLI::newLine();
}

/**
* Make body for table
*
* @param list<string> $tables
*
* @return list<list<int|string>>
*/
private function makeTbodyForShowAllTables(array $tables): array
{
$this->removeDBPrefix();
Expand All @@ -244,6 +263,11 @@ private function makeTbodyForShowAllTables(array $tables): array
return $this->tbody;
}

/**
* Make table rows
*
* @return list<list<int|string>>
*/
private function makeTableRows(
string $tableName,
int $limitRows,
Expand Down
4 changes: 4 additions & 0 deletions system/Commands/ListCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public function run(array $params)

/**
* Lists the commands with accompanying info.
*
* @return void
*/
protected function listFull(array $commands)
{
Expand Down Expand Up @@ -126,6 +128,8 @@ protected function listFull(array $commands)

/**
* Lists the commands only.
*
* @return void
*/
protected function listSimple(array $commands)
{
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Server/Serve.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function run(array $params)
$docroot = escapeshellarg(FCPATH);

// Mimic Apache's mod_rewrite functionality with user settings.
$rewrite = escapeshellarg(__DIR__ . '/rewrite.php');
$rewrite = escapeshellarg(SYSTEMPATH . 'rewrite.php');

// Call PHP's built-in webserver, making sure to set our
// base path to the public folder, and to use the rewrite file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class AutoRouteCollector
* @param string $namespace namespace to search
* @param list<class-string> $protectedControllers List of controllers in Defined
* Routes that should not be accessed via Auto-Routing.
* @param list<string> $httpMethods
* @param string $prefix URI prefix for Module Routing
*/
public function __construct(
Expand Down Expand Up @@ -91,6 +92,13 @@ public function get(): array
return $tbody;
}

/**
* Adding Filters
*
* @param list<array<string, array|string>> $routes
*
* @return list<array<string, array|string>>
*/
private function addFilters($routes)
{
$filterCollector = new FilterCollector(true);
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Utilities/Routes/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use CodeIgniter\Exceptions\PageNotFoundException;
use CodeIgniter\Filters\Filters;
use CodeIgniter\HTTP\Exceptions\BadRequestException;
use CodeIgniter\HTTP\Exceptions\RedirectException;
use CodeIgniter\Router\Router;
use Config\Feature;
Expand Down Expand Up @@ -72,7 +73,7 @@ public function find(string $uri): array
'before' => [],
'after' => [],
];
} catch (PageNotFoundException) {
} catch (BadRequestException|PageNotFoundException) {
return [
'before' => ['<unknown>'],
'after' => ['<unknown>'],
Expand Down
6 changes: 6 additions & 0 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ public static function serviceExists(string $name): ?string
* Reset shared instances and mocks for testing.
*
* @return void
*
* @testTag only available to test code
*/
public static function reset(bool $initAutoloader = true)
{
Expand All @@ -362,6 +364,8 @@ public static function reset(bool $initAutoloader = true)
* Resets any mock and shared instances for a single service.
*
* @return void
*
* @testTag only available to test code
*/
public static function resetSingle(string $name)
{
Expand All @@ -375,6 +379,8 @@ public static function resetSingle(string $name)
* @param object $mock
*
* @return void
*
* @testTag only available to test code
*/
public static function injectMock(string $name, $mock)
{
Expand Down
7 changes: 3 additions & 4 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1448,11 +1448,12 @@ public function orHaving($key, $value = null, ?bool $escape = null)
*/
public function orderBy(string $orderBy, string $direction = '', ?bool $escape = null)
{
$qbOrderBy = [];
if ($orderBy === '') {
return $this;
}

$qbOrderBy = [];

$direction = strtoupper(trim($direction));

if ($direction === 'RANDOM') {
Expand All @@ -1463,7 +1464,7 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
$direction = in_array($direction, ['ASC', 'DESC'], true) ? ' ' . $direction : '';
}

if (! is_bool($escape)) {
if ($escape === null) {
$escape = $this->db->protectIdentifiers;
}

Expand All @@ -1474,8 +1475,6 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
'escape' => false,
];
} else {
$qbOrderBy = [];

foreach (explode(',', $orderBy) as $field) {
$qbOrderBy[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE))
? [
Expand Down
15 changes: 11 additions & 4 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ public function initialize()

/**
* Close the database connection.
*
* @return void
*/
public function close()
{
Expand Down Expand Up @@ -736,6 +738,8 @@ public function simpleQuery(string $sql)
* Disable Transactions
*
* This permits transactions to be disabled at run-time.
*
* @return void
*/
public function transOff()
{
Expand Down Expand Up @@ -1454,7 +1458,7 @@ protected function getDriverFunctionPrefix(): string
/**
* Returns an array of table names
*
* @return array|false
* @return false|list<string>
*
* @throws DatabaseException
*/
Expand All @@ -1481,6 +1485,7 @@ public function listTables(bool $constrainByPrefix = false)
$query = $this->query($sql);

foreach ($query->getResultArray() as $row) {
/** @var string $table */
$table = $row['table_name'] ?? $row['TABLE_NAME'] ?? $row[array_key_first($row)];

$this->dataCache['table_names'][] = $table;
Expand Down Expand Up @@ -1531,7 +1536,7 @@ public function tableExists(string $tableName, bool $cached = true): bool
/**
* Fetch Field Names
*
* @return array|false
* @return false|list<string>
*
* @throws DatabaseException
*/
Expand Down Expand Up @@ -1608,7 +1613,7 @@ public function getIndexData(string $table)
/**
* Returns an object with foreign key data
*
* @return array
* @return array<string, stdClass>
*/
public function getForeignKeyData(string $table)
{
Expand Down Expand Up @@ -1769,7 +1774,9 @@ abstract protected function _listColumns(string $table = '');
/**
* Platform-specific field data information.
*
* @see getFieldData()
* @see getFieldData()
*
* @return list<stdClass>
*/
abstract protected function _fieldData(string $table): array;

Expand Down
2 changes: 2 additions & 0 deletions system/Database/MySQLi/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ public function connect(bool $persistent = false)
/**
* Keep or establish the connection if no queries have been sent for
* a length of time exceeding the server's idle timeout.
*
* @return void
*/
public function reconnect()
{
Expand Down
10 changes: 7 additions & 3 deletions system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class Connection extends BaseConnection
*/
private function isValidDSN(): bool
{
if ($this->DSN === null || $this->DSN === '') {
return false;
}

foreach ($this->validDSNs as $regexp) {
if (preg_match($regexp, $this->DSN)) {
return true;
Expand All @@ -120,13 +124,13 @@ private function isValidDSN(): bool
*/
public function connect(bool $persistent = false)
{
if (empty($this->DSN) && ! $this->isValidDSN()) {
if (! $this->isValidDSN()) {
$this->buildDSN();
}

$func = $persistent ? 'oci_pconnect' : 'oci_connect';

return empty($this->charset)
return ($this->charset === '')
? $func($this->username, $this->password, $this->DSN)
: $func($this->username, $this->password, $this->DSN, $this->charset);
}
Expand Down Expand Up @@ -632,7 +636,7 @@ protected function buildDSN()
}

$isEasyConnectableHostName = $this->hostname !== '' && ! str_contains($this->hostname, '/') && ! str_contains($this->hostname, ':');
$easyConnectablePort = ! empty($this->port) && ctype_digit($this->port) ? ':' . $this->port : '';
$easyConnectablePort = ($this->port !== '') && ctype_digit((string) $this->port) ? ':' . $this->port : '';
$easyConnectableDatabase = $this->database !== '' ? '/' . ltrim($this->database, '/') : '';

if ($isEasyConnectableHostName && ($easyConnectablePort !== '' || $easyConnectableDatabase !== '')) {
Expand Down
4 changes: 4 additions & 0 deletions system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public function connect(bool $persistent = false)

/**
* Converts the DSN with semicolon syntax.
*
* @return void
*/
private function convertDSN()
{
Expand Down Expand Up @@ -143,6 +145,8 @@ private function convertDSN()
/**
* Keep or establish the connection if no queries have been sent for
* a length of time exceeding the server's idle timeout.
*
* @return void
*/
public function reconnect()
{
Expand Down
Loading

0 comments on commit be27314

Please sign in to comment.