Skip to content

Commit

Permalink
Release v4.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 28, 2024
1 parent 2849e7f commit 7822476
Show file tree
Hide file tree
Showing 134 changed files with 637 additions and 530 deletions.
4 changes: 2 additions & 2 deletions app/Config/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
*/
if (CI_DEBUG && ! is_cli()) {
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
Services::toolbar()->respond();
service('toolbar')->respond();
// Hot Reload route - for framework use on the hot reloader.
if (ENVIRONMENT === 'development') {
Services::routes()->get('__hot-reload', static function (): void {
service('routes')->get('__hot-reload', static function (): void {
(new HotReloader())->run();
});
}
Expand Down
2 changes: 1 addition & 1 deletion app/Config/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ class Format extends BaseConfig
*/
public function getFormatter(string $mime)
{
return Services::format()->getFormatter($mime);
return service('format')->getFormatter($mime);
}
}
2 changes: 1 addition & 1 deletion app/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ public function initController(RequestInterface $request, ResponseInterface $res

// Preload any models, libraries, etc, here.

// E.g.: $this->session = \Config\Services::session();
// E.g.: $this->session = service('session');
}
}
2 changes: 1 addition & 1 deletion app/Views/errors/cli/error_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

$args = implode(', ', array_map(static fn ($value) => match (true) {
is_object($value) => 'Object(' . $value::class . ')',
is_array($value) => count($value) ? '[...]' : '[]',
is_array($value) => $value !== [] ? '[...]' : '[]',
$value === null => 'null', // return the lowercased version
default => var_export($value, true),
}, array_values($error['args'] ?? [])));
Expand Down
5 changes: 2 additions & 3 deletions app/Views/errors/html/error_exception.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
use CodeIgniter\HTTP\Header;
use Config\Services;
use CodeIgniter\CodeIgniter;

$errorId = uniqid('error', true);
Expand Down Expand Up @@ -225,7 +224,7 @@

<!-- Request -->
<div class="content" id="request">
<?php $request = Services::request(); ?>
<?php $request = service('request'); ?>

<table>
<tbody>
Expand Down Expand Up @@ -343,7 +342,7 @@

<!-- Response -->
<?php
$response = Services::response();
$response = service('response');
$response->setStatusCode(http_response_code());
?>
<div class="content" id="response">
Expand Down
8 changes: 5 additions & 3 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Config\Autoload;
use Config\Kint as KintConfig;
use Config\Modules;
use Config\Services;
use InvalidArgumentException;
use Kint;
use Kint\Renderer\CliRenderer;
Expand Down Expand Up @@ -367,6 +366,9 @@ public function sanitizeFilename(string $filename): string
return $cleanFilename;
}

/**
* @param array{only?: list<string>, exclude?: list<string>} $composerPackages
*/
private function loadComposerNamespaces(ClassLoader $composer, array $composerPackages): void
{
$namespacePaths = $composer->getPrefixesPsr4();
Expand All @@ -380,7 +382,7 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa
}
}

if (! method_exists(InstalledVersions::class, 'getAllRawData')) {
if (! method_exists(InstalledVersions::class, 'getAllRawData')) { // @phpstan-ignore function.alreadyNarrowedType
throw new RuntimeException(
'Your Composer version is too old.'
. ' Please update Composer (run `composer self-update`) to v2.0.14 or later'
Expand Down Expand Up @@ -537,7 +539,7 @@ private function configureKint(): void
Kint::$plugins = $config->plugins;
}

$csp = Services::csp();
$csp = service('csp');
if ($csp->enabled()) {
RichRenderer::$js_nonce = $csp->getScriptNonce();
RichRenderer::$css_nonce = $csp->getStyleNonce();
Expand Down
31 changes: 19 additions & 12 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ public function getClassname(string $file): string

if ((isset($tokens[$i - 2][1]) && ($tokens[$i - 2][1] === 'phpnamespace' || $tokens[$i - 2][1] === 'namespace')) || ($dlm && $tokens[$i - 1][0] === T_NS_SEPARATOR && $token[0] === T_STRING)) {
if (! $dlm) {
$namespace = 0;
$namespace = '';
}

if (isset($token[1])) {
$namespace = $namespace ? $namespace . '\\' . $token[1] : $token[1];
$namespace = $namespace !== '' ? $namespace . '\\' . $token[1] : $token[1];
$dlm = true;
}
} elseif ($dlm && ($token[0] !== T_NS_SEPARATOR) && ($token[0] !== T_STRING)) {
Expand Down Expand Up @@ -194,8 +195,9 @@ public function search(string $path, string $ext = 'php', bool $prioritizeApp =

foreach ($this->getNamespaces() as $namespace) {
if (isset($namespace['path']) && is_file($namespace['path'] . $path)) {
$fullPath = $namespace['path'] . $path;
$fullPath = realpath($fullPath) ?: $fullPath;
$fullPath = $namespace['path'] . $path;
$resolvedPath = realpath($fullPath);
$fullPath = $resolvedPath !== false ? $resolvedPath : $fullPath;

if ($prioritizeApp) {
$foundPaths[] = $fullPath;
Expand Down Expand Up @@ -272,14 +274,16 @@ protected function getNamespaces()
*/
public function findQualifiedNameFromPath(string $path)
{
$path = realpath($path) ?: $path;
$resolvedPath = realpath($path);
$path = $resolvedPath !== false ? $resolvedPath : $path;

if (! is_file($path)) {
return false;
}

foreach ($this->getNamespaces() as $namespace) {
$namespace['path'] = realpath($namespace['path']) ?: $namespace['path'];
$resolvedNamespacePath = realpath($namespace['path']);
$namespace['path'] = $resolvedNamespacePath !== false ? $resolvedNamespacePath : $namespace['path'];

if ($namespace['path'] === '') {
continue;
Expand Down Expand Up @@ -331,8 +335,9 @@ public function listFiles(string $path): array
helper('filesystem');

foreach ($this->getNamespaces() as $namespace) {
$fullPath = $namespace['path'] . $path;
$fullPath = realpath($fullPath) ?: $fullPath;
$fullPath = $namespace['path'] . $path;
$resolvedPath = realpath($fullPath);
$fullPath = $resolvedPath !== false ? $resolvedPath : $fullPath;

if (! is_dir($fullPath)) {
continue;
Expand Down Expand Up @@ -365,8 +370,9 @@ public function listNamespaceFiles(string $prefix, string $path): array

// autoloader->getNamespace($prefix) returns an array of paths for that namespace
foreach ($this->autoloader->getNamespace($prefix) as $namespacePath) {
$fullPath = rtrim($namespacePath, '/') . '/' . $path;
$fullPath = realpath($fullPath) ?: $fullPath;
$fullPath = rtrim($namespacePath, '/') . '/' . $path;
$resolvedPath = realpath($fullPath);
$fullPath = $resolvedPath !== false ? $resolvedPath : $fullPath;

if (! is_dir($fullPath)) {
continue;
Expand All @@ -392,8 +398,9 @@ public function listNamespaceFiles(string $prefix, string $path): array
*/
protected function legacyLocate(string $file, ?string $folder = null)
{
$path = APPPATH . ($folder === null ? $file : $folder . '/' . $file);
$path = realpath($path) ?: $path;
$path = APPPATH . ($folder === null ? $file : $folder . '/' . $file);
$resolvedPath = realpath($path);
$path = $resolvedPath !== false ? $resolvedPath : $path;

if (is_file($path)) {
return $path;
Expand Down
5 changes: 5 additions & 0 deletions system/Autoloader/FileLocatorCached.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ final class FileLocatorCached implements FileLocatorInterface
* [
* 'search' => [$path => $foundPaths],
* ]
*
* @var array<string, array<string, mixed>>
*/
private array $cache = [];

Expand Down Expand Up @@ -114,6 +116,9 @@ public function getClassname(string $file): string
return $classname;
}

/**
* @return list<string>
*/
public function search(string $path, string $ext = 'php', bool $prioritizeApp = true): array
{
if (isset($this->cache['search'][$path][$ext][$prioritizeApp])) {
Expand Down
2 changes: 2 additions & 0 deletions system/Autoloader/FileLocatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function getClassname(string $file): string;
* 'app/Modules/foo/Config/Routes.php',
* 'app/Modules/bar/Config/Routes.php',
* ]
*
* @return list<string>
*/
public function search(string $path, string $ext = 'php', bool $prioritizeApp = true): array;

Expand Down
17 changes: 7 additions & 10 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use CodeIgniter\Pager\Pager;
use CodeIgniter\Validation\ValidationInterface;
use Config\Feature;
use Config\Services;
use InvalidArgumentException;
use ReflectionClass;
use ReflectionException;
Expand All @@ -47,7 +46,7 @@
* - process various callbacks
* - allow intermingling calls to the db connection
*
* @phpstan-type row_array array<int|string, float|int|null|object|string>
* @phpstan-type row_array array<int|string, float|int|null|object|string|bool>
* @phpstan-type event_data_beforeinsert array{data: row_array}
* @phpstan-type event_data_afterinsert array{id: int|string, data: row_array, result: bool}
* @phpstan-type event_data_beforefind array{id?: int|string, method: string, singleton: bool, limit?: int, offset?: int}
Expand Down Expand Up @@ -571,8 +570,8 @@ abstract public function countAllResults(bool $reset = true, bool $test = false)
* Loops over records in batches, allowing you to operate on them.
* This method works only with dbCalls.
*
* @param int $size Size
* @param Closure $userFunc Callback Function
* @param int $size Size
* @param Closure(array<string, string>|object): mixed $userFunc Callback Function
*
* @return void
*
Expand Down Expand Up @@ -640,7 +639,7 @@ public function findColumn(string $columnName)

$resultSet = $this->doFindColumn($columnName);

return $resultSet ? array_column($resultSet, $columnName) : null;
return $resultSet !== null ? array_column($resultSet, $columnName) : null;
}

/**
Expand Down Expand Up @@ -1138,7 +1137,7 @@ public function delete($id = null, bool $purge = false)
throw new InvalidArgumentException('delete(): argument #1 ($id) should not be boolean.');
}

if ($id && (is_numeric($id) || is_string($id))) {
if (! in_array($id, [null, 0, '0'], true) && (is_numeric($id) || is_string($id))) {
$id = [$id];
}

Expand Down Expand Up @@ -1251,7 +1250,7 @@ public function errors(bool $forceDB = false)
}

// Do we have validation errors?
if (! $forceDB && ! $this->skipValidation && ($errors = $this->validation->getErrors())) {
if (! $forceDB && ! $this->skipValidation && ($errors = $this->validation->getErrors()) !== []) {
return $errors;
}

Expand Down Expand Up @@ -1609,7 +1608,7 @@ public function getValidationRules(array $options = []): array
protected function ensureValidation(): void
{
if ($this->validation === null) {
$this->validation = Services::validation(null, false);
$this->validation = service('validation', null, false);
}
}

Expand Down Expand Up @@ -1800,8 +1799,6 @@ protected function objectToRawArray($object, bool $onlyChanged = true, bool $rec
// Loop over each property,
// saving the name/value in a new array we can return.
foreach ($props as $prop) {
// Must make protected values accessible.
$prop->setAccessible(true);
$properties[$prop->getName()] = $prop->getValue($object);
}
}
Expand Down
19 changes: 14 additions & 5 deletions system/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,16 @@ protected static function definePathConstants(Paths $paths): void

// The path to the writable directory.
if (! defined('WRITEPATH')) {
define('WRITEPATH', realpath(rtrim($paths->writableDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
$writePath = realpath(rtrim($paths->writableDirectory, '\\/ '));

if ($writePath === false) {
header('HTTP/1.1 503 Service Unavailable.', true, 503);
echo 'The WRITEPATH is not set correctly.';

// EXIT_ERROR is not yet defined
exit(1);
}
define('WRITEPATH', $writePath . DIRECTORY_SEPARATOR);
}

// The path to the tests directory
Expand Down Expand Up @@ -246,12 +255,12 @@ protected static function loadAutoloader(): void

protected static function autoloadHelpers(): void
{
Services::autoloader()->loadHelpers();
service('autoloader')->loadHelpers();
}

protected static function setExceptionHandler(): void
{
Services::exceptions()->initialize();
service('exceptions')->initialize();
}

protected static function checkMissingExtensions(): void
Expand Down Expand Up @@ -290,7 +299,7 @@ protected static function checkMissingExtensions(): void

protected static function initializeKint(): void
{
Services::autoloader()->initializeKint(CI_DEBUG);
service('autoloader')->initializeKint(CI_DEBUG);
}

protected static function loadConfigCache(): FactoriesCache
Expand All @@ -308,7 +317,7 @@ protected static function loadConfigCache(): FactoriesCache
*/
protected static function initializeCodeIgniter(): CodeIgniter
{
$app = Config\Services::codeigniter();
$app = service('codeigniter');
$app->initialize();
$context = is_cli() ? 'php-cli' : 'web';
$app->setContext($context);
Expand Down
Loading

0 comments on commit 7822476

Please sign in to comment.