Skip to content

Commit 877692c

Browse files
authored
Merge pull request #19 from alwaysblank/12-allow-removing-data
2 parents e71624f + 3346d6e commit 877692c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Brief.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,4 +903,23 @@ protected function resolveInternalKey($key) {
903903

904904
return null;
905905
}
906+
907+
/**
908+
* Remove data from the Brief.
909+
*
910+
* This will resolve aliases and delete the data they point to,
911+
* but *not* the aliases themselves.
912+
*
913+
* @param $key
914+
*
915+
* @return void
916+
*/
917+
public function delete($key) {
918+
$internalKey = $this->resolveInternalKey($key);
919+
if ($internalKey === null) {
920+
// Doesn't exist, so nothing to do.
921+
return;
922+
}
923+
unset($this->store[$internalKey]);
924+
}
906925
}

tests/BriefTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,18 @@ public function testCanUserCustomEmptyFunction(): void
480480
], ['isEmpty' => $test]);
481481
$this->assertFalse($Brieful->isEmpty());
482482
}
483+
484+
public function testCanDeleteDataFromBrief(): void {
485+
$Brief = Brief::make(['key' => 'value']);
486+
$this->assertEquals('value', $Brief->key);
487+
$Brief->delete('key');
488+
$this->assertNull($Brief->value);
489+
$NumericBrief = Brief::make(['value', 'not-value']);
490+
$this->assertEquals('value', $NumericBrief->_0);
491+
$NumericBrief->delete(0);
492+
$this->assertNull($NumericBrief->_0);
493+
494+
}
483495
}
484496

485497
/**

0 commit comments

Comments
 (0)