Skip to content

Commit 011ce3b

Browse files
committed
Release v4.2.7
1 parent 872c8fb commit 011ce3b

File tree

85 files changed

+596
-518
lines changed

Some content is hidden

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

85 files changed

+596
-518
lines changed

app/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* The goal of this file is to allow developers a location
55
* where they can overwrite core procedural functions and
66
* replace them with their own. This file is loaded during
7-
* the bootstrap process and is called during the frameworks
7+
* the bootstrap process and is called during the framework's
88
* execution.
99
*
1010
* This can be looked at as a `master helper` file that is

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"psr/log": "^1.1"
1616
},
1717
"require-dev": {
18-
"codeigniter/coding-standard": "^1.1",
18+
"codeigniter/coding-standard": "^1.5",
1919
"fakerphp/faker": "^1.9",
2020
"friendsofphp/php-cs-fixer": "~3.11.0",
2121
"mikey179/vfsstream": "^1.6",
22-
"nexusphp/cs-config": "^3.3",
22+
"nexusphp/cs-config": "^3.6",
2323
"phpunit/phpunit": "^9.1",
2424
"predis/predis": "^1.1 || ^2.0"
2525
},

system/API/ResponseTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected function fail($messages, int $status = 400, ?string $code = null, stri
143143
/**
144144
* Used after successfully creating a new resource.
145145
*
146-
* @param mixed $data
146+
* @param array|string|null $data
147147
*
148148
* @return Response
149149
*/
@@ -155,7 +155,7 @@ protected function respondCreated($data = null, string $message = '')
155155
/**
156156
* Used after a resource has been successfully deleted.
157157
*
158-
* @param mixed $data
158+
* @param array|string|null $data
159159
*
160160
* @return Response
161161
*/
@@ -167,7 +167,7 @@ protected function respondDeleted($data = null, string $message = '')
167167
/**
168168
* Used after a resource has been successfully updated.
169169
*
170-
* @param mixed $data
170+
* @param array|string|null $data
171171
*
172172
* @return Response
173173
*/

system/BaseModel.php

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ abstract class BaseModel
189189

190190
/**
191191
* Whether rules should be removed that do not exist
192-
* in the passed in data. Used between inserts/updates.
192+
* in the passed data. Used in updates.
193193
*
194194
* @var bool
195195
*/
@@ -326,9 +326,9 @@ abstract protected function doFind(bool $singleton, $id = null);
326326
*
327327
* @param string $columnName Column Name
328328
*
329-
* @throws DataException
330-
*
331329
* @return array|null The resulting row of data, or null if no data found.
330+
*
331+
* @throws DataException
332332
*/
333333
abstract protected function doFindColumn(string $columnName);
334334

@@ -392,9 +392,9 @@ abstract protected function doUpdate($id = null, $data = null): bool;
392392
* @param int $batchSize The size of the batch to run
393393
* @param bool $returnSQL True means SQL is returned, false will execute the query
394394
*
395-
* @throws DatabaseException
396-
*
397395
* @return mixed Number of rows affected or FALSE on failure
396+
*
397+
* @throws DatabaseException
398398
*/
399399
abstract protected function doUpdateBatch(?array $set = null, ?string $index = null, int $batchSize = 100, bool $returnSQL = false);
400400

@@ -405,9 +405,9 @@ abstract protected function doUpdateBatch(?array $set = null, ?string $index = n
405405
* @param array|int|string|null $id The rows primary key(s)
406406
* @param bool $purge Allows overriding the soft deletes setting.
407407
*
408-
* @throws DatabaseException
409-
*
410408
* @return bool|string
409+
*
410+
* @throws DatabaseException
411411
*/
412412
abstract protected function doDelete($id = null, bool $purge = false);
413413

@@ -541,9 +541,9 @@ public function find($id = null)
541541
*
542542
* @param string $columnName Column Name
543543
*
544-
* @throws DataException
545-
*
546544
* @return array|null The resulting row of data, or null if no data found.
545+
*
546+
* @throws DataException
547547
*/
548548
public function findColumn(string $columnName)
549549
{
@@ -693,21 +693,31 @@ public function getInsertID()
693693
* @param array|object|null $data Data
694694
* @param bool $returnID Whether insert ID should be returned or not.
695695
*
696-
* @throws ReflectionException
697-
*
698696
* @return bool|int|string insert ID or true on success. false on failure.
697+
*
698+
* @throws ReflectionException
699699
*/
700700
public function insert($data = null, bool $returnID = true)
701701
{
702702
$this->insertID = 0;
703703

704+
// Set $cleanValidationRules to false temporary.
705+
$cleanValidationRules = $this->cleanValidationRules;
706+
$this->cleanValidationRules = false;
707+
704708
$data = $this->transformDataToArray($data, 'insert');
705709

706710
// Validate data before saving.
707-
if (! $this->skipValidation && ! $this->cleanRules()->validate($data)) {
711+
if (! $this->skipValidation && ! $this->validate($data)) {
712+
// Restore $cleanValidationRules
713+
$this->cleanValidationRules = $cleanValidationRules;
714+
708715
return false;
709716
}
710717

718+
// Restore $cleanValidationRules
719+
$this->cleanValidationRules = $cleanValidationRules;
720+
711721
// Must be called first so we don't
712722
// strip out created_at values.
713723
$data = $this->doProtectFields($data);
@@ -767,12 +777,16 @@ public function insert($data = null, bool $returnID = true)
767777
* @param int $batchSize The size of the batch to run
768778
* @param bool $testing True means only number of records is returned, false will execute the query
769779
*
770-
* @throws ReflectionException
771-
*
772780
* @return bool|int Number of rows inserted or FALSE on failure
781+
*
782+
* @throws ReflectionException
773783
*/
774784
public function insertBatch(?array $set = null, ?bool $escape = null, int $batchSize = 100, bool $testing = false)
775785
{
786+
// Set $cleanValidationRules to false temporary.
787+
$cleanValidationRules = $this->cleanValidationRules;
788+
$this->cleanValidationRules = false;
789+
776790
if (is_array($set)) {
777791
foreach ($set as &$row) {
778792
// If $data is using a custom class with public or protected
@@ -789,8 +803,11 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
789803
$row = (array) $row;
790804
}
791805

792-
// Validate every row..
793-
if (! $this->skipValidation && ! $this->cleanRules()->validate($row)) {
806+
// Validate every row.
807+
if (! $this->skipValidation && ! $this->validate($row)) {
808+
// Restore $cleanValidationRules
809+
$this->cleanValidationRules = $cleanValidationRules;
810+
794811
return false;
795812
}
796813

@@ -811,6 +828,9 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
811828
}
812829
}
813830

831+
// Restore $cleanValidationRules
832+
$this->cleanValidationRules = $cleanValidationRules;
833+
814834
return $this->doInsertBatch($set, $escape, $batchSize, $testing);
815835
}
816836

@@ -832,7 +852,7 @@ public function update($id = null, $data = null): bool
832852
$data = $this->transformDataToArray($data, 'update');
833853

834854
// Validate data before saving.
835-
if (! $this->skipValidation && ! $this->cleanRules(true)->validate($data)) {
855+
if (! $this->skipValidation && ! $this->validate($data)) {
836856
return false;
837857
}
838858

@@ -882,10 +902,10 @@ public function update($id = null, $data = null): bool
882902
* @param int $batchSize The size of the batch to run
883903
* @param bool $returnSQL True means SQL is returned, false will execute the query
884904
*
905+
* @return mixed Number of rows affected or FALSE on failure
906+
*
885907
* @throws DatabaseException
886908
* @throws ReflectionException
887-
*
888-
* @return mixed Number of rows affected or FALSE on failure
889909
*/
890910
public function updateBatch(?array $set = null, ?string $index = null, int $batchSize = 100, bool $returnSQL = false)
891911
{
@@ -906,7 +926,7 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
906926
}
907927

908928
// Validate data before saving.
909-
if (! $this->skipValidation && ! $this->cleanRules(true)->validate($row)) {
929+
if (! $this->skipValidation && ! $this->validate($row)) {
910930
return false;
911931
}
912932

@@ -937,9 +957,9 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
937957
* @param array|int|string|null $id The rows primary key(s)
938958
* @param bool $purge Allows overriding the soft deletes setting.
939959
*
940-
* @throws DatabaseException
941-
*
942960
* @return BaseResult|bool
961+
*
962+
* @throws DatabaseException
943963
*/
944964
public function delete($id = null, bool $purge = false)
945965
{
@@ -1027,7 +1047,7 @@ public function onlyDeleted()
10271047
public function replace(?array $data = null, bool $returnSQL = false)
10281048
{
10291049
// Validate data before saving.
1030-
if ($data && ! $this->skipValidation && ! $this->cleanRules(true)->validate($data)) {
1050+
if ($data && ! $this->skipValidation && ! $this->validate($data)) {
10311051
return false;
10321052
}
10331053

@@ -1153,9 +1173,9 @@ protected function doProtectFields(array $data): array
11531173
*
11541174
* @param int|null $userData An optional PHP timestamp to be converted.
11551175
*
1156-
* @throws ModelException
1157-
*
11581176
* @return mixed
1177+
*
1178+
* @throws ModelException
11591179
*/
11601180
protected function setDate(?int $userData = null)
11611181
{
@@ -1177,9 +1197,9 @@ protected function setDate(?int $userData = null)
11771197
*
11781198
* @param int $value value
11791199
*
1180-
* @throws ModelException
1181-
*
11821200
* @return int|string
1201+
*
1202+
* @throws ModelException
11831203
*/
11841204
protected function intToDate(int $value)
11851205
{
@@ -1440,9 +1460,9 @@ public function allowCallbacks(bool $val = true)
14401460
* @param string $event Event
14411461
* @param array $eventData Event Data
14421462
*
1443-
* @throws DataException
1444-
*
14451463
* @return mixed
1464+
*
1465+
* @throws DataException
14461466
*/
14471467
protected function trigger(string $event, array $eventData)
14481468
{
@@ -1501,9 +1521,9 @@ public function asObject(string $class = 'object')
15011521
* @param bool $onlyChanged Only Changed Property
15021522
* @param bool $recursive If true, inner entities will be casted as array as well
15031523
*
1504-
* @throws ReflectionException
1505-
*
15061524
* @return array Array
1525+
*
1526+
* @throws ReflectionException
15071527
*/
15081528
protected function objectToArray($data, bool $onlyChanged = true, bool $recursive = false): array
15091529
{
@@ -1531,9 +1551,9 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv
15311551
* @param bool $onlyChanged Only Changed Property
15321552
* @param bool $recursive If true, inner entities will be casted as array as well
15331553
*
1534-
* @throws ReflectionException
1535-
*
15361554
* @return array|null Array
1555+
*
1556+
* @throws ReflectionException
15371557
*/
15381558
protected function objectToRawArray($data, bool $onlyChanged = true, bool $recursive = false): ?array
15391559
{
@@ -1581,7 +1601,11 @@ protected function transformDataToArray($data, string $type): array
15811601
// properties representing the collection elements, we need to grab
15821602
// them as an array.
15831603
if (is_object($data) && ! $data instanceof stdClass) {
1584-
$data = $this->objectToArray($data, ($type === 'update'), true);
1604+
// If it validates with entire rules, all fields are needed.
1605+
$onlyChanged = ($this->skipValidation === false && $this->cleanValidationRules === false)
1606+
? false : ($type === 'update');
1607+
1608+
$data = $this->objectToArray($data, $onlyChanged, true);
15851609
}
15861610

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

system/CLI/BaseCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ abstract public function run(array $params);
103103
/**
104104
* Can be used by a command to run other commands.
105105
*
106-
* @throws ReflectionException
107-
*
108106
* @return mixed
107+
*
108+
* @throws ReflectionException
109109
*/
110110
protected function call(string $command, array $params = [])
111111
{

system/CLI/CommandRunner.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function __construct()
4242
* @param string $method
4343
* @param array $params
4444
*
45-
* @throws ReflectionException
46-
*
4745
* @return mixed
46+
*
47+
* @throws ReflectionException
4848
*/
4949
public function _remap($method, $params)
5050
{
@@ -54,9 +54,9 @@ public function _remap($method, $params)
5454
/**
5555
* Default command.
5656
*
57-
* @throws ReflectionException
58-
*
5957
* @return mixed
58+
*
59+
* @throws ReflectionException
6060
*/
6161
public function index(array $params)
6262
{

system/CLI/Console.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public function __construct(CodeIgniter $app)
3434
/**
3535
* Runs the current command discovered on the CLI.
3636
*
37-
* @throws Exception
38-
*
3937
* @return mixed
38+
*
39+
* @throws Exception
4040
*/
4141
public function run(bool $useSafeOutput = false)
4242
{

0 commit comments

Comments
 (0)