Skip to content

Commit cfb1684

Browse files
Merge pull request #4 from StyxOfDynamite/pass-closure-to-ink
ink method may now accept closures
2 parents 02a0b75 + 47bc051 commit cfb1684

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ArrayRedactor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function keys($keys = [])
7777
*/
7878
public function ink($ink = '[REDACTED]')
7979
{
80-
$this->ink = $ink;
80+
$this->ink = is_callable($ink) ? $ink() : $ink;
8181
return $this;
8282
}
8383

tests/ArrayRedactorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,16 @@ public function can_omit_constructor_arguments_in_favor_of_methods()
9494
'password' => null
9595
]), $result);
9696
}
97+
98+
/** @test */
99+
public function can_accept_closure_in_ink()
100+
{
101+
$array = $this->content;
102+
$result = (new ArrayRedactor())->content($this->content)->keys(['email'])->ink(function() use ($array) {
103+
return substr($array['email'], stripos($array['email'], '@'));
104+
})->redact();
105+
$this->assertEquals(array_merge($this->content, [
106+
'email' => '@gmail.com'
107+
]), $result);
108+
}
97109
}

0 commit comments

Comments
 (0)