Skip to content

Commit 3a6ea4c

Browse files
committed
Release v4.2.8
1 parent 011ce3b commit 3a6ea4c

Some content is hidden

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

53 files changed

+403
-295
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.github export-ignore
2+
/.gitattributes export-ignore
3+
/.gitignore export-ignore

app/Config/Logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Config;
44

5-
use CodeIgniter\Log\Handlers\FileHandler;
65
use CodeIgniter\Config\BaseConfig;
6+
use CodeIgniter\Log\Handlers\FileHandler;
77

88
class Logger extends BaseConfig
99
{

app/Views/errors/html/error_exception.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270

271271
<?php endif; ?>
272272

273-
<?php $headers = $request->getHeaders(); ?>
273+
<?php $headers = $request->headers(); ?>
274274
<?php if (! empty($headers)) : ?>
275275

276276
<h3>Headers</h3>
@@ -318,7 +318,7 @@
318318
</tr>
319319
</table>
320320

321-
<?php $headers = $response->getHeaders(); ?>
321+
<?php $headers = $response->headers(); ?>
322322
<?php if (! empty($headers)) : ?>
323323
<?php natsort($headers) ?>
324324

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
"require-dev": {
1818
"codeigniter/coding-standard": "^1.5",
1919
"fakerphp/faker": "^1.9",
20-
"friendsofphp/php-cs-fixer": "~3.11.0",
20+
"friendsofphp/php-cs-fixer": "~3.12.0",
2121
"mikey179/vfsstream": "^1.6",
2222
"nexusphp/cs-config": "^3.6",
2323
"phpunit/phpunit": "^9.1",
2424
"predis/predis": "^1.1 || ^2.0"
2525
},
2626
"suggest": {
2727
"ext-imagick": "If you use Image class ImageMagickHandler",
28+
"ext-gd": "If you use Image class GDHandler",
29+
"ext-exif": "If you run Image class tests",
2830
"ext-simplexml": "If you format XML",
2931
"ext-mysqli": "If you use MySQL",
3032
"ext-oci8": "If you use Oracle Database",
@@ -34,6 +36,8 @@
3436
"ext-memcache": "If you use Cache class MemcachedHandler with Memcache",
3537
"ext-memcached": "If you use Cache class MemcachedHandler with Memcached",
3638
"ext-redis": "If you use Cache class RedisHandler",
39+
"ext-dom": "If you use TestResponse",
40+
"ext-libxml": "If you use TestResponse",
3741
"ext-fileinfo": "Improves mime type detection for files",
3842
"ext-readline": "Improves CLI::input() usability"
3943
},

system/BaseModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ abstract class BaseModel
6464
* should be instantiated.
6565
*
6666
* @var string
67+
* @phpstan-var non-empty-string
6768
*/
6869
protected $DBGroup;
6970

@@ -416,7 +417,7 @@ abstract protected function doDelete($id = null, bool $purge = false);
416417
* through soft deletes (deleted = 1)
417418
* This methods works only with dbCalls
418419
*
419-
* @return bool|mixed
420+
* @return bool|string Returns a string if in test mode.
420421
*/
421422
abstract protected function doPurgeDeleted();
422423

system/CLI/BaseCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ protected function showError(Throwable $e)
119119
{
120120
$exception = $e;
121121
$message = $e->getMessage();
122+
$config = config('Exceptions');
122123

123-
require APPPATH . 'Views/errors/cli/error_exception.php';
124+
require $config->errorViewPath . '/cli/error_exception.php';
124125
}
125126

126127
/**

system/CodeIgniter.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CodeIgniter
4747
/**
4848
* The current version of CodeIgniter Framework
4949
*/
50-
public const CI_VERSION = '4.2.7';
50+
public const CI_VERSION = '4.2.8';
5151

5252
/**
5353
* App startup time.
@@ -151,6 +151,11 @@ class CodeIgniter
151151
*/
152152
protected ?string $context = null;
153153

154+
/**
155+
* Whether to return Response object or send response.
156+
*/
157+
protected bool $returnResponse = false;
158+
154159
/**
155160
* Constructor.
156161
*/
@@ -291,6 +296,8 @@ protected function initializeKint()
291296
*/
292297
public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false)
293298
{
299+
$this->returnResponse = $returnResponse;
300+
294301
if ($this->context === null) {
295302
throw new LogicException('Context must be set before run() is called. If you are upgrading from 4.1.x, you need to merge `public/index.php` and `spark` file from `vendor/codeigniter4/framework`.');
296303
}
@@ -309,6 +316,10 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
309316
if ($this->request instanceof IncomingRequest && strtolower($this->request->getMethod()) === 'cli') {
310317
$this->response->setStatusCode(405)->setBody('Method Not Allowed');
311318

319+
if ($this->returnResponse) {
320+
return $this->response;
321+
}
322+
312323
$this->sendResponse();
313324

314325
return;
@@ -345,13 +356,22 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
345356
// If the route is a 'redirect' route, it throws
346357
// the exception with the $to as the message
347358
$this->response->redirect(base_url($e->getMessage()), 'auto', $e->getCode());
359+
360+
if ($this->returnResponse) {
361+
return $this->response;
362+
}
363+
348364
$this->sendResponse();
349365

350366
$this->callExit(EXIT_SUCCESS);
351367

352368
return;
353369
} catch (PageNotFoundException $e) {
354-
$this->display404errors($e);
370+
$return = $this->display404errors($e);
371+
372+
if ($return instanceof ResponseInterface) {
373+
return $return;
374+
}
355375
}
356376
}
357377

@@ -400,9 +420,13 @@ private function isWeb(): bool
400420
*
401421
* @throws PageNotFoundException
402422
* @throws RedirectException
423+
*
424+
* @deprecated $returnResponse is deprecated.
403425
*/
404426
protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, bool $returnResponse = false)
405427
{
428+
$this->returnResponse = $returnResponse;
429+
406430
$routeFilter = $this->tryToRouteIt($routes);
407431

408432
$uri = $this->determinePath();
@@ -433,7 +457,8 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
433457

434458
// If a ResponseInterface instance is returned then send it back to the client and stop
435459
if ($possibleResponse instanceof ResponseInterface) {
436-
return $returnResponse ? $possibleResponse : $possibleResponse->pretend($this->useSafeOutput)->send();
460+
return $this->returnResponse ? $possibleResponse
461+
: $possibleResponse->pretend($this->useSafeOutput)->send();
437462
}
438463

439464
if ($possibleResponse instanceof Request) {
@@ -512,7 +537,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
512537

513538
unset($uri);
514539

515-
if (! $returnResponse) {
540+
if (! $this->returnResponse) {
516541
$this->sendResponse();
517542
}
518543

@@ -910,6 +935,8 @@ protected function runController($class)
910935
/**
911936
* Displays a 404 Page Not Found error. If set, will try to
912937
* call the 404Override controller/method that was set in routing config.
938+
*
939+
* @return ResponseInterface|void
913940
*/
914941
protected function display404errors(PageNotFoundException $e)
915942
{
@@ -934,6 +961,10 @@ protected function display404errors(PageNotFoundException $e)
934961

935962
$cacheConfig = new Cache();
936963
$this->gatherOutput($cacheConfig, $returned);
964+
if ($this->returnResponse) {
965+
return $this->response;
966+
}
967+
937968
$this->sendResponse();
938969

939970
return;

system/Common.php

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ function command(string $command)
145145
$args[] = stripcslashes($match[1]);
146146
} else {
147147
// @codeCoverageIgnoreStart
148-
throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ...".', substr($command, $cursor, 10)));
148+
throw new InvalidArgumentException(sprintf(
149+
'Unable to parse input near "... %s ...".',
150+
substr($command, $cursor, 10)
151+
));
149152
// @codeCoverageIgnoreEnd
150153
}
151154

@@ -357,12 +360,10 @@ function db_connect($db = null, bool $getShared = true)
357360
*/
358361
function dd(...$vars)
359362
{
360-
// @codeCoverageIgnoreStart
361363
Kint::$aliases[] = 'dd';
362364
Kint::dump(...$vars);
363365

364366
exit;
365-
// @codeCoverageIgnoreEnd
366367
}
367368
}
368369

@@ -414,10 +415,11 @@ function env(string $key, $default = null)
414415
* If $data is an array, then it loops over it, escaping each
415416
* 'value' of the key/value pairs.
416417
*
417-
* Valid context values: html, js, css, url, attr, raw
418-
*
419418
* @param array|string $data
420-
* @param string $encoding
419+
* @phpstan-param 'html'|'js'|'css'|'url'|'attr'|'raw' $context
420+
* @param string|null $encoding Current encoding for escaping.
421+
* If not UTF-8, we convert strings from this encoding
422+
* pre-escaping and back to this encoding post-escaping.
421423
*
422424
* @return array|string
423425
*
@@ -437,7 +439,7 @@ function esc($data, string $context = 'html', ?string $encoding = null)
437439
// Provide a way to NOT escape data since
438440
// this could be called automatically by
439441
// the View library.
440-
if (empty($context) || $context === 'raw') {
442+
if ($context === 'raw') {
441443
return $data;
442444
}
443445

@@ -493,18 +495,13 @@ function force_https(int $duration = 31_536_000, ?RequestInterface $request = nu
493495
}
494496

495497
if ((ENVIRONMENT !== 'testing' && (is_cli() || $request->isSecure())) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'test')) {
496-
// @codeCoverageIgnoreStart
497-
return;
498-
// @codeCoverageIgnoreEnd
498+
return; // @codeCoverageIgnore
499499
}
500500

501501
// If the session status is active, we should regenerate
502502
// the session ID for safety sake.
503503
if (ENVIRONMENT !== 'testing' && session_status() === PHP_SESSION_ACTIVE) {
504-
// @codeCoverageIgnoreStart
505-
Services::session(null, true)
506-
->regenerate();
507-
// @codeCoverageIgnoreEnd
504+
Services::session(null, true)->regenerate(); // @codeCoverageIgnore
508505
}
509506

510507
$baseURL = config(App::class)->baseURL;
@@ -529,9 +526,7 @@ function force_https(int $duration = 31_536_000, ?RequestInterface $request = nu
529526
$response->sendHeaders();
530527

531528
if (ENVIRONMENT !== 'testing') {
532-
// @codeCoverageIgnoreStart
533-
exit();
534-
// @codeCoverageIgnoreEnd
529+
exit(); // @codeCoverageIgnore
535530
}
536531
}
537532
}
@@ -782,7 +777,7 @@ function lang(string $line, array $args = [], ?string $locale = null)
782777
* - info
783778
* - debug
784779
*
785-
* @return mixed
780+
* @return bool
786781
*/
787782
function log_message(string $level, string $message, array $context = [])
788783
{
@@ -795,10 +790,7 @@ function log_message(string $level, string $message, array $context = [])
795790
return $logger->log($level, $message, $context);
796791
}
797792

798-
// @codeCoverageIgnoreStart
799-
return Services::logger(true)
800-
->log($level, $message, $context);
801-
// @codeCoverageIgnoreEnd
793+
return Services::logger(true)->log($level, $message, $context); // @codeCoverageIgnore
802794
}
803795
}
804796

@@ -823,18 +815,17 @@ function model(string $name, bool $getShared = true, ?ConnectionInterface &$conn
823815
* Provides access to "old input" that was set in the session
824816
* during a redirect()->withInput().
825817
*
826-
* @param null $default
827-
* @param bool|string $escape
818+
* @param string|null $default
819+
* @param false|string $escape
820+
* @phpstan-param false|'attr'|'css'|'html'|'js'|'raw'|'url' $escape
828821
*
829-
* @return mixed|null
822+
* @return array|string|null
830823
*/
831824
function old(string $key, $default = null, $escape = 'html')
832825
{
833826
// Ensure the session is loaded
834827
if (session_status() === PHP_SESSION_NONE && ENVIRONMENT !== 'testing') {
835-
// @codeCoverageIgnoreStart
836-
session();
837-
// @codeCoverageIgnoreEnd
828+
session(); // @codeCoverageIgnore
838829
}
839830

840831
$request = Services::request();
@@ -932,7 +923,8 @@ function route_to(string $method, ...$params)
932923
*
933924
* @param string $val
934925
*
935-
* @return mixed|Session|null
926+
* @return array|bool|float|int|object|Session|string|null
927+
* @phpstan-return ($val is null ? Session : array|bool|float|int|object|string|null)
936928
*/
937929
function session(?string $val = null)
938930
{
@@ -1054,7 +1046,7 @@ function slash_item(string $item): ?string
10541046
* Helper function used to convert a string, array, or object
10551047
* of attributes to a string.
10561048
*
1057-
* @param mixed $attributes string, array, object
1049+
* @param array|object|string $attributes string, array, object that can be cast to array
10581050
*/
10591051
function stringify_attributes($attributes, bool $js = false): string
10601052
{

system/Config/DotEnv.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public function normaliseVariable(string $name, string $value = ''): array
116116
$value = trim($value);
117117

118118
// Sanitize the name
119-
$name = str_replace(['export', '\'', '"'], '', $name);
119+
$name = preg_replace('/^export[ \t]++(\S+)/', '$1', $name);
120+
$name = str_replace(['\'', '"'], '', $name);
120121

121122
// Sanitize the value
122123
$value = $this->sanitizeValue($value);

system/Database/BaseBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ public function unionAll($union)
11791179
*/
11801180
protected function addUnionStatement($union, bool $all = false)
11811181
{
1182-
$this->QBUnion[] = "\n" . 'UNION '
1182+
$this->QBUnion[] = "\nUNION "
11831183
. ($all ? 'ALL ' : '')
11841184
. 'SELECT * FROM '
11851185
. $this->buildSubquery($union, true, 'uwrp' . (count($this->QBUnion) + 1));
@@ -2350,7 +2350,7 @@ public function getCompiledDelete(bool $reset = true): string
23502350
*
23512351
* @param mixed $where
23522352
*
2353-
* @return bool|string
2353+
* @return bool|string Returns a string if in test mode.
23542354
*
23552355
* @throws DatabaseException
23562356
*/

0 commit comments

Comments
 (0)