Skip to content

Commit

Permalink
Release v4.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 26, 2023
1 parent e91e4fa commit e3821f9
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
* loaded early on, and may also contain additional functions
* that you'd like to use throughout your entire application
*
* @see: https://codeigniter4.github.io/CodeIgniter4/
* @see: https://codeigniter.com/user_guide/extending/common.html
*/
9 changes: 9 additions & 0 deletions app/Config/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,13 @@ class Encryption extends BaseConfig
* Set to 'authentication' for CI3 Encryption compatibility.
*/
public string $authKeyInfo = '';

/**
* Cipher to use.
* This setting is only used by OpenSSLHandler.
*
* Set to 'AES-128-CBC' to decrypt encrypted data that encrypted
* by CI3 Encryption default configuration.
*/
public string $cipher = 'AES-256-CTR';
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"psr/log": "^1.1"
},
"require-dev": {
"kint-php/kint": "^5.0.3",
"kint-php/kint": "^5.0.4",
"codeigniter/coding-standard": "^1.5",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "3.13.0",
Expand Down
2 changes: 2 additions & 0 deletions system/API/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ protected function respond($data = null, ?int $status = null, string $message =
if ($data === null && $status === null) {
$status = 404;
$output = null;
$this->format($data);
} elseif ($data === null && is_numeric($status)) {
$output = null;
$this->format($data);
} else {
$status = empty($status) ? 200 : $status;
$output = $this->format($data);
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true,
while (false !== ($file = readdir($fp))) {
if (is_dir($sourceDir . $file) && $file[0] !== '.' && $topLevelOnly === false) {
$this->getDirFileInfo($sourceDir . $file . DIRECTORY_SEPARATOR, $topLevelOnly, true);
} elseif ($file[0] !== ".") {
} elseif (! is_dir($sourceDir . $file) && $file[0] !== ".") {
$_filedata[$file] = $this->getFileInfo($sourceDir . $file);
$_filedata[$file]['relative_path'] = $relativePath;
}
Expand Down
3 changes: 1 addition & 2 deletions system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,11 @@ public function getCacheInfo()
*/
public function getMetaData(string $key)
{
$key = static::validateKey($key, $this->prefix);
$value = $this->get($key);

if ($value !== null) {
$time = Time::now()->getTimestamp();
$ttl = $this->redis->ttl($key);
$ttl = $this->redis->ttl(static::validateKey($key, $this->prefix));

return [
'expire' => $ttl > 0 ? $time + $ttl : null,
Expand Down
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CodeIgniter
/**
* The current version of CodeIgniter Framework
*/
public const CI_VERSION = "4.3.2";
public const CI_VERSION = "4.3.3";

/**
* App startup time.
Expand Down
2 changes: 1 addition & 1 deletion system/Commands/Database/MigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MigrateRollback extends BaseCommand
* @var array
*/
protected $options = [
"-b" => "Specify a batch to roll back to; e.g. "3" to return to batch #3 or "-2" to roll back twice",
"-b" => "Specify a batch to roll back to; e.g. "3" to return to batch #3",
'-g' => 'Set database group',
'-f' => 'Force command - this option allows you to bypass the confirmation question when running this command in a production environment',
];
Expand Down
1 change: 1 addition & 0 deletions system/Commands/Utilities/Routes/ControllerFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function find(): array
$nsArray = explode('\\', trim($this->namespace, '\\'));
$count = count($nsArray);
$ns = '';
$files = [];

for ($i = 0; $i < $count; $i++) {
$ns .= '\\' . array_shift($nsArray);
Expand Down
10 changes: 7 additions & 3 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2021,9 +2021,9 @@ private function setAlias(string $alias): BaseBuilder
/**
* Sets update fields for upsert, update
*
* @param string|string[] $set
* @param bool $addToDefault adds update fields to the default ones
* @param array|null $ignore ignores items in set
* @param RawSql[]|string|string[] $set
* @param bool $addToDefault adds update fields to the default ones
* @param array|null $ignore ignores items in set
*
* @return $this
*/
Expand Down Expand Up @@ -3082,6 +3082,10 @@ protected function compileWhereHaving(string $qbKey): string
continue;
}

if ($qbkey instanceof RawSql) {
continue;
}

if ($qbkey['condition'] instanceof RawSql) {
$qbkey = $qbkey['condition'];

Expand Down
8 changes: 5 additions & 3 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public function exceptionHandler(Throwable $exception)

[$statusCode, $exitCode] = $this->determineCodes($exception);

// Get the first exception.
while ($prevException = $exception->getPrevious()) {
$exception = $prevException;
}

if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) {
log_message('critical', "{message}\nin {exFile} on line {exLine}.\n{trace}", [
'message' => $exception->getMessage(),
Expand Down Expand Up @@ -531,9 +536,6 @@ private static function renderBacktrace(array $backtrace): string
case is_resource($value):
return sprintf('resource (%s)', get_resource_type($value));

case is_string($value):
return var_export(clean_path($value), true);

default:
return var_export($value, true);
}
Expand Down
5 changes: 4 additions & 1 deletion system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,10 @@ protected function SMTPConnect()
$crypto = stream_socket_enable_crypto(
$this->SMTPConnect,
true,
STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT | STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT
| STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT
| STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
| STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT
);

if ($crypto !== true) {
Expand Down
4 changes: 2 additions & 2 deletions system/Filters/FilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface FilterInterface
* sent back to the client, allowing for error pages,
* redirects, etc.
*
* @param null $arguments
* @param array|null $arguments
*
* @return mixed
*/
Expand All @@ -41,7 +41,7 @@ public function before(RequestInterface $request, $arguments = null);
* to stop execution of other after filters, short of
* throwing an Exception or Error.
*
* @param null $arguments
* @param array|null $arguments
*
* @return mixed
*/
Expand Down
5 changes: 2 additions & 3 deletions system/HTTP/DownloadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ public function setContentType(string $mime, string $charset = 'UTF-8')
*/
public function noCache(): self
{
$this->removeHeader('Cache-control');

$this->setHeader('Cache-control', ['private', 'no-transform', 'no-store', 'must-revalidate']);
$this->removeHeader('Cache-Control');
$this->setHeader('Cache-Control', ['private', 'no-transform', 'no-store', 'must-revalidate']);

return $this;
}
Expand Down
4 changes: 2 additions & 2 deletions system/HTTP/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function isValidIP(string $ip, ?string $which = null): bool;
* Fetch an item from the $_SERVER array.
* Supplied by RequestTrait.
*
* @param string $index Index for item to be fetched from $_SERVER
* @param null $filter A filter name to be applied
* @param array|string|null $index Index for item to be fetched from $_SERVER
* @param int|null $filter A filter name to be applied
*
* @return mixed
*/
Expand Down
8 changes: 4 additions & 4 deletions system/HTTP/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private function getClientIP(string $header): ?string
*
* @param array|string|null $index Index for item to be fetched from $_SERVER
* @param int|null $filter A filter name to be applied
* @param null $flags
* @param array|int|null $flags
*
* @return mixed
*/
Expand All @@ -204,9 +204,9 @@ public function getServer($index = null, $filter = null, $flags = null)
/**
* Fetch an item from the $_ENV array.
*
* @param null $index Index for item to be fetched from $_ENV
* @param null $filter A filter name to be applied
* @param null $flags
* @param array|string|null $index Index for item to be fetched from $_ENV
* @param int|null $filter A filter name to be applied
* @param array|int|null $flags
*
* @return mixed
*/
Expand Down
6 changes: 3 additions & 3 deletions system/HTTP/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ protected function formatBody($body, string $format)
*/
public function noCache()
{
$this->removeHeader("Cache-control");
$this->setHeader("Cache-control", ["no-store", "max-age=0", "no-cache"]);
$this->removeHeader("Cache-Control");
$this->setHeader("Cache-Control", ["no-store", "max-age=0", "no-cache"]);

return $this;
}
Expand Down Expand Up @@ -399,7 +399,7 @@ public function setCache(array $options = [])
unset($options['last-modified']);
}

$this->setHeader("Cache-control", $options);
$this->setHeader("Cache-Control", $options);

return $this;
}
Expand Down
76 changes: 70 additions & 6 deletions system/Helpers/text_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ function random_string(string $type = 'alnum', int $len = 8): string
{
switch ($type) {
case 'alnum':
case 'numeric':
case 'nozero':
case 'alpha':
switch ($type) {
Expand All @@ -555,16 +554,18 @@ function random_string(string $type = 'alnum', int $len = 8): string
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;

case 'numeric':
$pool = '0123456789';
break;

case 'nozero':
$pool = '123456789';
break;
}

return substr(str_shuffle(str_repeat($pool, (int) ceil($len / strlen($pool)))), 0, $len);
return _from_random($len, $pool);

case 'numeric':
$max = 10 ** $len - 1;
$rand = random_int(0, $max);

return sprintf('%0' . $len . 'd', $rand);

case 'md5':
return md5(uniqid((string) mt_rand(), true));
Expand All @@ -586,6 +587,69 @@ function random_string(string $type = 'alnum', int $len = 8): string
}
}

if (! function_exists('_from_random')) {
/**
* The following function was derived from code of Symfony (v6.2.7 - 2023-02-28)
* https://github.com/symfony/symfony/blob/80cac46a31d4561804c17d101591a4f59e6db3a2/src/Symfony/Component/String/ByteString.php#L45
* Code subject to the MIT license (https://github.com/symfony/symfony/blob/v6.2.7/LICENSE).
* Copyright (c) 2004-present Fabien Potencier
*
* The following method was derived from code of the Hack Standard Library (v4.40 - 2020-05-03)
* https://github.com/hhvm/hsl/blob/80a42c02f036f72a42f0415e80d6b847f4bf62d5/src/random/private.php#L16
* Code subject to the MIT license (https://github.com/hhvm/hsl/blob/master/LICENSE).
* Copyright (c) 2004-2020, Facebook, Inc. (https://www.facebook.com/)
*
* @internal Outside the framework this should not be used directly.
*/
function _from_random(int $length, string $pool): string
{
if ($length <= 0) {
throw new InvalidArgumentException(
sprintf('A strictly positive length is expected, "%d" given.', $length)
);
}

$poolSize = \strlen($pool);
$bits = (int) ceil(log($poolSize, 2.0));
if ($bits <= 0 || $bits > 56) {
throw new InvalidArgumentException(
'The length of the alphabet must in the [2^1, 2^56] range.'
);
}

$string = '';

while ($length > 0) {
$urandomLength = (int) ceil(2 * $length * $bits / 8.0);
$data = random_bytes($urandomLength);
$unpackedData = 0;
$unpackedBits = 0;

for ($i = 0; $i < $urandomLength && $length > 0; $i++) {
// Unpack 8 bits
$unpackedData = ($unpackedData << 8) | \ord($data[$i]);
$unpackedBits += 8;

// While we have enough bits to select a character from the alphabet, keep
// consuming the random data
for (; $unpackedBits >= $bits && $length > 0; $unpackedBits -= $bits) {
$index = ($unpackedData & ((1 << $bits) - 1));
$unpackedData >>= $bits;
// Unfortunately, the alphabet size is not necessarily a power of two.
// Worst case, it is 2^k + 1, which means we need (k+1) bits and we
// have around a 50% chance of missing as k gets larger
if ($index < $poolSize) {
$string .= $pool[$index];
$length--;
}
}
}
}

return $string;
}
}

if (! function_exists('increment_string')) {
/**
* Add's _1 to a string or increment the ending number to allow _2, _3, etc
Expand Down
9 changes: 8 additions & 1 deletion system/Helpers/url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,20 @@ function site_url($relativePath = '', ?string $scheme = null, ?App $config = nul
{
$uri = _get_uri($relativePath, $config);

return URI::createURIString(
$uriString = URI::createURIString(
$scheme ?? $uri->getScheme(),
$uri->getAuthority(),
$uri->getPath(),
$uri->getQuery(),
$uri->getFragment()
);

// For protocol-relative links
if ($scheme === '') {
$uriString = '//' . $uriString;
}

return $uriString;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(SplFileInfo $fileInfo)
$this->path = $fileInfo->getPathname();

try {
if ($fileInfo->getRealPath()) {
if (\strlen($this->path) && $fileInfo->getRealPath()) {
$this->perms = $fileInfo->getPerms();
$this->size = $fileInfo->getSize();
$this->owner = $fileInfo->getOwner();
Expand Down
Loading

0 comments on commit e3821f9

Please sign in to comment.