Skip to content

Commit

Permalink
Release v4.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jun 16, 2022
1 parent 29f0e9e commit f65a2cf
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 58 deletions.
19 changes: 8 additions & 11 deletions app/Config/Mimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ class Mimes
],
'pptx' => [
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/x-zip',
'application/zip',
],
'wbxml' => 'application/wbxml',
'wmlc' => 'application/wmlc',
Expand Down Expand Up @@ -512,20 +510,19 @@ public static function guessExtensionFromType(string $type, ?string $proposedExt

$proposedExtension = trim(strtolower($proposedExtension ?? ''));

if ($proposedExtension !== '') {
if (array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true)) {
// The detected mime type matches with the proposed extension.
return $proposedExtension;
}

// An extension was proposed, but the media type does not match the mime type list.
return null;
if (
$proposedExtension !== ''
&& array_key_exists($proposedExtension, static::$mimes)
&& in_array($type, (array) static::$mimes[$proposedExtension], true)
) {
// The detected mime type matches with the proposed extension.
return $proposedExtension;
}

// Reverse check the mime type list if no extension was proposed.
// This search is order sensitive!
foreach (static::$mimes as $ext => $types) {
if ((is_string($types) && $types === $type) || (is_array($types) && in_array($type, $types, true))) {
if (in_array($type, (array) $types, true)) {
return $ext;
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"mikey179/vfsstream": "^1.6",
"nexusphp/cs-config": "^3.3",
"phpunit/phpunit": "^9.1",
"predis/predis": "^1.1"
"predis/predis": "^1.1 || ^2.0"
},
"suggest": {
"ext-fileinfo": "Improves mime type detection for files"
Expand Down
2 changes: 0 additions & 2 deletions system/Cache/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ public function initialize()
} else {
throw new CriticalError('Cache: Not support Memcache(d) extension.');
}
} catch (CriticalError $e) {
throw $e;
} catch (Exception $e) {
throw new CriticalError('Cache: Memcache(d) connection refused (' . $e->getMessage() . ').');
}
Expand Down
6 changes: 2 additions & 4 deletions 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.2.0';
public const CI_VERSION = '4.2.1';

private const MIN_PHP_VERSION = '7.4';

Expand Down Expand Up @@ -256,9 +256,7 @@ protected function initializeKint()
require_once SYSTEMPATH . 'ThirdParty/Kint/init.php';
}

/**
* Config\Kint
*/
/** @var \Config\Kint $config */
$config = config(KintConfig::class);

Kint::$depth_limit = $config->maxDepth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function get(): array

foreach ($finder->find() as $class) {
// Exclude controllers in Defined Routes.
if (in_array($class, $this->protectedControllers, true)) {
if (in_array('\\' . $class, $this->protectedControllers, true)) {
continue;
}

Expand Down
4 changes: 3 additions & 1 deletion system/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class Cookie implements ArrayAccess, CloneableCookieInterface
* Set the default attributes to a Cookie instance by injecting
* the values from the `CookieConfig` config or an array.
*
* This method is called from Response::__construct().
*
* @param array<string, mixed>|CookieConfig $config
*
* @return array<string, mixed> The old defaults array. Useful for resetting.
Expand Down Expand Up @@ -209,7 +211,7 @@ final public function __construct(string $name, string $value = '', array $optio
}

// to preserve backward compatibility with array-based cookies in previous CI versions
$prefix = $options['prefix'] ?: self::$defaults['prefix'];
$prefix = ($options['prefix'] === '') ? self::$defaults['prefix'] : $options['prefix'];
$path = $options['path'] ?: self::$defaults['path'];
$domain = $options['domain'] ?: self::$defaults['domain'];

Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ protected function validateInsert(): bool
{
if (empty($this->QBSet)) {
if (CI_DEBUG) {
throw new DatabaseException('You must use the "set" method to update an entry.');
throw new DatabaseException('You must use the "set" method to insert an entry.');
}

return false; // @codeCoverageIgnore
Expand Down
19 changes: 18 additions & 1 deletion system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Closure;
use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Events\Events;
use Exception;
use stdClass;
use Throwable;

Expand Down Expand Up @@ -603,7 +604,14 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
$this->lastQuery = $query;

// Run the query for real
if (! $this->pretend && false === ($this->resultID = $this->simpleQuery($query->getQuery()))) {
try {
$exception = null;
$this->resultID = $this->simpleQuery($query->getQuery());
} catch (Exception $exception) {
$this->resultID = false;
}

if (! $this->pretend && $this->resultID === false) {
$query->setDuration($startTime, $startTime);

// This will trigger a rollback if transactions are being used
Expand All @@ -626,6 +634,15 @@ public function query(string $sql, $binds = null, bool $setEscapeFlags = true, s
}
}

if (! $this->pretend) {
// Let others do something with this query.
Events::trigger('DBQuery', $query);
}

if ($exception !== null) {
throw $exception;
}

return false;
}

Expand Down
4 changes: 4 additions & 0 deletions system/Database/MigrationRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ public function findMigrations(): array
$migrations = [];

foreach ($namespaces as $namespace) {
if (ENVIRONMENT !== 'testing' && $namespace === 'Tests\Support') {
continue;
}

foreach ($this->findNamespaceMigrations($namespace) as $migration) {
$migrations[$migration->uid] = $migration;
}
Expand Down
4 changes: 0 additions & 4 deletions system/Debug/Toolbar/Views/toolbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@
#debug-bar .ci-label img {
margin: unset;
}

.hide-sm {
display: none !important;
}
Expand Down Expand Up @@ -432,7 +431,6 @@
#debug-icon a:visited {
color: #DD8615;
}

#debug-bar {
background-color: #252525;
color: #DFDFDF;
Expand Down Expand Up @@ -526,11 +524,9 @@
#debug-bar .timeline .timer {
background-color: #DD8615;
}

.debug-view.show-view {
border-color: #DD8615;
}

.debug-view-path {
background-color: #FDC894;
color: #434343;
Expand Down
6 changes: 2 additions & 4 deletions system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -1046,10 +1046,8 @@ public function wordWrap($str, $charlim = null)
$output .= $line . $this->newline;
}

if ($unwrap) {
foreach ($unwrap as $key => $val) {
$output = str_replace('{{unwrapped' . $key . '}}', $val, $output);
}
foreach ($unwrap as $key => $val) {
$output = str_replace('{{unwrapped' . $key . '}}', $val, $output);
}

return $output;
Expand Down
7 changes: 6 additions & 1 deletion system/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ public function getSizeByUnit(string $unit = 'b')
*/
public function guessExtension(): ?string
{
return Mimes::guessExtensionFromType($this->getMimeType());
// naively get the path extension using pathinfo
$pathinfo = pathinfo($this->getRealPath() ?: $this->__toString()) + ['extension' => ''];

$proposedExtension = $pathinfo['extension'];

return Mimes::guessExtensionFromType($this->getMimeType(), $proposedExtension);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/CLIRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,6 @@ protected function parseCommand()
*/
public function isCLI(): bool
{
return true;
return is_cli();
}
}
2 changes: 1 addition & 1 deletion system/HTTP/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function negotiate(string $type, array $supported, bool $strictMatch = fa
*/
public function isCLI(): bool
{
return false;
return is_cli();
}

/**
Expand Down
5 changes: 4 additions & 1 deletion system/HTTP/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public function redirect(string $uri, string $method = 'auto', ?int $code = null
* @param string $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param string $prefix Cookie name prefix ('': the default prefix)
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether only make the cookie accessible via HTTP (no javascript)
* @param string|null $samesite
Expand Down Expand Up @@ -618,6 +618,9 @@ public function hasCookie(string $name, ?string $value = null, string $prefix =
/**
* Returns the cookie
*
* @param string $prefix Cookie prefix.
* '': the default prefix
*
* @return Cookie|Cookie[]|null
*/
public function getCookie(?string $name = null, string $prefix = '')
Expand Down
21 changes: 16 additions & 5 deletions system/Helpers/cookie_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

use Config\App;
use Config\Cookie;
use Config\Services;

//=============================================================================
Expand All @@ -28,7 +29,7 @@
* @param string $expire The number of seconds until expiration
* @param string $domain For site-wide cookie. Usually: .yourdomain.com
* @param string $path The cookie path
* @param string $prefix The cookie prefix
* @param string $prefix The cookie prefix ('': the default prefix)
* @param bool $secure True makes the cookie secure
* @param bool $httpOnly True makes the cookie accessible via http(s) only (no javascript)
* @param string|null $sameSite The cookie SameSite value
Expand All @@ -55,15 +56,25 @@ function set_cookie(
/**
* Fetch an item from the $_COOKIE array
*
* @param string $index
* @param string $index
* @param string|null $prefix Cookie name prefix.
* '': the prefix in Config\Cookie
* null: no prefix
*
* @return mixed
* @return array|string|null
*
* @see \CodeIgniter\HTTP\IncomingRequest::getCookie()
*/
function get_cookie($index, bool $xssClean = false)
function get_cookie($index, bool $xssClean = false, ?string $prefix = '')
{
$prefix = isset($_COOKIE[$index]) ? '' : config(App::class)->cookiePrefix;
if ($prefix === '') {
/** @var Cookie|null $cookie */
$cookie = config('Cookie');

// @TODO Remove Config\App fallback when deprecated `App` members are removed.
$prefix = $cookie instanceof Cookie ? $cookie->prefix : config(App::class)->cookiePrefix;
}

$request = Services::request();
$filter = $xssClean ? FILTER_SANITIZE_FULL_SPECIAL_CHARS : FILTER_DEFAULT;

Expand Down
6 changes: 3 additions & 3 deletions system/I18n/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(?string $time = null, $timezone = null, ?string $loc
// If a test instance has been provided, use it instead.
if ($time === '' && static::$testNow instanceof self) {
$timezone = $timezone ?: static::$testNow->getTimezone();
$time = (string) static::$testNow->toDateTimeString();
$time = static::$testNow->format('Y-m-d H:i:s');
}

$timezone = $timezone ?: date_default_timezone_get();
Expand Down Expand Up @@ -1005,7 +1005,7 @@ public function isAfter($testTime, ?string $timezone = null): bool
*/
public function humanize()
{
$now = IntlCalendar::fromDateTime(self::now($this->timezone)->toDateTimeString());
$now = IntlCalendar::fromDateTime(self::now($this->timezone));
$time = $this->getCalendar()->getTime();

$years = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
Expand Down Expand Up @@ -1106,7 +1106,7 @@ public function getUTCObject($time, ?string $timezone = null)
*/
public function getCalendar()
{
return IntlCalendar::fromDateTime($this->toDateTimeString());
return IntlCalendar::fromDateTime($this);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions system/Router/AutoRouterImproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ private function scanControllers(array $segments): array
$c = count($segments);

while ($c-- > 0) {
$segmentConvert = ucfirst(
$this->translateURIDashes === true
? str_replace('-', '_', $segments[0])
: $segments[0]
);
$segmentConvert = $this->translateURIDashes(ucfirst($segments[0]));

// as soon as we encounter any segment that is not PSR-4 compliant, stop searching
if (! $this->isValidSegment($segmentConvert)) {
Expand Down
2 changes: 1 addition & 1 deletion system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ public function reverseRoute(string $search, ...$params)
$namespace = trim($this->defaultNamespace, '\\') . '\\';
if (
substr($search, 0, 1) !== '\\'
|| substr($search, 0, strlen($namespace)) !== $namespace
&& substr($search, 0, strlen($namespace)) !== $namespace
) {
$search = $namespace . $search;
}
Expand Down
Loading

0 comments on commit f65a2cf

Please sign in to comment.