{"id":22917430,"url":"https://github.com/mtownsend5512/array-redactor","last_synced_at":"2025-04-05T12:07:30.126Z","repository":{"id":57021625,"uuid":"187906223","full_name":"mtownsend5512/array-redactor","owner":"mtownsend5512","description":"A PHP package to redact array values by their keys.","archived":false,"fork":false,"pushed_at":"2023-08-04T08:38:40.000Z","size":16,"stargazers_count":146,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T11:08:58.984Z","etag":null,"topics":["array","laravel","logging","recursive","redactor"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtownsend5512.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-21T20:09:11.000Z","updated_at":"2025-01-13T00:36:48.000Z","dependencies_parsed_at":"2024-06-19T09:27:26.363Z","dependency_job_id":null,"html_url":"https://github.com/mtownsend5512/array-redactor","commit_stats":{"total_commits":6,"total_committers":4,"mean_commits":1.5,"dds":0.6666666666666667,"last_synced_commit":"cfb168402a3539c35965bc316b59c34d22d1e375"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Farray-redactor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Farray-redactor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Farray-redactor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Farray-redactor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtownsend5512","download_url":"https://codeload.github.com/mtownsend5512/array-redactor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332609,"owners_count":20921853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","laravel","logging","recursive","redactor"],"created_at":"2024-12-14T06:17:55.896Z","updated_at":"2025-04-05T12:07:30.097Z","avatar_url":"https://github.com/mtownsend5512.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"A PHP package to redact an array's values by their keys no matter how deep the array.\n\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://i.imgur.com/zkRNi2A.jpg\"\u003e\n\u003c/p\u003e\n\n## Why?\n\nHave you ever built or interacted with an api and needed to log all outgoing and incoming calls? Chances are that somewhere in that process is an authentication, either by an app or on behalf of a user. Logs are useful for debugging, but storing sensitive information such as passwords or api keys is not something you want to have in your logs for anyone to see. The usage goes beyond just this example, but that is what prompted me to create the ArrayRedactor package.\n\nWhatever your usage needs may be, this package aims to provide a dead-simple, lightweight way to censor sensitive information in an array no matter how deeply it is nested.\n\n## Installation\n\nInstall via composer:\n\n```\ncomposer require mtownsend/array-redactor\n```\n\n*This package is designed to work with any PHP 5.6+ application but has special Facade support for Laravel.*\n\n### Registering the service provider (Laravel users)\n\nFor Laravel 5.4 and lower, add the following line to your ``config/app.php``:\n\n```php\n/*\n * Package Service Providers...\n */\nMtownsend\\ArrayRedactor\\Providers\\ArrayRedactorServiceProvider::class,\n```\n\nFor Laravel 5.5 and greater, the package will auto register the provider for you.\n\n### Using Lumen\n\nTo register the service provider, add the following line to ``app/bootstrap/app.php``:\n\n```php\n$app-\u003eregister(Mtownsend\\ArrayRedactor\\Providers\\ArrayRedactorServiceProvider::class);\n```\n\n### Publishing the config file (Laravel users)\n\n````\nphp artisan vendor:publish --provider=\"Mtownsend\\ArrayRedactor\\Providers\\ArrayRedactorServiceProvider\"\n````\n\nOnce your ``arrayredactor.php`` has been published to your config folder, you will see a file with 2 keys in it: ``keys`` and ``ink``. You can replace these values with anything you want, but please note: **these values will only be applied when using the Laravel Facade**.\n\n## Quick start\n\n### Using the class\n\n```php\nuse Mtownsend\\ArrayRedactor\\ArrayRedactor;\n\n// An example array, maybe a request being made to/from an API application you wish to log in your database\n$login = [\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e 'secret123',\n    'data' =\u003e [\n        'session_id' =\u003e 'z481jf0an4kasnc8a84aj831'\n    ],\n];\n\n$redactor = (new ArrayRedactor($login, ['password', 'session_id']))-\u003eredact();\n\n// $redactor will return:\n[\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e '[REDACTED]',\n    'data' =\u003e [\n        'session_id' =\u003e '[REDACTED]'\n    ],\n];\n```\n\n### Advanced usage\n\nArray Redactor can also receive valid json instead of an array of content.\n\n```php\n$json = json_encode([\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e 'secret123',\n    'data' =\u003e [\n        'session_id' =\u003e 'z481jf0an4kasnc8a84aj831'\n    ],\n]);\n\n$redactor = (new ArrayRedactor($json, ['password', 'session_id']))-\u003eredact();\n\n// $redactor will return:\n[\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e '[REDACTED]',\n    'data' =\u003e [\n        'session_id' =\u003e '[REDACTED]'\n    ],\n];\n```\n\nYou can also receive your content back as json instead of an array.\n\n```php\n$login = [\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e 'secret123',\n    'data' =\u003e [\n        'session_id' =\u003e 'z481jf0an4kasnc8a84aj831'\n    ],\n];\n\n$redactor = (new ArrayRedactor($login, ['password', 'session_id']))-\u003eredactToJson();\n\n// $redactor will return:\n\"{\n\t\"email\": \"john_doe@domain.com\",\n\t\"password\": \"[REDACTED]\",\n\t\"data\": {\n\t\t\"session_id\": \"[REDACTED]\"\n\t}\n}\"\n```\n\nYou can change the redaction value (default: [REDACTED]), known as the ``ink``, by passing it as the third argument of the constructor, or using the dedicated ``-\u003eink()`` method.\n\n```php\n$login = [\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e 'secret123',\n    'data' =\u003e [\n        'session_id' =\u003e 'z481jf0an4kasnc8a84aj831'\n    ],\n];\n\n$redactor = (new ArrayRedactor($login, ['password', 'session_id'], null))-\u003eredact();\n// or...\n$redactor = (new ArrayRedactor($login, ['password', 'session_id']))-\u003eink(null)-\u003eredact();\n\n// $redactor will return:\n[\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e null,\n    'data' =\u003e [\n        'session_id' =\u003e null\n    ],\n];\n```\n\nYou can call the ``ArrayRedactor`` as a function and the magic ``__invoke()`` method will call the ``redact`` method for you.\n\n```php\n$login = [\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e 'secret123',\n    'data' =\u003e [\n        'session_id' =\u003e 'z481jf0an4kasnc8a84aj831'\n    ],\n];\n\n$redactor = (new ArrayRedactor($login, ['password', 'session_id'], null))();\n\n// $redactor will return:\n[\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e null,\n    'data' =\u003e [\n        'session_id' =\u003e null\n    ],\n];\n```\n\nLastly, you can skip the constructor arguments entirely if you prefer.\n\n```php\n$login = [\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e 'secret123',\n    'data' =\u003e [\n        'session_id' =\u003e 'z481jf0an4kasnc8a84aj831'\n    ],\n];\n\n$redactor = (new ArrayRedactor)-\u003econtent($login)-\u003ekeys(['password'])-\u003eink(null)-\u003eredact();\n\n// $redactor will return:\n[\n    'email' =\u003e 'john_doe@domain.com',\n    'password' =\u003e null,\n    'data' =\u003e [\n        'session_id' =\u003e 'z481jf0an4kasnc8a84aj831'\n    ],\n];\n```\n\n### Using the global helper\n\nThis package provides a convenient helper function which is globally accessible.\n\n```php\narray_redactor($array, $keys, $ink)-\u003eredact();\n// or...\narray_redactor()-\u003econtent($array)-\u003ekeys(['current_password', 'new_password'])-\u003eink('████████')-\u003eredact();\n```\n\n### Using the facade (Laravel users)\n\nIf you are using Laravel, this package provides a facade. To register the facade add the following line to your ``config/app.php`` under the ``aliases`` key.\n\n**Please note:** this is the only method for Laravel users that will prefill your ``keys`` and ``ink`` from your ``arrayredactor.php`` config file. The global helper and direct instantiation of the class will not prefill these values for you.\n\n````php\n'ArrayRedactor' =\u003e Mtownsend\\ArrayRedactor\\Facades\\ArrayRedactor::class,\n````\n\n```php\nuse ArrayRedactor;\n\n// Laravel prefills our keys() and ink() methods for us from the config file\nArrayRedactor::content($array)-\u003eredact();\n```\n\n## Error handling\n\nIn the event you pass content that is not valid json or an array, an ``ArrayRedactorException`` will be thrown.\n\n```php\ntry {\n    $redactor = (new ArrayRedactor('i am an invalid argument', ['password']))-\u003eredact();\n} catch (\\Mtownsend\\ArrayRedactor\\Exceptions\\ArrayRedactorException $exception) {\n    // do something...\n}\n```\n\n## Credits\n\n- Mark Townsend\n- [All Contributors](../../contributors)\n\n## Testing\n\nYou can run the tests with:\n\n```bash\n./vendor/bin/phpunit\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Farray-redactor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtownsend5512%2Farray-redactor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Farray-redactor/lists"}