Skip to content

Commit 5b34d72

Browse files
committed
Release v4.1.6
1 parent 27eb447 commit 5b34d72

File tree

177 files changed

+2853
-1428
lines changed

Some content is hidden

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

177 files changed

+2853
-1428
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The MIT License (MIT)
22

33
Copyright (c) 2014-2019 British Columbia Institute of Technology
4-
Copyright (c) 2019-2021 CodeIgniter Foundation
4+
Copyright (c) 2019-2022 CodeIgniter Foundation
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal

app/Config/Filters.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use CodeIgniter\Filters\CSRF;
77
use CodeIgniter\Filters\DebugToolbar;
88
use CodeIgniter\Filters\Honeypot;
9+
use CodeIgniter\Filters\InvalidChars;
10+
use CodeIgniter\Filters\SecureHeaders;
911

1012
class Filters extends BaseConfig
1113
{
@@ -16,9 +18,11 @@ class Filters extends BaseConfig
1618
* @var array
1719
*/
1820
public $aliases = [
19-
'csrf' => CSRF::class,
20-
'toolbar' => DebugToolbar::class,
21-
'honeypot' => Honeypot::class,
21+
'csrf' => CSRF::class,
22+
'toolbar' => DebugToolbar::class,
23+
'honeypot' => Honeypot::class,
24+
'invalidchars' => InvalidChars::class,
25+
'secureheaders' => SecureHeaders::class,
2226
];
2327

2428
/**
@@ -31,10 +35,12 @@ class Filters extends BaseConfig
3135
'before' => [
3236
// 'honeypot',
3337
// 'csrf',
38+
// 'invalidchars',
3439
],
3540
'after' => [
3641
'toolbar',
3742
// 'honeypot',
43+
// 'secureheaders',
3844
],
3945
];
4046

app/Config/Mimes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ public static function guessExtensionFromType(string $type, ?string $proposedExt
509509
{
510510
$type = trim(strtolower($type), '. ');
511511

512-
$proposedExtension = trim(strtolower($proposedExtension));
512+
$proposedExtension = trim(strtolower($proposedExtension ?? ''));
513513

514514
if ($proposedExtension !== '') {
515515
if (array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true)) {

app/Config/Security.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ class Security extends BaseConfig
1717
*/
1818
public $csrfProtection = 'cookie';
1919

20+
/**
21+
* --------------------------------------------------------------------------
22+
* CSRF Token Randomization
23+
* --------------------------------------------------------------------------
24+
*
25+
* Randomize the CSRF Token for added security.
26+
*
27+
* @var bool
28+
*/
29+
public $tokenRandomize = false;
30+
2031
/**
2132
* --------------------------------------------------------------------------
2233
* CSRF Token Name

app/Config/Toolbar.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ class Toolbar extends BaseConfig
4444
Events::class,
4545
];
4646

47+
/**
48+
* --------------------------------------------------------------------------
49+
* Collect Var Data
50+
* --------------------------------------------------------------------------
51+
*
52+
* If set to false var data from the views will not be colleted. Usefull to
53+
* avoid high memory usage when there are lots of data passed to the view.
54+
*
55+
* @var bool
56+
*/
57+
public $collectVarData = true;
58+
4759
/**
4860
* --------------------------------------------------------------------------
4961
* Max History

app/Views/errors/html/error_exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
<tbody>
196196
<tr>
197197
<td style="width: 10em">Path</td>
198-
<td><?= esc($request->uri) ?></td>
198+
<td><?= esc($request->getUri()) ?></td>
199199
</tr>
200200
<tr>
201201
<td>HTTP Method</td>

env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#--------------------------------------------------------------------
112112

113113
# security.csrfProtection = 'cookie'
114+
# security.tokenRandomize = false
114115
# security.tokenName = 'csrf_token_name'
115116
# security.headerName = 'X-CSRF-TOKEN'
116117
# security.cookieName = 'csrf_cookie_name'

system/Autoloader/Autoloader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ public function initialize(Autoload $config, Modules $modules)
114114
public function register()
115115
{
116116
// Prepend the PSR4 autoloader for maximum performance.
117-
spl_autoload_register([$this, 'loadClass'], true, true); // @phpstan-ignore-line
117+
spl_autoload_register([$this, 'loadClass'], true, true);
118118

119119
// Now prepend another loader for the files in our class map.
120-
spl_autoload_register([$this, 'loadClassmap'], true, true); // @phpstan-ignore-line
120+
spl_autoload_register([$this, 'loadClassmap'], true, true);
121121

122122
// Load our non-class files
123123
foreach ($this->files as $file) {

system/Autoloader/FileLocator.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
5555

5656
// Standardize slashes to handle nested directories.
5757
$file = strtr($file, '/', '\\');
58+
$file = ltrim($file, '\\');
5859

5960
$segments = explode('\\', $file);
6061

@@ -64,23 +65,20 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '
6465
}
6566

6667
$paths = [];
67-
$prefix = '';
6868
$filename = '';
6969

7070
// Namespaces always comes with arrays of paths
7171
$namespaces = $this->autoloader->getNamespace();
7272

73-
while (! empty($segments)) {
74-
$prefix .= empty($prefix) ? array_shift($segments) : '\\' . array_shift($segments);
73+
foreach (array_keys($namespaces) as $namespace) {
74+
if (substr($file, 0, strlen($namespace)) === $namespace) {
75+
// There may be sub-namespaces of the same vendor,
76+
// so overwrite them with namespaces found later.
77+
$paths = $namespaces[$namespace];
7578

76-
if (empty($namespaces[$prefix])) {
77-
continue;
79+
$fileWithoutNamespace = substr($file, strlen($namespace));
80+
$filename = ltrim(str_replace('\\', '/', $fileWithoutNamespace), '/');
7881
}
79-
80-
$paths = $namespaces[$prefix];
81-
82-
$filename = implode('/', $segments);
83-
break;
8482
}
8583

8684
// if no namespaces matched then quit

system/BaseModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ protected function transformDataToArray($data, string $type): array
15781578
// properties representing the collection elements, we need to grab
15791579
// them as an array.
15801580
if (is_object($data) && ! $data instanceof stdClass) {
1581-
$data = $this->objectToArray($data, true, true);
1581+
$data = $this->objectToArray($data, ($type === 'update'), true);
15821582
}
15831583

15841584
// If it's still a stdClass, go ahead and convert to

system/CLI/CLI.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -865,10 +865,12 @@ public static function getOptionString(bool $useLongOpts = false, bool $trim = f
865865
$out .= "-{$name} ";
866866
}
867867

868-
// If there's a space, we need to group
869-
// so it will pass correctly.
868+
if ($value === null) {
869+
continue;
870+
}
871+
870872
if (mb_strpos($value, ' ') !== false) {
871-
$out .= '"' . $value . '" ';
873+
$out .= "\"{$value}\" ";
872874
} elseif ($value !== null) {
873875
$out .= "{$value} ";
874876
}

system/Cache/Handlers/FileHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ protected function getItem(string $filename)
241241
return false;
242242
}
243243

244-
// @phpstan-ignore-next-line
245244
if ($data['ttl'] > 0 && time() > $data['time'] + $data['ttl']) {
246245
// If the file is still there then try to remove it
247246
if (is_file($this->path . $filename)) {

system/Cache/Handlers/MemcachedHandler.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function get(string $key)
146146
}
147147
}
148148

149-
return is_array($data) ? $data[0] : $data; // @phpstan-ignore-line
149+
return is_array($data) ? $data[0] : $data;
150150
}
151151

152152
/**
@@ -172,7 +172,6 @@ public function save(string $key, $value, int $ttl = 60)
172172
return $this->memcached->set($key, $value, 0, $ttl);
173173
}
174174

175-
// @phpstan-ignore-next-line
176175
return false;
177176
}
178177

@@ -205,7 +204,6 @@ public function increment(string $key, int $offset = 1)
205204

206205
$key = static::validateKey($key, $this->prefix);
207206

208-
// @phpstan-ignore-next-line
209207
return $this->memcached->increment($key, $offset, $offset, 60);
210208
}
211209

@@ -221,7 +219,7 @@ public function decrement(string $key, int $offset = 1)
221219
$key = static::validateKey($key, $this->prefix);
222220

223221
// FIXME: third parameter isn't other handler actions.
224-
// @phpstan-ignore-next-line
222+
225223
return $this->memcached->decrement($key, $offset, $offset, 60);
226224
}
227225

system/CodeIgniter.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace CodeIgniter;
1313

1414
use Closure;
15+
use CodeIgniter\Debug\Kint\RichRenderer;
1516
use CodeIgniter\Debug\Timer;
1617
use CodeIgniter\Events\Events;
1718
use CodeIgniter\Exceptions\FrameworkException;
@@ -33,7 +34,6 @@
3334
use Exception;
3435
use Kint;
3536
use Kint\Renderer\CliRenderer;
36-
use Kint\Renderer\RichRenderer;
3737

3838
/**
3939
* This class is the core of the framework, and will analyse the
@@ -45,7 +45,7 @@ class CodeIgniter
4545
/**
4646
* The current version of CodeIgniter Framework
4747
*/
48-
public const CI_VERSION = '4.1.5';
48+
public const CI_VERSION = '4.1.6';
4949

5050
private const MIN_PHP_VERSION = '7.3';
5151

@@ -249,19 +249,21 @@ protected function initializeKint()
249249
*/
250250
$config = config('Config\Kint');
251251

252-
Kint::$max_depth = $config->maxDepth;
252+
Kint::$depth_limit = $config->maxDepth;
253253
Kint::$display_called_from = $config->displayCalledFrom;
254254
Kint::$expanded = $config->expanded;
255255

256256
if (! empty($config->plugins) && is_array($config->plugins)) {
257257
Kint::$plugins = $config->plugins;
258258
}
259259

260+
Kint::$renderers[Kint::MODE_RICH] = RichRenderer::class;
261+
260262
RichRenderer::$theme = $config->richTheme;
261263
RichRenderer::$folder = $config->richFolder;
262264
RichRenderer::$sort = $config->richSort;
263265
if (! empty($config->richObjectPlugins) && is_array($config->richObjectPlugins)) {
264-
RichRenderer::$object_plugins = $config->richObjectPlugins;
266+
RichRenderer::$value_plugins = $config->richObjectPlugins;
265267
}
266268
if (! empty($config->richTabPlugins) && is_array($config->richTabPlugins)) {
267269
RichRenderer::$tab_plugins = $config->richTabPlugins;
@@ -537,7 +539,6 @@ protected function getRequestObject()
537539
return;
538540
}
539541

540-
// @phpstan-ignore-next-line
541542
if (is_cli() && ENVIRONMENT !== 'testing') {
542543
// @codeCoverageIgnoreStart
543544
$this->request = Services::clirequest($this->config);
@@ -721,7 +722,7 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
721722
// If a {locale} segment was matched in the final route,
722723
// then we need to set the correct locale on our Request.
723724
if ($this->router->hasLocale()) {
724-
$this->request->setLocale($this->router->getLocale()); // @phpstan-ignore-line
725+
$this->request->setLocale($this->router->getLocale());
725726
}
726727

727728
$this->benchmark->stop('routing');
@@ -816,7 +817,7 @@ protected function createController()
816817
protected function runController($class)
817818
{
818819
// If this is a console request then use the input segments as parameters
819-
$params = defined('SPARKED') ? $this->request->getSegments() : $this->router->params(); // @phpstan-ignore-line
820+
$params = defined('SPARKED') ? $this->request->getSegments() : $this->router->params();
820821

821822
if (method_exists($class, '_remap')) {
822823
$output = $class->_remap($this->method, ...$params);
@@ -969,7 +970,7 @@ public function spoofRequestMethod()
969970
return;
970971
}
971972

972-
$method = $this->request->getPost('_method'); // @phpstan-ignore-line
973+
$method = $this->request->getPost('_method');
973974

974975
if (empty($method)) {
975976
return;

system/Common.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ function env(string $key, $default = null)
380380
* If $data is an array, then it loops over it, escaping each
381381
* 'value' of the key/value pairs.
382382
*
383-
* Valid context values: html, js, css, url, attr, raw, null
383+
* Valid context values: html, js, css, url, attr, raw
384384
*
385385
* @param array|string $data
386386
* @param string $encoding
@@ -480,9 +480,9 @@ function force_https(int $duration = 31536000, ?RequestInterface $request = null
480480
$uri = URI::createURIString(
481481
'https',
482482
$baseURL,
483-
$request->uri->getPath(), // Absolute URIs should use a "/" for an empty path
484-
$request->uri->getQuery(),
485-
$request->uri->getFragment()
483+
$request->getUri()->getPath(), // Absolute URIs should use a "/" for an empty path
484+
$request->getUri()->getQuery(),
485+
$request->getUri()->getFragment()
486486
);
487487

488488
// Set an HSTS header
@@ -643,16 +643,13 @@ function helper($filenames)
643643
*/
644644
function is_cli(): bool
645645
{
646-
if (defined('STDIN')) {
646+
if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) {
647647
return true;
648648
}
649649

650-
if (! isset($_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT']) && isset($_SERVER['argv']) && count($_SERVER['argv']) > 0) {
651-
return true;
652-
}
653-
654-
// if source of request is from CLI, the `$_SERVER` array will not populate this key
655-
return ! isset($_SERVER['REQUEST_METHOD']);
650+
// PHP_SAPI could be 'cgi-fcgi', 'fpm-fcgi'.
651+
// See https://github.com/codeigniter4/CodeIgniter4/pull/5393
652+
return ! isset($_SERVER['REMOTE_ADDR']) && ! isset($_SERVER['REQUEST_METHOD']);
656653
}
657654
}
658655

@@ -813,11 +810,6 @@ function old(string $key, $default = null, $escape = 'html')
813810
return $default;
814811
}
815812

816-
// If the result was serialized array or string, then unserialize it for use...
817-
if (is_string($value) && (strpos($value, 'a:') === 0 || strpos($value, 's:') === 0)) {
818-
$value = unserialize($value);
819-
}
820-
821813
return $escape === false ? $value : esc($value, $escape);
822814
}
823815
}
@@ -1156,7 +1148,6 @@ function class_uses_recursive($class)
11561148

11571149
$results = [];
11581150

1159-
// @phpstan-ignore-next-line
11601151
foreach (array_reverse(class_parents($class)) + [$class => $class] as $class) {
11611152
$results += trait_uses_recursive($class);
11621153
}

0 commit comments

Comments
 (0)