Skip to content

Commit

Permalink
Add JSON whitelist mask (TheSoftwareHouse#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmahoney authored Jun 16, 2020
1 parent ff1f6d0 commit 436ca84
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Fogger/Mask/JSONWhitelistMask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Fogger\Mask;

final class JSONWhitelistMask extends AbstractMask
{
public function apply(?string $value, array $options = []): ?string
{
if ((null === $value) or ("" === $value )) {
return $value;
}

$whitelist = $options['whitelist'] ?? [];

$result = [];
$jsonArray = json_decode($value, true);

foreach ($whitelist as $field) {
if (array_key_exists($field, $jsonArray)) {
$result[$field] = $jsonArray[$field];
}
}
return json_encode($result);
}

protected function getMaskName(): string
{
return 'jsonwhitelist';
}
}

0 comments on commit 436ca84

Please sign in to comment.