@@ -31,11 +31,39 @@ public function add($value, Model &$object)
3131 $ object ->load ($ this ->attribute );
3232 }
3333
34- public function remove ($ value , Model &$ object , Path $ path = null )
34+ public function remove ($ value , Model &$ object , ? Path $ path = null )
3535 {
36- $ values = collect ($ value )->pluck ('value ' )->all ();
36+ if ($ path ?->getValuePathFilter()?->getComparisonExpression() != null ) {
37+ $ attributes = $ path ?->getValuePathFilter()?->getComparisonExpression()?->attributePath?->attributeNames;
38+ $ operator = $ path ?->getValuePathFilter()?->getComparisonExpression()?->operator;
39+ $ compareValue = $ path ?->getValuePathFilter()?->getComparisonExpression()?->compareValue;
40+
41+ if ($ value != null ) {
42+ throw new SCIMException ('Remove operation with filter requires a null value parameter ' , 400 );
43+ }
44+
45+ if (count ($ attributes ) != 1 ) {
46+ throw new SCIMException (sprintf ('Filter must specify exactly one attribute, found %d attributes ' , count ($ attributes )), 400 );
47+ }
48+
49+ if ($ operator != 'eq ' ) {
50+ throw new SCIMException (sprintf ('Unsupported filter operator "%s" - only "eq" is supported ' , $ operator ), 400 );
51+ }
52+
53+ if ($ attributes [0 ] != 'value ' ) {
54+ throw new SCIMException (sprintf ('Cannot filter on "%s" - only filtering on "value" attribute is supported ' , $ attributes [0 ]), 400 );
55+ }
56+
57+ if ($ value != null ) {
58+ throw new SCIMException ('Cannot specify both a filter path and a value parameter simultaneously ' , 400 );
59+ }
60+
61+ $ object ->{$ this ->attribute }()->detach ([$ compareValue ]);
62+ } else {
63+ $ values = collect ($ value )->pluck ('value ' )->all ();
3764
38- $ object ->{$ this ->attribute }()->detach ($ values );
65+ $ object ->{$ this ->attribute }()->detach ($ values );
66+ }
3967
4068 $ object ->load ($ this ->attribute );
4169 }
0 commit comments