Skip to content

Commit

Permalink
Release v4.2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 31, 2022
1 parent 011ce3b commit 3a6ea4c
Show file tree
Hide file tree
Showing 53 changed files with 403 additions and 295 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
2 changes: 1 addition & 1 deletion app/Config/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Config;

use CodeIgniter\Log\Handlers\FileHandler;
use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Log\Handlers\FileHandler;

class Logger extends BaseConfig
{
Expand Down
4 changes: 2 additions & 2 deletions app/Views/errors/html/error_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@

<?php endif; ?>

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

<h3>Headers</h3>
Expand Down Expand Up @@ -318,7 +318,7 @@
</tr>
</table>

<?php $headers = $response->getHeaders(); ?>
<?php $headers = $response->headers(); ?>
<?php if (! empty($headers)) : ?>
<?php natsort($headers) ?>

Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
"require-dev": {
"codeigniter/coding-standard": "^1.5",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "~3.11.0",
"friendsofphp/php-cs-fixer": "~3.12.0",
"mikey179/vfsstream": "^1.6",
"nexusphp/cs-config": "^3.6",
"phpunit/phpunit": "^9.1",
"predis/predis": "^1.1 || ^2.0"
},
"suggest": {
"ext-imagick": "If you use Image class ImageMagickHandler",
"ext-gd": "If you use Image class GDHandler",
"ext-exif": "If you run Image class tests",
"ext-simplexml": "If you format XML",
"ext-mysqli": "If you use MySQL",
"ext-oci8": "If you use Oracle Database",
Expand All @@ -34,6 +36,8 @@
"ext-memcache": "If you use Cache class MemcachedHandler with Memcache",
"ext-memcached": "If you use Cache class MemcachedHandler with Memcached",
"ext-redis": "If you use Cache class RedisHandler",
"ext-dom": "If you use TestResponse",
"ext-libxml": "If you use TestResponse",
"ext-fileinfo": "Improves mime type detection for files",
"ext-readline": "Improves CLI::input() usability"
},
Expand Down
3 changes: 2 additions & 1 deletion system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ abstract class BaseModel
* should be instantiated.
*
* @var string
* @phpstan-var non-empty-string
*/
protected $DBGroup;

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

Expand Down
3 changes: 2 additions & 1 deletion system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ protected function showError(Throwable $e)
{
$exception = $e;
$message = $e->getMessage();
$config = config('Exceptions');

require APPPATH . 'Views/errors/cli/error_exception.php';
require $config->errorViewPath . '/cli/error_exception.php';
}

/**
Expand Down
39 changes: 35 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.7';
public const CI_VERSION = '4.2.8';

/**
* App startup time.
Expand Down Expand Up @@ -151,6 +151,11 @@ class CodeIgniter
*/
protected ?string $context = null;

/**
* Whether to return Response object or send response.
*/
protected bool $returnResponse = false;

/**
* Constructor.
*/
Expand Down Expand Up @@ -291,6 +296,8 @@ protected function initializeKint()
*/
public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false)
{
$this->returnResponse = $returnResponse;

if ($this->context === null) {
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`.');
}
Expand All @@ -309,6 +316,10 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
if ($this->request instanceof IncomingRequest && strtolower($this->request->getMethod()) === 'cli') {
$this->response->setStatusCode(405)->setBody('Method Not Allowed');

if ($this->returnResponse) {
return $this->response;
}

$this->sendResponse();

return;
Expand Down Expand Up @@ -345,13 +356,22 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
// If the route is a 'redirect' route, it throws
// the exception with the $to as the message
$this->response->redirect(base_url($e->getMessage()), 'auto', $e->getCode());

if ($this->returnResponse) {
return $this->response;
}

$this->sendResponse();

$this->callExit(EXIT_SUCCESS);

return;
} catch (PageNotFoundException $e) {
$this->display404errors($e);
$return = $this->display404errors($e);

if ($return instanceof ResponseInterface) {
return $return;
}
}
}

Expand Down Expand Up @@ -400,9 +420,13 @@ private function isWeb(): bool
*
* @throws PageNotFoundException
* @throws RedirectException
*
* @deprecated $returnResponse is deprecated.
*/
protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, bool $returnResponse = false)
{
$this->returnResponse = $returnResponse;

$routeFilter = $this->tryToRouteIt($routes);

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

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

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

unset($uri);

if (! $returnResponse) {
if (! $this->returnResponse) {
$this->sendResponse();
}

Expand Down Expand Up @@ -910,6 +935,8 @@ protected function runController($class)
/**
* Displays a 404 Page Not Found error. If set, will try to
* call the 404Override controller/method that was set in routing config.
*
* @return ResponseInterface|void
*/
protected function display404errors(PageNotFoundException $e)
{
Expand All @@ -934,6 +961,10 @@ protected function display404errors(PageNotFoundException $e)

$cacheConfig = new Cache();
$this->gatherOutput($cacheConfig, $returned);
if ($this->returnResponse) {
return $this->response;
}

$this->sendResponse();

return;
Expand Down
52 changes: 22 additions & 30 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ function command(string $command)
$args[] = stripcslashes($match[1]);
} else {
// @codeCoverageIgnoreStart
throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ...".', substr($command, $cursor, 10)));
throw new InvalidArgumentException(sprintf(
'Unable to parse input near "... %s ...".',
substr($command, $cursor, 10)
));
// @codeCoverageIgnoreEnd
}

Expand Down Expand Up @@ -357,12 +360,10 @@ function db_connect($db = null, bool $getShared = true)
*/
function dd(...$vars)
{
// @codeCoverageIgnoreStart
Kint::$aliases[] = 'dd';
Kint::dump(...$vars);

exit;
// @codeCoverageIgnoreEnd
}
}

Expand Down Expand Up @@ -414,10 +415,11 @@ function env(string $key, $default = null)
* If $data is an array, then it loops over it, escaping each
* 'value' of the key/value pairs.
*
* Valid context values: html, js, css, url, attr, raw
*
* @param array|string $data
* @param string $encoding
* @phpstan-param 'html'|'js'|'css'|'url'|'attr'|'raw' $context
* @param string|null $encoding Current encoding for escaping.
* If not UTF-8, we convert strings from this encoding
* pre-escaping and back to this encoding post-escaping.
*
* @return array|string
*
Expand All @@ -437,7 +439,7 @@ function esc($data, string $context = 'html', ?string $encoding = null)
// Provide a way to NOT escape data since
// this could be called automatically by
// the View library.
if (empty($context) || $context === 'raw') {
if ($context === 'raw') {
return $data;
}

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

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

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

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

if (ENVIRONMENT !== 'testing') {
// @codeCoverageIgnoreStart
exit();
// @codeCoverageIgnoreEnd
exit(); // @codeCoverageIgnore
}
}
}
Expand Down Expand Up @@ -782,7 +777,7 @@ function lang(string $line, array $args = [], ?string $locale = null)
* - info
* - debug
*
* @return mixed
* @return bool
*/
function log_message(string $level, string $message, array $context = [])
{
Expand All @@ -795,10 +790,7 @@ function log_message(string $level, string $message, array $context = [])
return $logger->log($level, $message, $context);
}

// @codeCoverageIgnoreStart
return Services::logger(true)
->log($level, $message, $context);
// @codeCoverageIgnoreEnd
return Services::logger(true)->log($level, $message, $context); // @codeCoverageIgnore
}
}

Expand All @@ -823,18 +815,17 @@ function model(string $name, bool $getShared = true, ?ConnectionInterface &$conn
* Provides access to "old input" that was set in the session
* during a redirect()->withInput().
*
* @param null $default
* @param bool|string $escape
* @param string|null $default
* @param false|string $escape
* @phpstan-param false|'attr'|'css'|'html'|'js'|'raw'|'url' $escape
*
* @return mixed|null
* @return array|string|null
*/
function old(string $key, $default = null, $escape = 'html')
{
// Ensure the session is loaded
if (session_status() === PHP_SESSION_NONE && ENVIRONMENT !== 'testing') {
// @codeCoverageIgnoreStart
session();
// @codeCoverageIgnoreEnd
session(); // @codeCoverageIgnore
}

$request = Services::request();
Expand Down Expand Up @@ -932,7 +923,8 @@ function route_to(string $method, ...$params)
*
* @param string $val
*
* @return mixed|Session|null
* @return array|bool|float|int|object|Session|string|null
* @phpstan-return ($val is null ? Session : array|bool|float|int|object|string|null)
*/
function session(?string $val = null)
{
Expand Down Expand Up @@ -1054,7 +1046,7 @@ function slash_item(string $item): ?string
* Helper function used to convert a string, array, or object
* of attributes to a string.
*
* @param mixed $attributes string, array, object
* @param array|object|string $attributes string, array, object that can be cast to array
*/
function stringify_attributes($attributes, bool $js = false): string
{
Expand Down
3 changes: 2 additions & 1 deletion system/Config/DotEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public function normaliseVariable(string $name, string $value = ''): array
$value = trim($value);

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

// Sanitize the value
$value = $this->sanitizeValue($value);
Expand Down
4 changes: 2 additions & 2 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ public function unionAll($union)
*/
protected function addUnionStatement($union, bool $all = false)
{
$this->QBUnion[] = "\n" . 'UNION '
$this->QBUnion[] = "\nUNION "
. ($all ? 'ALL ' : '')
. 'SELECT * FROM '
. $this->buildSubquery($union, true, 'uwrp' . (count($this->QBUnion) + 1));
Expand Down Expand Up @@ -2350,7 +2350,7 @@ public function getCompiledDelete(bool $reset = true): string
*
* @param mixed $where
*
* @return bool|string
* @return bool|string Returns a string if in test mode.
*
* @throws DatabaseException
*/
Expand Down
Loading

0 comments on commit 3a6ea4c

Please sign in to comment.