Skip to content

feat: add encrypted JSON casts#10385

Open
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/encrypted-json-casts
Open

feat: add encrypted JSON casts#10385
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/encrypted-json-casts

Conversation

@memleakd

@memleakd memleakd commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds encrypted-json and encrypted-json-array casts for Entity properties and Model fields.

This builds on the recently added encrypted cast and adds support for structured values. The values are JSON encoded first, then encrypted before they are stored. When read back, they are decrypted and decoded again.

This is useful when the application needs array/object access in PHP, but encrypted text at rest.

protected array $casts = [
    'settings' => 'encrypted-json-array',
];

encrypted-json returns stdClass, and encrypted-json-array returns arrays. Nullable values can be handled with ?encrypted-json and ?encrypted-json-array.

The implementation reuses the existing JsonCast and EncryptedCast, so this follows the same behavior as the current JSON and encrypted casts. The stored database value is still encrypted text, not queryable JSON.

Tests were added for direct casting, nullable values, invalid payloads, DataConverter, and Entity usage.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

- Add encrypted-json and encrypted-json-array cast types
- Reuse existing JSON and encrypted cast handling
- Cover nullable values, invalid payloads, DataConverter, and Entity usage
- Update Model and Entity docs

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant