Skip to content

Commit e4d3702

Browse files
committed
Release v4.6.4
1 parent 68d1a58 commit e4d3702

File tree

118 files changed

+910
-562
lines changed

Some content is hidden

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

118 files changed

+910
-562
lines changed

app/Config/Database.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class Database extends Config
182182
'port' => 3306,
183183
'foreignKeys' => true,
184184
'busyTimeout' => 1000,
185+
'synchronous' => null,
185186
'dateFormat' => [
186187
'date' => 'Y-m-d',
187188
'datetime' => 'Y-m-d H:i:s',

app/Controllers/BaseController.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,43 @@
33
namespace App\Controllers;
44

55
use CodeIgniter\Controller;
6-
use CodeIgniter\HTTP\CLIRequest;
7-
use CodeIgniter\HTTP\IncomingRequest;
86
use CodeIgniter\HTTP\RequestInterface;
97
use CodeIgniter\HTTP\ResponseInterface;
108
use Psr\Log\LoggerInterface;
119

1210
/**
13-
* Class BaseController
14-
*
1511
* BaseController provides a convenient place for loading components
1612
* and performing functions that are needed by all your controllers.
13+
*
1714
* Extend this class in any new controllers:
15+
* ```
1816
* class Home extends BaseController
17+
* ```
1918
*
20-
* For security be sure to declare any new methods as protected or private.
19+
* For security, be sure to declare any new methods as protected or private.
2120
*/
2221
abstract class BaseController extends Controller
2322
{
24-
/**
25-
* Instance of the main Request object.
26-
*
27-
* @var CLIRequest|IncomingRequest
28-
*/
29-
protected $request;
30-
31-
/**
32-
* An array of helpers to be loaded automatically upon
33-
* class instantiation. These helpers will be available
34-
* to all other controllers that extend BaseController.
35-
*
36-
* @var list<string>
37-
*/
38-
protected $helpers = [];
39-
4023
/**
4124
* Be sure to declare properties for any property fetch you initialized.
4225
* The creation of dynamic property is deprecated in PHP 8.2.
4326
*/
27+
4428
// protected $session;
4529

4630
/**
4731
* @return void
4832
*/
4933
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
5034
{
51-
// Do Not Edit This Line
35+
// Load here all helpers you want to be available in your controllers that extend BaseController.
36+
// Caution: Do not put the this below the parent::initController() call below.
37+
// $this->helpers = ['form', 'url'];
38+
39+
// Caution: Do not edit this line.
5240
parent::initController($request, $response, $logger);
5341

5442
// Preload any models, libraries, etc, here.
55-
56-
// E.g.: $this->session = service('session');
43+
// $this->session = service('session');
5744
}
5845
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"codeigniter/coding-standard": "^1.7",
2121
"fakerphp/faker": "^1.24",
2222
"friendsofphp/php-cs-fixer": "^3.47.1",
23-
"kint-php/kint": "^6.0",
23+
"kint-php/kint": "^6.1",
2424
"mikey179/vfsstream": "^1.6.12",
2525
"nexusphp/cs-config": "^3.6",
2626
"phpunit/phpunit": "^10.5.16 || ^11.2",

preload.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ public function load(): void
101101
}
102102

103103
require_once $file[0];
104-
echo 'Loaded: ' . $file[0] . "\n";
104+
// Uncomment only for debugging (to inspect which files are included).
105+
// Never use this in production - preload scripts must not generate output.
106+
// echo 'Loaded: ' . $file[0] . "\n";
105107
}
106108
}
107109
}

system/API/ResponseTrait.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515

1616
use CodeIgniter\Format\Format;
1717
use CodeIgniter\Format\FormatterInterface;
18+
use CodeIgniter\HTTP\CLIRequest;
1819
use CodeIgniter\HTTP\IncomingRequest;
19-
use CodeIgniter\HTTP\RequestInterface;
2020
use CodeIgniter\HTTP\ResponseInterface;
2121

2222
/**
2323
* Provides common, more readable, methods to provide
2424
* consistent HTTP responses under a variety of common
2525
* situations when working as an API.
2626
*
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.
27+
* @property CLIRequest|IncomingRequest $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.
3131
*/
3232
trait ResponseTrait
3333
{
@@ -122,9 +122,9 @@ protected function respond($data = null, ?int $status = null, string $message =
122122
/**
123123
* Used for generic failures that no custom methods exist for.
124124
*
125-
* @param list<string>|string $messages
126-
* @param int $status HTTP status code
127-
* @param string|null $code Custom, API-specific, error code
125+
* @param array<array-key, string>|string $messages
126+
* @param int $status HTTP status code
127+
* @param string|null $code Custom, API-specific, error code
128128
*
129129
* @return ResponseInterface
130130
*/
@@ -230,7 +230,7 @@ protected function failNotFound(string $description = 'Not Found', ?string $code
230230
/**
231231
* Used when the data provided by the client cannot be validated on one or more fields.
232232
*
233-
* @param list<string>|string $errors
233+
* @param array<array-key, string>|string $errors
234234
*
235235
* @return ResponseInterface
236236
*/

system/BaseModel.php

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ protected function shouldUpdate($row): bool
769769
{
770770
$id = $this->getIdValue($row);
771771

772-
return ! ($id === null || $id === [] || $id === '');
772+
return ! in_array($id, [null, [], ''], true);
773773
}
774774

775775
/**
@@ -909,22 +909,7 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
909909

910910
if (is_array($set)) {
911911
foreach ($set as &$row) {
912-
// If $row is using a custom class with public or protected
913-
// properties representing the collection elements, we need to grab
914-
// them as an array.
915-
if (is_object($row) && ! $row instanceof stdClass) {
916-
$row = $this->objectToArray($row, false, true);
917-
}
918-
919-
// If it's still a stdClass, go ahead and convert to
920-
// an array so doProtectFields and other model methods
921-
// don't have to do special checks.
922-
if (is_object($row)) {
923-
$row = (array) $row;
924-
}
925-
926-
// Convert any Time instances to appropriate $dateFormat
927-
$row = $this->timeToString($row);
912+
$row = $this->transformDataRowToArray($row);
928913

929914
// Validate every row.
930915
if (! $this->skipValidation && ! $this->validate($row)) {
@@ -1051,21 +1036,7 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
10511036
{
10521037
if (is_array($set)) {
10531038
foreach ($set as &$row) {
1054-
// If $row is using a custom class with public or protected
1055-
// properties representing the collection elements, we need to grab
1056-
// them as an array.
1057-
if (is_object($row) && ! $row instanceof stdClass) {
1058-
// For updates the index field is needed even if it is not changed.
1059-
// So set $onlyChanged to false.
1060-
$row = $this->objectToArray($row, false, true);
1061-
}
1062-
1063-
// If it's still a stdClass, go ahead and convert to
1064-
// an array so doProtectFields and other model methods
1065-
// don't have to do special checks.
1066-
if (is_object($row)) {
1067-
$row = (array) $row;
1068-
}
1039+
$row = $this->transformDataRowToArray($row);
10691040

10701041
// Validate data before saving.
10711042
if (! $this->skipValidation && ! $this->validate($row)) {
@@ -1220,7 +1191,9 @@ public function replace(?array $row = null, bool $returnSQL = false)
12201191
return false;
12211192
}
12221193

1223-
$row = $this->setUpdatedField((array) $row, $this->setDate());
1194+
$row = (array) $row;
1195+
$row = $this->setCreatedField($row, $this->setDate());
1196+
$row = $this->setUpdatedField($row, $this->setDate());
12241197

12251198
return $this->doReplace($row, $returnSQL);
12261199
}
@@ -1694,6 +1667,52 @@ protected function trigger(string $event, array $eventData)
16941667
return $eventData;
16951668
}
16961669

1670+
/**
1671+
* If the model is using casts, this will convert the data
1672+
* in $row according to the rules defined in `$casts`.
1673+
*
1674+
* @param object|row_array|null $row Row data
1675+
*
1676+
* @return object|row_array|null Converted row data
1677+
*
1678+
* @used-by insertBatch()
1679+
* @used-by updateBatch()
1680+
*
1681+
* @throws ReflectionException
1682+
* @deprecated Since 4.6.4, temporary solution - will be removed in 4.7
1683+
*/
1684+
protected function transformDataRowToArray(array|object|null $row): array|object|null
1685+
{
1686+
// If casts are used, convert the data first
1687+
if ($this->useCasts()) {
1688+
if (is_array($row)) {
1689+
$row = $this->converter->toDataSource($row);
1690+
} elseif ($row instanceof stdClass) {
1691+
$row = (array) $row;
1692+
$row = $this->converter->toDataSource($row);
1693+
} elseif ($row instanceof Entity) {
1694+
$row = $this->converter->extract($row);
1695+
} elseif (is_object($row)) {
1696+
$row = $this->converter->extract($row);
1697+
}
1698+
} elseif (is_object($row) && ! $row instanceof stdClass) {
1699+
// If $row is using a custom class with public or protected
1700+
// properties representing the collection elements, we need to grab
1701+
// them as an array.
1702+
$row = $this->objectToArray($row, false, true);
1703+
}
1704+
1705+
// If it's still a stdClass, go ahead and convert to
1706+
// an array so doProtectFields and other model methods
1707+
// don't have to do special checks.
1708+
if (is_object($row)) {
1709+
$row = (array) $row;
1710+
}
1711+
1712+
// Convert any Time instances to appropriate $dateFormat
1713+
return $this->timeToString($row);
1714+
}
1715+
16971716
/**
16981717
* Sets the return type of the results to be as an associative array.
16991718
*

system/CLI/BaseCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function showHelp()
142142
{
143143
CLI::write(lang('CLI.helpUsage'), 'yellow');
144144

145-
if (isset($this->usage)) {
145+
if ($this->usage !== null) {
146146
$usage = $this->usage;
147147
} else {
148148
$usage = $this->name;
@@ -154,7 +154,7 @@ public function showHelp()
154154

155155
CLI::write($this->setPad($usage, 0, 0, 2));
156156

157-
if (isset($this->description)) {
157+
if ($this->description !== null) {
158158
CLI::newLine();
159159
CLI::write(lang('CLI.helpDescription'), 'yellow');
160160
CLI::write($this->setPad($this->description, 0, 0, 2));

system/CLI/CLI.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,7 @@ public static function promptByMultipleKeys(string $text, array $options): array
318318
if ($opts === []) {
319319
$extraOutput = $extraOutputDefault;
320320
} else {
321-
$optsKey = [];
322-
323-
foreach (array_keys($opts) as $key) {
324-
$optsKey[] = $key;
325-
}
321+
$optsKey = array_keys($opts);
326322
$extraOutput = '[' . $extraOutputDefault . ', ' . implode(', ', $optsKey) . ']';
327323
$extraOutput = 'You can specify multiple values separated by commas.' . PHP_EOL . $extraOutput;
328324
}

system/CLI/Commands.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function discoverCommands()
129129

130130
$class = new $className($this->logger, $this);
131131

132-
if (isset($class->group) && ! isset($this->commands[$class->name])) {
132+
if ($class->group !== null && ! isset($this->commands[$class->name])) {
133133
$this->commands[$class->name] = [
134134
'class' => $className,
135135
'file' => $file,

system/Cache/Handlers/PredisHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public function deleteMatching(string $pattern)
162162
$matchedKeys[] = $key;
163163
}
164164

165+
if ($matchedKeys === []) {
166+
return 0;
167+
}
168+
165169
return $this->redis->del($matchedKeys);
166170
}
167171

0 commit comments

Comments
 (0)