gryfoss / twig-anonymize
Basic anonymize filter which leaves first and last letter and replaces rest with asterisks.
Requires
- twig/twig: ^2.12|^3.0
Requires (Dev)
- behat/behat: ^3.13
- phpunit/phpunit: ^9.5|^10.0|^11.0
README
Basic Twig Anonymize extension which allows you to anonymize texts in your twig
frontend. It keeps first and last letter (if string longer than 2) and replaces the
rest with symbols (asterisks by default).
.
If you have a variable called mytext
then you can anonymize it by typing:
{{ mytext|anonymize }}
Filter has few options:
- keepLength: determines if original lenght of the text should be left intact or should it minify the hidden part.
- replacementChar: character to be used in for the replacement. Defaults to *.
For example:
{{ mytext|anonymize(false, '!') }}
will not keep original length (replace with 3 symbols) and use '!' as the replacement char.
Warning: replacement length is always at least 3 symbols long, no matter the
keepLength
setting.
Installation
Install using composer:
composer require gryfoss/twig-anonymize
Since this is not a bundle for Symfony or any other framework but just a simple filter you may need to tell your framework how to look for the filter.
In Symfony, in your services.yaml
, add under services
:
gryfoss.twig.anonymize_extension: class: GryfOSS\Twig\Extension\AnonymizeExtension tags: - { name: twig.extension }
Contributing
We welcome contributions from everyone! Whether you're fixing bugs, adding new features, or improving documentation, your help is appreciated.
How to contribute:
- 🐛 Report issues: Found a bug? Open an issue to let us know
- 💡 Feature requests: Have an idea for improvement? Create a feature request
- 🔧 Pull requests: Ready to contribute code? Submit a pull request
- 📖 Documentation: Help improve the documentation by submitting updates
Development setup:
- Fork the repository
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/twig-anonymize.git
- Install dependencies:
composer install
- Run tests:
composer test-all
- Make your changes
- Ensure 100% test coverage:
composer check-coverage
- Submit a pull request
All contributions must maintain 100% test coverage and pass all quality checks. Our automated CI/CD pipeline will verify this when you submit your pull request.
Thank you for contributing! 🎉