Skip to content

Commit 47d8379

Browse files
Allow not returning certain attributes (limosa-io#94)
1 parent fa60195 commit 47d8379

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/Attribute/Attribute.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Attribute
3939
protected $type = 'string';
4040
protected $description = null;
4141
protected $defaultValue = null;
42+
protected $returned = 'default';
4243

4344
public $dirty = false;
4445

@@ -68,7 +69,7 @@ public function generateSchema(){
6869
'name' => $this->name,
6970
'type' => $this->type,
7071
'mutability' => $this->mutability,
71-
'returned' => 'default',
72+
'returned' => $this->returned,
7273
'uniqueness' => 'server',
7374
'required' => $this->isRequired(),
7475
'multiValued' => $this->getMultiValued(),
@@ -133,6 +134,11 @@ public function shouldReturn(&$object)
133134
return true;
134135
}
135136

137+
public function setReturned($returned){
138+
$this->returned = $returned;
139+
return $this;
140+
}
141+
136142
public function setParent($parent)
137143
{
138144
$this->parent = $parent;
@@ -150,6 +156,10 @@ public function read(&$object, array $attributes = []): ?AttributeValue
150156
return null;
151157
}
152158

159+
if($this->returned == 'never'){
160+
return null;
161+
}
162+
153163
return new AttributeValue($this->doRead($object, $attributes) ?? $this->defaultValue);
154164
}
155165

src/SCIMConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function doRead(&$object, $attributes = [])
7878
eloquent('userName', 'name')->ensure('required'),
7979
eloquent('active')->ensure('boolean')->default(false),
8080
complex('name')->withSubAttributes(eloquent('formatted')),
81-
eloquent('password')->ensure('nullable'),
81+
eloquent('password')->ensure('nullable')->setReturned('never'),
8282
(new class ('emails') extends Complex {
8383
protected function doRead(&$object, $attributes = [])
8484
{

tests/BasicTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ public function testPost()
369369
$this->assertArrayHasKey('urn:ietf:params:scim:schemas:core:2.0:User', $json);
370370
$this->assertEquals('mariejo@example.com', $json['urn:ietf:params:scim:schemas:core:2.0:User']['emails'][0]['value']);
371371
$this->assertEquals('Dr. Marie Jo', $json['urn:ietf:params:scim:schemas:core:2.0:User']['userName']);
372+
$this->assertArrayNotHasKey('password', $json['urn:ietf:params:scim:schemas:core:2.0:User']);
372373
}
373374

374375
public function testPostTopLevel()

0 commit comments

Comments
 (0)