File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change 7
7
namespace karmabunny \kb ;
8
8
9
9
/**
10
- * This modifies the behaviour of a DataObject/Collection so that only
11
- * properties defined in the class are updated .
10
+ * This is functional the same as {@see UpdateTrait} only it uses the
11
+ * `getProperties()` helper to determine which fields belong to the class .
12
12
*
13
- * The default implementation will create _new_ fields that aren't typed. This
14
- * trait will only update fields that are explicitly defined. Unknown fields
15
- * are silently ignored.
16
- *
17
- * For a more aggressive approach {@see UpdateStrictTrait}.
13
+ * To raise errors on unknown fields {@see UpdateStrictTrait}.
18
14
*
19
15
* @package karmabunny\kb
20
16
*/
Original file line number Diff line number Diff line change 9
9
/**
10
10
* This implements basic `update()` behaviour for an object.
11
11
*
12
+ * Only fields that are defined as properties will be set. Unknown fields
13
+ * are silently ignored.
14
+ *
15
+ * To raise errors on unknown fields {@see UpdateStrictTrait}.
16
+ *
12
17
* @package karmabunny\kb
13
18
*/
14
19
trait UpdateTrait
@@ -21,6 +26,7 @@ trait UpdateTrait
21
26
public function update ($ config )
22
27
{
23
28
foreach ($ config as $ key => $ item ) {
29
+ if (!property_exists ($ this , $ key )) continue ;
24
30
$ this ->$ key = $ item ;
25
31
}
26
32
You can’t perform that action at this time.
0 commit comments