@@ -18,7 +18,7 @@ class Complex extends AbstractComplex
1818 */
1919 public function getSchemas ()
2020 {
21- return collect ($ this ->getSchemaNodes ())->map (fn ($ element ) => $ element ->name )->values ()->toArray ();
21+ return collect ($ this ->getSchemaNodes ())->map (fn ($ element ) => $ element ->name )->values ()->toArray ();
2222 }
2323
2424
@@ -76,21 +76,29 @@ public function patch($operation, $value, Model &$object, Path $path = null, $re
7676 $ attributeNames = $ path ?->getAttributePath()?->getAttributeNames() ?? [];
7777
7878 if (!empty ($ attributeNames )) {
79- $ attribute = $ this ->getSubNode ($ attributeNames [0 ]);
79+ $ schema = $ path ->getAttributePath ()?->path?->schema;
80+ // Resolve attribute either directly or via schema parent when specified
81+ $ attribute = $ schema
82+ ? ((($ parent = $ this ->getSubNode ($ schema )) instanceof Schema) ? $ parent ->getSubNode ($ attributeNames [0 ]) : null )
83+ : $ this ->getSubNode ($ attributeNames [0 ]);
84+
8085 if ($ attribute != null ) {
8186 $ attribute ->patch ($ operation , $ value , $ object , $ path ->shiftAttributePathAttributes ());
82- } elseif ($ this ->parent == null ) {
83- // this is the root node, check within the first (the default) schema node
84- // pass the unchanged path object
87+ return ; // done
88+ }
89+
90+ if ($ this ->parent == null ) {
91+ // root node: delegate unchanged path to default schema node
8592 $ this ->getSchemaNode ()->patch ($ operation , $ value , $ object , $ path );
86- } else {
87- throw new SCIMException ('Unknown path: ' . (string )$ path . ", in object: " . $ this ->getFullKey ());
93+ return ; // done
8894 }
95+
96+ throw new SCIMException ('Unknown path: ' . (string )$ path . ", in object: " . $ this ->getFullKey ());
8997 }
9098 }
9199 } else {
92100 // if there is no path, keys of value are attribute names
93- switch ($ operation ) {
101+ switch ($ operation ) {
94102 case 'replace ' :
95103 $ this ->replace ($ value , $ object , $ path , false );
96104 break ;
@@ -300,6 +308,6 @@ public function applyComparison(Builder &$query, Path $path, $parentAttribute =
300308 */
301309 public function getDefaultSchema ()
302310 {
303- return collect ($ this ->subAttributes )->first (fn ($ element ) => $ element instanceof Schema)->name ;
311+ return collect ($ this ->subAttributes )->first (fn ($ element ) => $ element instanceof Schema)->name ;
304312 }
305313}
0 commit comments