Skip to content

Commit dbc07dc

Browse files
committed
Release v4.6.2
1 parent d021b04 commit dbc07dc

File tree

109 files changed

+1149
-900
lines changed

Some content is hidden

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

109 files changed

+1149
-900
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ writable/uploads/*
6161
!writable/uploads/index.html
6262

6363
writable/debugbar/*
64-
!writable/debugbar/.gitkeep
64+
!writable/debugbar/index.html
6565

6666
php_errors.log
6767

app/Config/Cache.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Cache extends BaseConfig
7878
* Your file storage preferences can be specified below, if you are using
7979
* the File driver.
8080
*
81-
* @var array<string, int|string|null>
81+
* @var array{storePath?: string, mode?: int}
8282
*/
8383
public array $file = [
8484
'storePath' => WRITEPATH . 'cache/',
@@ -95,7 +95,7 @@ class Cache extends BaseConfig
9595
*
9696
* @see https://codeigniter.com/user_guide/libraries/caching.html#memcached
9797
*
98-
* @var array<string, bool|int|string>
98+
* @var array{host?: string, port?: int, weight?: int, raw?: bool}
9999
*/
100100
public array $memcached = [
101101
'host' => '127.0.0.1',
@@ -112,7 +112,7 @@ class Cache extends BaseConfig
112112
* Your Redis server can be specified below, if you are using
113113
* the Redis or Predis drivers.
114114
*
115-
* @var array<string, int|string|null>
115+
* @var array{host?: string, password?: string|null, port?: int, timeout?: int, database?: int}
116116
*/
117117
public array $redis = [
118118
'host' => '127.0.0.1',

app/Config/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Cookie extends BaseConfig
8585
* (empty string) means default SameSite attribute set by browsers (`Lax`)
8686
* will be set on cookies. If set to `None`, `$secure` must also be set.
8787
*
88-
* @phpstan-var 'None'|'Lax'|'Strict'|''
88+
* @var ''|'Lax'|'None'|'Strict'
8989
*/
9090
public string $samesite = 'Lax';
9191

app/Config/Logger.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CodeIgniter\Config\BaseConfig;
66
use CodeIgniter\Log\Handlers\FileHandler;
7+
use CodeIgniter\Log\Handlers\HandlerInterface;
78

89
class Logger extends BaseConfig
910
{
@@ -73,7 +74,7 @@ class Logger extends BaseConfig
7374
* Handlers are executed in the order defined in this array, starting with
7475
* the handler on top and continuing down.
7576
*
76-
* @var array<class-string, array<string, int|list<string>|string>>
77+
* @var array<class-string<HandlerInterface>, array<string, int|list<string>|string>>
7778
*/
7879
public array $handlers = [
7980
/*

app/Views/errors/html/error_exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<!-- Header -->
2525
<div class="header">
2626
<div class="environment">
27-
Displayed at <?= esc(date('H:i:sa')) ?> &mdash;
27+
Displayed at <?= esc(date('H:i:s')) ?> &mdash;
2828
PHP: <?= esc(PHP_VERSION) ?> &mdash;
2929
CodeIgniter: <?= esc(CodeIgniter::CI_VERSION) ?> --
3030
Environment: <?= ENVIRONMENT ?>

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"php": "^8.1",
1414
"ext-intl": "*",
1515
"ext-mbstring": "*",
16-
"laminas/laminas-escaper": "^2.14",
16+
"laminas/laminas-escaper": "^2.17",
1717
"psr/log": "^3.0"
1818
},
1919
"require-dev": {
@@ -24,7 +24,7 @@
2424
"mikey179/vfsstream": "^1.6.12",
2525
"nexusphp/cs-config": "^3.6",
2626
"phpunit/phpunit": "^10.5.16 || ^11.2",
27-
"predis/predis": "^1.1 || ^2.3"
27+
"predis/predis": "^3.0"
2828
},
2929
"suggest": {
3030
"ext-curl": "If you use CURLRequest class",

system/API/ResponseTrait.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@
1313

1414
namespace CodeIgniter\API;
1515

16+
use CodeIgniter\Format\Format;
1617
use CodeIgniter\Format\FormatterInterface;
1718
use CodeIgniter\HTTP\IncomingRequest;
19+
use CodeIgniter\HTTP\RequestInterface;
1820
use CodeIgniter\HTTP\ResponseInterface;
1921

2022
/**
2123
* Provides common, more readable, methods to provide
2224
* consistent HTTP responses under a variety of common
2325
* situations when working as an API.
2426
*
25-
* @property bool $stringAsHtml Whether to treat string data as HTML in JSON response.
26-
* Setting `true` is only for backward compatibility.
27+
* @property RequestInterface $request
28+
* @property ResponseInterface $response
29+
* @property bool $stringAsHtml Whether to treat string data as HTML in JSON response.
30+
* Setting `true` is only for backward compatibility.
2731
*/
2832
trait ResponseTrait
2933
{
@@ -69,8 +73,7 @@ trait ResponseTrait
6973
* Either 'json' or 'xml'. If null is set, it will be determined through
7074
* content negotiation.
7175
*
72-
* @var string|null
73-
* @phpstan-var 'html'|'json'|'xml'|null
76+
* @var 'html'|'json'|'xml'|null
7477
*/
7578
protected $format = 'json';
7679

@@ -85,7 +88,7 @@ trait ResponseTrait
8588
* Provides a single, simple method to return an API response, formatted
8689
* to match the requested format, with proper content-type and status code.
8790
*
88-
* @param array|string|null $data
91+
* @param array<string, mixed>|string|null $data
8992
*
9093
* @return ResponseInterface
9194
*/
@@ -119,9 +122,9 @@ protected function respond($data = null, ?int $status = null, string $message =
119122
/**
120123
* Used for generic failures that no custom methods exist for.
121124
*
122-
* @param array|string $messages
123-
* @param int $status HTTP status code
124-
* @param string|null $code Custom, API-specific, error code
125+
* @param list<string>|string $messages
126+
* @param int $status HTTP status code
127+
* @param string|null $code Custom, API-specific, error code
125128
*
126129
* @return ResponseInterface
127130
*/
@@ -147,7 +150,7 @@ protected function fail($messages, int $status = 400, ?string $code = null, stri
147150
/**
148151
* Used after successfully creating a new resource.
149152
*
150-
* @param array|string|null $data
153+
* @param array<string, mixed>|string|null $data
151154
*
152155
* @return ResponseInterface
153156
*/
@@ -159,7 +162,7 @@ protected function respondCreated($data = null, string $message = '')
159162
/**
160163
* Used after a resource has been successfully deleted.
161164
*
162-
* @param array|string|null $data
165+
* @param array<string, mixed>|string|null $data
163166
*
164167
* @return ResponseInterface
165168
*/
@@ -171,7 +174,7 @@ protected function respondDeleted($data = null, string $message = '')
171174
/**
172175
* Used after a resource has been successfully updated.
173176
*
174-
* @param array|string|null $data
177+
* @param array<string, mixed>|string|null $data
175178
*
176179
* @return ResponseInterface
177180
*/
@@ -288,15 +291,17 @@ protected function failServerError(string $description = 'Internal Server Error'
288291
* Handles formatting a response. Currently, makes some heavy assumptions
289292
* and needs updating! :)
290293
*
291-
* @param array|string|null $data
294+
* @param array<string, mixed>|string|null $data
292295
*
293296
* @return string|null
294297
*/
295298
protected function format($data = null)
296299
{
300+
/** @var Format $format */
297301
$format = service('format');
298302

299-
$mime = ($this->format === null) ? $format->getConfig()->supportedResponseFormats[0]
303+
$mime = $this->format === null
304+
? $format->getConfig()->supportedResponseFormats[0]
300305
: "application/{$this->format}";
301306

302307
// Determine correct response type through content negotiation if not explicitly declared
@@ -314,14 +319,10 @@ protected function format($data = null)
314319
$this->response->setContentType($mime);
315320

316321
// if we don't have a formatter, make one
317-
if (! isset($this->formatter)) {
318-
// if no formatter, use the default
319-
$this->formatter = $format->getFormatter($mime);
320-
}
322+
$this->formatter ??= $format->getFormatter($mime);
321323

322324
$asHtml = $this->stringAsHtml ?? false;
323325

324-
// Returns as HTML.
325326
if (
326327
($mime === 'application/json' && $asHtml && is_string($data))
327328
|| ($mime !== 'application/json' && is_string($data))
@@ -339,6 +340,7 @@ protected function format($data = null)
339340
if ($mime !== 'application/json') {
340341
// Recursively convert objects into associative arrays
341342
// Conversion not required for JSONFormatter
343+
/** @var array<string, mixed>|string|null $data */
342344
$data = json_decode(json_encode($data), true);
343345
}
344346

@@ -348,14 +350,13 @@ protected function format($data = null)
348350
/**
349351
* Sets the format the response should be in.
350352
*
351-
* @param string|null $format Response format
352-
* @phpstan-param 'json'|'xml' $format
353+
* @param 'json'|'xml' $format Response format
353354
*
354355
* @return $this
355356
*/
356357
protected function setResponseFormat(?string $format = null)
357358
{
358-
$this->format = ($format === null) ? null : strtolower($format);
359+
$this->format = $format === null ? null : strtolower($format);
359360

360361
return $this;
361362
}

system/Autoloader/Autoloader.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Config\Autoload;
2222
use Config\Kint as KintConfig;
2323
use Config\Modules;
24-
use Kint;
24+
use Kint\Kint;
2525
use Kint\Renderer\CliRenderer;
2626
use Kint\Renderer\RichRenderer;
2727

@@ -67,29 +67,29 @@ class Autoloader
6767
/**
6868
* Stores namespaces as key, and path as values.
6969
*
70-
* @var array<string, list<string>>
70+
* @var array<non-empty-string, list<non-empty-string>>
7171
*/
7272
protected $prefixes = [];
7373

7474
/**
7575
* Stores class name as key, and path as values.
7676
*
77-
* @var array<class-string, string>
77+
* @var array<class-string, non-empty-string>
7878
*/
7979
protected $classmap = [];
8080

8181
/**
8282
* Stores files as a list.
8383
*
84-
* @var list<string>
84+
* @var list<non-empty-string>
8585
*/
8686
protected $files = [];
8787

8888
/**
8989
* Stores helper list.
9090
* Always load the URL helper, it should be used in most apps.
9191
*
92-
* @var list<string>
92+
* @var list<non-empty-string>
9393
*/
9494
protected $helpers = ['url'];
9595

@@ -147,36 +147,35 @@ private function loadComposerAutoloader(Modules $modules): void
147147

148148
// Should we load through Composer's namespaces, also?
149149
if ($modules->discoverInComposer) {
150-
// @phpstan-ignore-next-line
151-
$this->loadComposerNamespaces($composer, $modules->composerPackages ?? []);
150+
$composerPackages = $modules->composerPackages;
151+
$this->loadComposerNamespaces($composer, $composerPackages ?? []);
152152
}
153153

154154
unset($composer);
155155
}
156156

157157
/**
158-
* Register the loader with the SPL autoloader stack.
158+
* Register the loader with the SPL autoloader stack
159+
* in the following order:
160+
*
161+
* 1. Classmap loader
162+
* 2. PSR-4 autoloader
163+
* 3. Non-class files
159164
*
160165
* @return void
161166
*/
162167
public function register()
163168
{
164-
// Register classmap loader for the files in our class map.
165169
spl_autoload_register($this->loadClassmap(...), true);
166-
167-
// Register the PSR-4 autoloader.
168170
spl_autoload_register($this->loadClass(...), true);
169171

170-
// Load our non-class files
171172
foreach ($this->files as $file) {
172173
$this->includeFile($file);
173174
}
174175
}
175176

176177
/**
177-
* Unregister autoloader.
178-
*
179-
* This method is for testing.
178+
* Unregisters the autoloader from the SPL autoload stack.
180179
*/
181180
public function unregister(): void
182181
{
@@ -187,7 +186,7 @@ public function unregister(): void
187186
/**
188187
* Registers namespaces with the autoloader.
189188
*
190-
* @param array<string, list<string>|string>|string $namespace
189+
* @param array<non-empty-string, list<non-empty-string>|non-empty-string>|non-empty-string $namespace
191190
*
192191
* @return $this
193192
*/
@@ -219,8 +218,7 @@ public function addNamespace($namespace, ?string $path = null)
219218
*
220219
* If a prefix param is set, returns only paths to the given prefix.
221220
*
222-
* @return array<string, list<string>>|list<string>
223-
* @phpstan-return ($prefix is null ? array<string, list<string>> : list<string>)
221+
* @return ($prefix is null ? array<non-empty-string, list<non-empty-string>> : list<non-empty-string>)
224222
*/
225223
public function getNamespace(?string $prefix = null)
226224
{
@@ -248,6 +246,8 @@ public function removeNamespace(string $namespace)
248246
/**
249247
* Load a class using available class mapping.
250248
*
249+
* @param class-string $class The fully qualified class name.
250+
*
251251
* @internal For `spl_autoload_register` use.
252252
*/
253253
public function loadClassmap(string $class): void
@@ -262,9 +262,9 @@ public function loadClassmap(string $class): void
262262
/**
263263
* Loads the class file for a given class name.
264264
*
265-
* @internal For `spl_autoload_register` use.
265+
* @param class-string $class The fully qualified class name.
266266
*
267-
* @param string $class The fully qualified class name.
267+
* @internal For `spl_autoload_register` use.
268268
*/
269269
public function loadClass(string $class): void
270270
{
@@ -274,9 +274,9 @@ public function loadClass(string $class): void
274274
/**
275275
* Loads the class file for a given class name.
276276
*
277-
* @param string $class The fully-qualified class name
277+
* @param class-string $class The fully qualified class name.
278278
*
279-
* @return false|string The mapped file name on success, or boolean false on fail
279+
* @return false|non-empty-string The mapped file name on success, or boolean false on fail
280280
*/
281281
protected function loadInNamespace(string $class)
282282
{
@@ -294,21 +294,20 @@ protected function loadInNamespace(string $class)
294294
$filePath = $directory . $relativeClassPath . '.php';
295295
$filename = $this->includeFile($filePath);
296296

297-
if ($filename) {
297+
if ($filename !== false) {
298298
return $filename;
299299
}
300300
}
301301
}
302302
}
303303

304-
// never found a mapped file
305304
return false;
306305
}
307306

308307
/**
309308
* A central way to include a file. Split out primarily for testing purposes.
310309
*
311-
* @return false|string The filename on success, false if the file is not loaded
310+
* @return false|non-empty-string The filename on success, false if the file is not loaded
312311
*/
313312
protected function includeFile(string $file)
314313
{

0 commit comments

Comments
 (0)