-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from quetzyg/feat/audit-redactors
[FEAT] Audit redactors
- Loading branch information
Showing
7 changed files
with
300 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* This file is part of the Laravel Auditing package. | ||
* | ||
* @author Antério Vieira <anteriovieira@gmail.com> | ||
* @author Quetzy Garcia <quetzyg@altek.org> | ||
* @author Raphael França <raphaelfrancabsb@gmail.com> | ||
* @copyright 2015-2018 | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE.md file that was distributed | ||
* with this source code. | ||
*/ | ||
|
||
namespace OwenIt\Auditing\Contracts; | ||
|
||
interface AuditRedactor | ||
{ | ||
/** | ||
* Redact a value. | ||
* | ||
* @param mixed $value | ||
* | ||
* @return string | ||
*/ | ||
public static function redact($value): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* This file is part of the Laravel Auditing package. | ||
* | ||
* @author Antério Vieira <anteriovieira@gmail.com> | ||
* @author Quetzy Garcia <quetzyg@altek.org> | ||
* @author Raphael França <raphaelfrancabsb@gmail.com> | ||
* @copyright 2015-2018 | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE.md file that was distributed | ||
* with this source code. | ||
*/ | ||
|
||
namespace OwenIt\Auditing\Redactors; | ||
|
||
class LeftRedactor implements \OwenIt\Auditing\Contracts\AuditRedactor | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function redact($value): string | ||
{ | ||
$total = strlen($value); | ||
$tenth = ceil($total / 10); | ||
|
||
// Make sure single character strings get redacted | ||
$length = ($total > $tenth) ? ($total - $tenth) : 1; | ||
|
||
return str_pad(substr($value, $length), $total, '#', STR_PAD_LEFT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* This file is part of the Laravel Auditing package. | ||
* | ||
* @author Antério Vieira <anteriovieira@gmail.com> | ||
* @author Quetzy Garcia <quetzyg@altek.org> | ||
* @author Raphael França <raphaelfrancabsb@gmail.com> | ||
* @copyright 2015-2018 | ||
* | ||
* For the full copyright and license information, | ||
* please view the LICENSE.md file that was distributed | ||
* with this source code. | ||
*/ | ||
|
||
namespace OwenIt\Auditing\Redactors; | ||
|
||
class RightRedactor implements \OwenIt\Auditing\Contracts\AuditRedactor | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function redact($value): string | ||
{ | ||
$total = strlen($value); | ||
$tenth = ceil($total / 10); | ||
|
||
// Make sure single character strings get redacted | ||
$length = ($total > $tenth) ? ($total - $tenth) : 1; | ||
|
||
return str_pad(substr($value, 0, -$length), $total, '#', STR_PAD_RIGHT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters