Skip to content

Commit

Permalink
Release v4.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jun 10, 2024
1 parent 9b2cd73 commit 163f111
Show file tree
Hide file tree
Showing 59 changed files with 285 additions and 137 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ PHP version 8.1 or higher is required, with the following extensions installed:
- [mbstring](http://php.net/manual/en/mbstring.installation.php)

> [!WARNING]
> The end of life date for PHP 7.4 was November 28, 2022.
> The end of life date for PHP 8.0 was November 26, 2023.
> If you are still using PHP 7.4 or 8.0, you should upgrade immediately.
> The end of life date for PHP 8.1 will be November 25, 2024.
> - The end of life date for PHP 7.4 was November 28, 2022.
> - The end of life date for PHP 8.0 was November 26, 2023.
> - If you are still using PHP 7.4 or 8.0, you should upgrade immediately.
> - The end of life date for PHP 8.1 will be December 31, 2025.
Additionally, make sure that the following extensions are enabled in your PHP:

Expand Down
Empty file modified app/Config/DocTypes.php
100755 → 100644
Empty file.
8 changes: 3 additions & 5 deletions app/Config/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ class Exceptions extends BaseConfig

/**
* --------------------------------------------------------------------------
* LOG DEPRECATIONS INSTEAD OF THROWING?
* WHETHER TO THROW AN EXCEPTION ON DEPRECATED ERRORS
* --------------------------------------------------------------------------
* By default, CodeIgniter converts deprecations into exceptions. Also,
* starting in PHP 8.1 will cause a lot of deprecated usage warnings.
* Use this option to temporarily cease the warnings and instead log those.
* This option also works for user deprecations.
* If set to `true`, DEPRECATED errors are only logged and no exceptions are
* thrown. This option also works for user deprecations.
*/
public bool $logDeprecations = true;

Expand Down
22 changes: 6 additions & 16 deletions preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@
// Path to the front controller
define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR);

/**
* See https://www.php.net/manual/en/function.str-contains.php#126277
*/
if (! function_exists('str_contains')) {
/**
* Polyfill of str_contains()
*/
function str_contains(string $haystack, string $needle): bool
{
return empty($needle) || strpos($haystack, $needle) !== false;
}
}

class preload
{
/**
Expand All @@ -51,6 +38,7 @@ class preload
[
'include' => __DIR__ . '/vendor/codeigniter4/framework/system', // Change this path if using manual installation
'exclude' => [
'/system/bootstrap.php',
// Not needed if you don't use them.
'/system/Database/OCI8/',
'/system/Database/Postgre/',
Expand All @@ -77,16 +65,18 @@ public function __construct()
$this->loadAutoloader();
}

private function loadAutoloader()
private function loadAutoloader(): void
{
$paths = new Config\Paths();
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php';
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'Boot.php';

CodeIgniter\Boot::preload($paths);
}

/**
* Load PHP files.
*/
public function load()
public function load(): void
{
foreach ($this->paths as $path) {
$directory = new RecursiveDirectoryIterator($path['include']);
Expand Down
2 changes: 1 addition & 1 deletion spark
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

// Refuse to run when called from php-cgi
if (strpos(PHP_SAPI, 'cgi') === 0) {
if (str_starts_with(PHP_SAPI, 'cgi')) {
exit("The cli tool is not supported when running php-cgi. It needs php-cli to function!\n\n");
}

Expand Down
13 changes: 13 additions & 0 deletions system/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ public static function bootTest(Paths $paths): void
static::autoloadHelpers();
}

/**
* Used by `preload.php`
*/
public static function preload(Paths $paths): void
{
static::definePathConstants($paths);
static::loadConstants();
static::defineEnvironment();
static::loadEnvironmentBootstrap($paths, false);

static::loadAutoloader();
}

/**
* Load environment settings from .env files into $_SERVER and $_ENV
*/
Expand Down
17 changes: 11 additions & 6 deletions system/CLI/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ public static function prompt(string $field, $options = null, $validation = null
static::fwrite(STDOUT, $field . (trim($field) !== '' ? ' ' : '') . $extraOutput . ': ');

// Read the input from keyboard.
$input = trim(static::$io->input()) ?: (string) $default;
$input = trim(static::$io->input());
$input = ($input === '') ? (string) $default : $input;

if ($validation !== []) {
while (! static::validate('"' . trim($field) . '"', $input, $validation)) {
Expand Down Expand Up @@ -330,7 +331,9 @@ public static function promptByMultipleKeys(string $text, array $options): array
CLI::write($text);
CLI::printKeysAndValues($options);
CLI::newLine();
$input = static::prompt($extraOutput) ?: 0; // 0 is default

$input = static::prompt($extraOutput);
$input = ($input === '') ? '0' : $input; // 0 is default

// validation
while (true) {
Expand All @@ -343,13 +346,15 @@ public static function promptByMultipleKeys(string $text, array $options): array
// find max from input
$maxInput = max($inputToArray);

// return the prompt again if $input contain(s) non-numeric charachter, except a comma.
// And if max from $options less than max from input
// it is mean user tried to access null value in $options
// return the prompt again if $input contain(s) non-numeric character, except a comma.
// And if max from $options less than max from input,
// it means user tried to access null value in $options
if (! $pattern || $maxOptions < $maxInput) {
static::error('Please select correctly.');
CLI::newLine();
$input = static::prompt($extraOutput) ?: 0;

$input = static::prompt($extraOutput);
$input = ($input === '') ? '0' : $input;
} else {
break;
}
Expand Down
16 changes: 13 additions & 3 deletions system/CLI/GeneratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ trait GeneratorTrait
*
* @internal
*
* @var array
* @var array<int|string, string|null>
*/
private $params = [];

/**
* Execute the command.
*
* @param array<int|string, string|null> $params
*
* @deprecated use generateClass() instead
*/
protected function execute(array $params): void
Expand All @@ -112,6 +114,8 @@ protected function execute(array $params): void

/**
* Generates a class file from an existing template.
*
* @param array<int|string, string|null> $params
*/
protected function generateClass(array $params): void
{
Expand All @@ -134,7 +138,8 @@ protected function generateClass(array $params): void
/**
* Generate a view file from an existing template.
*
* @param string $view namespaced view name that is generated
* @param string $view namespaced view name that is generated
* @param array<int|string, string|null> $params
*/
protected function generateView(string $view, array $params): void
{
Expand Down Expand Up @@ -331,6 +336,8 @@ private function normalizeInputClassName(): string
/**
* Gets the generator view as defined in the `Config\Generators::$views`,
* with fallback to `$template` when the defined view does not exist.
*
* @param array<string, mixed> $data
*/
protected function renderTemplate(array $data = []): string
{
Expand All @@ -352,7 +359,10 @@ protected function renderTemplate(array $data = []): string
/**
* Performs pseudo-variables contained within view file.
*
* @param string $class namespaced classname or namespaced view.
* @param string $class namespaced classname or namespaced view.
* @param list<string> $search
* @param list<string> $replace
* @param array<string, bool|string|null> $data
*
* @return string generated file content
*/
Expand Down
2 changes: 1 addition & 1 deletion 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.1';
public const CI_VERSION = '4.5.2';

/**
* App startup time.
Expand Down
4 changes: 4 additions & 0 deletions system/Commands/Encryption/GenerateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ protected function generateRandomKey(string $prefix, int $length): string

/**
* Sets the new encryption key in your .env file.
*
* @param array<int|string, string|null> $params
*/
protected function setNewEncryptionKey(string $key, array $params): bool
{
Expand All @@ -139,6 +141,8 @@ protected function setNewEncryptionKey(string $key, array $params): bool

/**
* Checks whether to overwrite existing encryption key.
*
* @param array<int|string, string|null> $params
*/
protected function confirmOverwrite(array $params): bool
{
Expand Down
2 changes: 2 additions & 0 deletions system/Config/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class Filters extends BaseConfig
* If you use this, you should disable auto-routing because auto-routing
* permits any HTTP method to access a controller. Accessing the controller
* with a method you don't expect could bypass the filter.
*
* @var array<string, list<string>>
*/
public array $methods = [];

Expand Down
2 changes: 1 addition & 1 deletion system/DataCaster/DataCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function castAs(mixed $value, string $field, string $method = 'get'): mix
$params = array_map('trim', explode(',', $matches[2]));
}

if ($isNullable) {
if ($isNullable && ! $this->strict) {
$params[] = 'nullable';
}

Expand Down
27 changes: 20 additions & 7 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ public function join(string $table, $cond, string $type = '', ?bool $escape = nu
$cond = ' ON ' . $cond;
} else {
// Split multiple conditions
// @TODO This does not parse `BETWEEN a AND b` correctly.
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) {
$conditions = [];
$joints = $joints[0];
Expand All @@ -676,6 +677,13 @@ public function join(string $table, $cond, string $type = '', ?bool $escape = nu
foreach ($conditions as $i => $condition) {
$operator = $this->getOperator($condition);

// Workaround for BETWEEN
if ($operator === false) {
$cond .= $joints[$i] . $condition;

continue;
}

$cond .= $joints[$i];
$cond .= preg_match('/(\(*)?([\[\]\w\.\'-]+)' . preg_quote($operator, '/') . '(.*)/i', $condition, $match) ? $match[1] . $this->db->protectIdentifiers($match[2]) . $operator . $this->db->protectIdentifiers($match[3]) : $condition;
}
Expand Down Expand Up @@ -1090,7 +1098,7 @@ public function orNotHavingLike($field, string $match = '', string $side = 'both
* @used-by notHavingLike()
* @used-by orNotHavingLike()
*
* @param array|RawSql|string $field
* @param array<string, string>|RawSql|string $field
*
* @return $this
*/
Expand Down Expand Up @@ -2376,7 +2384,9 @@ protected function validateInsert(): bool
/**
* Generates a platform-specific insert string from the supplied data
*
* @param string $table Protected table name
* @param string $table Protected table name
* @param list<string> $keys Keys of QBSet
* @param list<int|string> $unescapedKeys Values of QBSet
*/
protected function _insert(string $table, array $keys, array $unescapedKeys): string
{
Expand Down Expand Up @@ -2416,7 +2426,9 @@ public function replace(?array $set = null)
/**
* Generates a platform-specific replace string from the supplied data
*
* @param string $table Protected table name
* @param string $table Protected table name
* @param list<string> $keys Keys of QBSet
* @param list<int|string> $values Values of QBSet
*/
protected function _replace(string $table, array $keys, array $values): string
{
Expand Down Expand Up @@ -2512,7 +2524,8 @@ public function update($set = null, $where = null, ?int $limit = null): bool
/**
* Generates a platform-specific update string from the supplied data
*
* @param string $table Protected table name
* @param string $table Protected table name
* @param array<string, string> $values QBSet
*/
protected function _update(string $table, array $values): string
{
Expand Down Expand Up @@ -2863,9 +2876,9 @@ public function deleteBatch($set = null, $constraints = null, int $batchSize = 1
*
* @used-by batchExecute()
*
* @param string $table Protected table name
* @param list<string> $keys QBKeys
* @paramst<string|int>> $values QBSet
* @param string $table Protected table name
* @param list<string> $keys QBKeys
* @param list<int|string> $values QBSet
*/
protected function _deleteBatch(string $table, array $keys, array $values): string
{
Expand Down
16 changes: 13 additions & 3 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,12 @@ public function initialize()
// Connect to the database and set the connection ID
$this->connID = $this->connect($this->pConnect);
} catch (Throwable $e) {
$connectionErrors[] = sprintf('Main connection [%s]: %s', $this->DBDriver, $e->getMessage());
$this->connID = false;
$connectionErrors[] = sprintf(
'Main connection [%s]: %s',
$this->DBDriver,
$e->getMessage()
);
log_message('error', 'Error connecting to the database: ' . $e);
}

Expand All @@ -441,7 +446,12 @@ public function initialize()
// Try to connect
$this->connID = $this->connect($this->pConnect);
} catch (Throwable $e) {
$connectionErrors[] = sprintf('Failover #%d [%s]: %s', ++$index, $this->DBDriver, $e->getMessage());
$connectionErrors[] = sprintf(
'Failover #%d [%s]: %s',
++$index,
$this->DBDriver,
$e->getMessage()
);
log_message('error', 'Error connecting to the database: ' . $e);
}

Expand Down Expand Up @@ -479,7 +489,7 @@ public function close()
/**
* Platform dependent way method for closing the connection.
*
* @return mixed
* @return void
*/
abstract protected function _close();

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 @@ -246,6 +246,8 @@ public function reconnect()

/**
* Close the database connection.
*
* @return void
*/
protected function _close()
{
Expand Down
Loading

0 comments on commit 163f111

Please sign in to comment.