maskDocument.php
Table of Contents
Functions
- maskDocument() : array<string|int, mixed>
- Applies a list of attribute masking rules to a single document.
Functions
maskDocument()
Applies a list of attribute masking rules to a single document.
maskDocument(array<string|int, mixed> $doc, array<string|int, mixed> $maskings[, array<int, string> $protectedAttributes = [] ]) : array<string|int, mixed>
This is a portable, self-contained masking engine. Each rule is
{ "path": …, "type": <masker>, …params }; the supported path forms are:
"name"— a leaf attributenameat the top level ;"a.b"— the exact nested patha→b(through objects only) ;".name"— every leaf attribute namedname, at any depth ;"*"— every leaf attribute ;"`a.b`"— a literal attribute name containing dots (backtick/tick quoted).
A leaf is a value that is null, a scalar or a JSON array; objects are
descended into. When a matched leaf is an array, the masker is applied to its
elements individually (see maskValue()). When several rules match the
same leaf, the first one in the list wins.
The attributes named in $protectedAttributes are never masked at the
top level, even by a * rule — use this to preserve identity fields. The
default is an empty list (nothing protected), so the engine stays agnostic of
any particular data store: supply the identity fields of your model yourself
(e.g. ['_key','_id','_rev','_from','_to'] for ArangoDB, ['_id'] for
MongoDB, ['id'] for a relational row).
Parameters
- $doc : array<string|int, mixed>
-
The document (decoded JSON object).
- $maskings : array<string|int, mixed>
-
The list of rules for this collection.
- $protectedAttributes : array<int, string> = []
-
Top-level attribute names never masked. Default: none.
Tags
Return values
array<string|int, mixed> —The masked document.