Skip to content

Commit 7822476

Browse files
committed
Release v4.5.6
1 parent 2849e7f commit 7822476

File tree

134 files changed

+637
-530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+637
-530
lines changed

app/Config/Events.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
*/
4545
if (CI_DEBUG && ! is_cli()) {
4646
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
47-
Services::toolbar()->respond();
47+
service('toolbar')->respond();
4848
// Hot Reload route - for framework use on the hot reloader.
4949
if (ENVIRONMENT === 'development') {
50-
Services::routes()->get('__hot-reload', static function (): void {
50+
service('routes')->get('__hot-reload', static function (): void {
5151
(new HotReloader())->run();
5252
});
5353
}

app/Config/Format.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ class Format extends BaseConfig
7272
*/
7373
public function getFormatter(string $mime)
7474
{
75-
return Services::format()->getFormatter($mime);
75+
return service('format')->getFormatter($mime);
7676
}
7777
}

app/Controllers/BaseController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ public function initController(RequestInterface $request, ResponseInterface $res
5353

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

56-
// E.g.: $this->session = \Config\Services::session();
56+
// E.g.: $this->session = service('session');
5757
}
5858
}

app/Views/errors/cli/error_exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
$args = implode(', ', array_map(static fn ($value) => match (true) {
5454
is_object($value) => 'Object(' . $value::class . ')',
55-
is_array($value) => count($value) ? '[...]' : '[]',
55+
is_array($value) => $value !== [] ? '[...]' : '[]',
5656
$value === null => 'null', // return the lowercased version
5757
default => var_export($value, true),
5858
}, array_values($error['args'] ?? [])));

app/Views/errors/html/error_exception.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
use CodeIgniter\HTTP\Header;
3-
use Config\Services;
43
use CodeIgniter\CodeIgniter;
54

65
$errorId = uniqid('error', true);
@@ -225,7 +224,7 @@
225224

226225
<!-- Request -->
227226
<div class="content" id="request">
228-
<?php $request = Services::request(); ?>
227+
<?php $request = service('request'); ?>
229228

230229
<table>
231230
<tbody>
@@ -343,7 +342,7 @@
343342

344343
<!-- Response -->
345344
<?php
346-
$response = Services::response();
345+
$response = service('response');
347346
$response->setStatusCode(http_response_code());
348347
?>
349348
<div class="content" id="response">

system/Autoloader/Autoloader.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Config\Autoload;
2020
use Config\Kint as KintConfig;
2121
use Config\Modules;
22-
use Config\Services;
2322
use InvalidArgumentException;
2423
use Kint;
2524
use Kint\Renderer\CliRenderer;
@@ -367,6 +366,9 @@ public function sanitizeFilename(string $filename): string
367366
return $cleanFilename;
368367
}
369368

369+
/**
370+
* @param array{only?: list<string>, exclude?: list<string>} $composerPackages
371+
*/
370372
private function loadComposerNamespaces(ClassLoader $composer, array $composerPackages): void
371373
{
372374
$namespacePaths = $composer->getPrefixesPsr4();
@@ -380,7 +382,7 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa
380382
}
381383
}
382384

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

540-
$csp = Services::csp();
542+
$csp = service('csp');
541543
if ($csp->enabled()) {
542544
RichRenderer::$js_nonce = $csp->getScriptNonce();
543545
RichRenderer::$css_nonce = $csp->getStyleNonce();

system/Autoloader/FileLocator.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ public function getClassname(string $file): string
145145

146146
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)) {
147147
if (! $dlm) {
148-
$namespace = 0;
148+
$namespace = '';
149149
}
150+
150151
if (isset($token[1])) {
151-
$namespace = $namespace ? $namespace . '\\' . $token[1] : $token[1];
152+
$namespace = $namespace !== '' ? $namespace . '\\' . $token[1] : $token[1];
152153
$dlm = true;
153154
}
154155
} elseif ($dlm && ($token[0] !== T_NS_SEPARATOR) && ($token[0] !== T_STRING)) {
@@ -194,8 +195,9 @@ public function search(string $path, string $ext = 'php', bool $prioritizeApp =
194195

195196
foreach ($this->getNamespaces() as $namespace) {
196197
if (isset($namespace['path']) && is_file($namespace['path'] . $path)) {
197-
$fullPath = $namespace['path'] . $path;
198-
$fullPath = realpath($fullPath) ?: $fullPath;
198+
$fullPath = $namespace['path'] . $path;
199+
$resolvedPath = realpath($fullPath);
200+
$fullPath = $resolvedPath !== false ? $resolvedPath : $fullPath;
199201

200202
if ($prioritizeApp) {
201203
$foundPaths[] = $fullPath;
@@ -272,14 +274,16 @@ protected function getNamespaces()
272274
*/
273275
public function findQualifiedNameFromPath(string $path)
274276
{
275-
$path = realpath($path) ?: $path;
277+
$resolvedPath = realpath($path);
278+
$path = $resolvedPath !== false ? $resolvedPath : $path;
276279

277280
if (! is_file($path)) {
278281
return false;
279282
}
280283

281284
foreach ($this->getNamespaces() as $namespace) {
282-
$namespace['path'] = realpath($namespace['path']) ?: $namespace['path'];
285+
$resolvedNamespacePath = realpath($namespace['path']);
286+
$namespace['path'] = $resolvedNamespacePath !== false ? $resolvedNamespacePath : $namespace['path'];
283287

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

333337
foreach ($this->getNamespaces() as $namespace) {
334-
$fullPath = $namespace['path'] . $path;
335-
$fullPath = realpath($fullPath) ?: $fullPath;
338+
$fullPath = $namespace['path'] . $path;
339+
$resolvedPath = realpath($fullPath);
340+
$fullPath = $resolvedPath !== false ? $resolvedPath : $fullPath;
336341

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

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

371377
if (! is_dir($fullPath)) {
372378
continue;
@@ -392,8 +398,9 @@ public function listNamespaceFiles(string $prefix, string $path): array
392398
*/
393399
protected function legacyLocate(string $file, ?string $folder = null)
394400
{
395-
$path = APPPATH . ($folder === null ? $file : $folder . '/' . $file);
396-
$path = realpath($path) ?: $path;
401+
$path = APPPATH . ($folder === null ? $file : $folder . '/' . $file);
402+
$resolvedPath = realpath($path);
403+
$path = $resolvedPath !== false ? $resolvedPath : $path;
397404

398405
if (is_file($path)) {
399406
return $path;

system/Autoloader/FileLocatorCached.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ final class FileLocatorCached implements FileLocatorInterface
3636
* [
3737
* 'search' => [$path => $foundPaths],
3838
* ]
39+
*
40+
* @var array<string, array<string, mixed>>
3941
*/
4042
private array $cache = [];
4143

@@ -114,6 +116,9 @@ public function getClassname(string $file): string
114116
return $classname;
115117
}
116118

119+
/**
120+
* @return list<string>
121+
*/
117122
public function search(string $path, string $ext = 'php', bool $prioritizeApp = true): array
118123
{
119124
if (isset($this->cache['search'][$path][$ext][$prioritizeApp])) {

system/Autoloader/FileLocatorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public function getClassname(string $file): string;
5353
* 'app/Modules/foo/Config/Routes.php',
5454
* 'app/Modules/bar/Config/Routes.php',
5555
* ]
56+
*
57+
* @return list<string>
5658
*/
5759
public function search(string $path, string $ext = 'php', bool $prioritizeApp = true): array;
5860

system/BaseModel.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use CodeIgniter\Pager\Pager;
2727
use CodeIgniter\Validation\ValidationInterface;
2828
use Config\Feature;
29-
use Config\Services;
3029
use InvalidArgumentException;
3130
use ReflectionClass;
3231
use ReflectionException;
@@ -47,7 +46,7 @@
4746
* - process various callbacks
4847
* - allow intermingling calls to the db connection
4948
*
50-
* @phpstan-type row_array array<int|string, float|int|null|object|string>
49+
* @phpstan-type row_array array<int|string, float|int|null|object|string|bool>
5150
* @phpstan-type event_data_beforeinsert array{data: row_array}
5251
* @phpstan-type event_data_afterinsert array{id: int|string, data: row_array, result: bool}
5352
* @phpstan-type event_data_beforefind array{id?: int|string, method: string, singleton: bool, limit?: int, offset?: int}
@@ -571,8 +570,8 @@ abstract public function countAllResults(bool $reset = true, bool $test = false)
571570
* Loops over records in batches, allowing you to operate on them.
572571
* This method works only with dbCalls.
573572
*
574-
* @param int $size Size
575-
* @param Closure $userFunc Callback Function
573+
* @param int $size Size
574+
* @param Closure(array<string, string>|object): mixed $userFunc Callback Function
576575
*
577576
* @return void
578577
*
@@ -640,7 +639,7 @@ public function findColumn(string $columnName)
640639

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

643-
return $resultSet ? array_column($resultSet, $columnName) : null;
642+
return $resultSet !== null ? array_column($resultSet, $columnName) : null;
644643
}
645644

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

1141-
if ($id && (is_numeric($id) || is_string($id))) {
1140+
if (! in_array($id, [null, 0, '0'], true) && (is_numeric($id) || is_string($id))) {
11421141
$id = [$id];
11431142
}
11441143

@@ -1251,7 +1250,7 @@ public function errors(bool $forceDB = false)
12511250
}
12521251

12531252
// Do we have validation errors?
1254-
if (! $forceDB && ! $this->skipValidation && ($errors = $this->validation->getErrors())) {
1253+
if (! $forceDB && ! $this->skipValidation && ($errors = $this->validation->getErrors()) !== []) {
12551254
return $errors;
12561255
}
12571256

@@ -1609,7 +1608,7 @@ public function getValidationRules(array $options = []): array
16091608
protected function ensureValidation(): void
16101609
{
16111610
if ($this->validation === null) {
1612-
$this->validation = Services::validation(null, false);
1611+
$this->validation = service('validation', null, false);
16131612
}
16141613
}
16151614

@@ -1800,8 +1799,6 @@ protected function objectToRawArray($object, bool $onlyChanged = true, bool $rec
18001799
// Loop over each property,
18011800
// saving the name/value in a new array we can return.
18021801
foreach ($props as $prop) {
1803-
// Must make protected values accessible.
1804-
$prop->setAccessible(true);
18051802
$properties[$prop->getName()] = $prop->getValue($object);
18061803
}
18071804
}

system/Boot.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,16 @@ protected static function definePathConstants(Paths $paths): void
196196

197197
// The path to the writable directory.
198198
if (! defined('WRITEPATH')) {
199-
define('WRITEPATH', realpath(rtrim($paths->writableDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
199+
$writePath = realpath(rtrim($paths->writableDirectory, '\\/ '));
200+
201+
if ($writePath === false) {
202+
header('HTTP/1.1 503 Service Unavailable.', true, 503);
203+
echo 'The WRITEPATH is not set correctly.';
204+
205+
// EXIT_ERROR is not yet defined
206+
exit(1);
207+
}
208+
define('WRITEPATH', $writePath . DIRECTORY_SEPARATOR);
200209
}
201210

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

247256
protected static function autoloadHelpers(): void
248257
{
249-
Services::autoloader()->loadHelpers();
258+
service('autoloader')->loadHelpers();
250259
}
251260

252261
protected static function setExceptionHandler(): void
253262
{
254-
Services::exceptions()->initialize();
263+
service('exceptions')->initialize();
255264
}
256265

257266
protected static function checkMissingExtensions(): void
@@ -290,7 +299,7 @@ protected static function checkMissingExtensions(): void
290299

291300
protected static function initializeKint(): void
292301
{
293-
Services::autoloader()->initializeKint(CI_DEBUG);
302+
service('autoloader')->initializeKint(CI_DEBUG);
294303
}
295304

296305
protected static function loadConfigCache(): FactoriesCache
@@ -308,7 +317,7 @@ protected static function loadConfigCache(): FactoriesCache
308317
*/
309318
protected static function initializeCodeIgniter(): CodeIgniter
310319
{
311-
$app = Config\Services::codeigniter();
320+
$app = service('codeigniter');
312321
$app->initialize();
313322
$context = is_cli() ? 'php-cli' : 'web';
314323
$app->setContext($context);

0 commit comments

Comments
 (0)