district5 / mondoc-encryption
Mondoc encryption provides the encrypt/decrypt functionality for Mondoc.
Requires
- php: ~8.2.35 || ~8.3.36 || ~8.4.27 || >=8.5.12
Requires (Dev)
Suggests
- ext-sodium: Required if leveraging Sodium secret key encryption
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-20 15:05:31 UTC
README
Provides the encryption function to Mondoc
Installing with composer
Mondoc Encryption is used by, and leverages functionality from, the Mondoc library. You will need to install Mondoc in order to use Mondoc Encryption.
composer require district5/mondoc
Documentation...
All documentation for Mondoc Encryption, Mondoc, and Mondoc Builder are available at mondoc.district5.dev.
Common topics...
- Getting started with encryption: mondoc.district5.dev/documentation/model/field-encryption
Testing
Requires a PHP2Shell-patched PHP: ~8.2.35 || ~8.3.36 || ~8.4.27 || >=8.5.12.
Run composer install, then:
# Unit tests only (no database needed) ./vendor/bin/phpunit --testsuite TestSuite # Everything, including the Integration suite, which saves encrypted Mondoc models to a real MongoDB docker run -d --rm --name mongo -p 27017:27017 mongo:8 MONGO_CONNECTION_STRING='mongodb://localhost:27017' ./vendor/bin/phpunit
CI runs both suites on PHP 8.2–8.6 against MongoDB 7 and 8 service containers.
Creating a new encryption adapter
To create a new encryption adapter, you need to implement the EncryptionAdapterInterface interface, which requires the
following methods:
/** * Encrypt the field value. */ public function encrypt(string $field, mixed $value): mixed; /** * Decrypt the field value. */ public function decrypt(string $field, mixed $value): mixed;