Skip to content

Commit e884702

Browse files
committed
setFrom second parameter is now optional valid fields
1 parent c769a1d commit e884702

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/PHPFUI/ORM/Record.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,18 @@ public function setEmpty() : static
492492
* Sets the object to values in the array. Invalid array values are ignored.
493493
*
494494
* @param array<string,mixed> $values
495-
*
495+
* @param array<string> $allowedFields list of allowed field names, other fields names will be ignored. Empty array updates all valid fields.
496496
* @param bool $loaded set to true if you want to simulated being loaded from the db.
497497
*/
498-
public function setFrom(array $values, bool $loaded = false) : static
498+
public function setFrom(array $values, array $allowedFields = [], bool $loaded = false) : static
499499
{
500500
$this->loaded = $loaded;
501501

502+
if (\count($allowedFields))
503+
{
504+
$values = \array_intersect_key($values, \array_flip($allowedFields));
505+
}
506+
502507
foreach ($values as $field => $value)
503508
{
504509
if (isset(static::$fields[$field]))

src/PHPFUI/ORM/RecordCursor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function next() : void
4848
}
4949
else
5050
{
51-
$this->current->setFrom($data, true);
51+
$this->current->setFrom($data, loaded:true);
5252
}
5353
++$this->index;
5454
}

src/PHPFUI/ORM/Validator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*
3333
* | Validator Name | Description | Parameters |
3434
* | -------------- | ----------- | ----------- |
35-
* | alnum | Numbers and characters only (ctype_alnum) | None |
35+
* | alpha_numeric | Numbers and characters only (ctype_alnum) | None |
3636
* | alpha | Characters only (ctype_alpha) | None |
3737
* | bool | Must be one or zero | None |
3838
* | card | Credit card number (LUHN validation) | None |

0 commit comments

Comments
 (0)