Model » Advanced field encryption with field aliases

Combining the power of Mondoc field encryption with Mondoc field aliases, to give you the best of both worlds.

Using Mondoc field encryption alongside field aliases

Mondoc supports the use of aliases, which are a way to map a field name to a different name in MongoDB. This is useful for when you want to use a different name for a field in your model, but still want to store it with a different name in MongoDB, for example, you may use $dateOfBirth in your model, but want to store it as 'dob' in MongoDB.

To do this, you'd still define your $mondocEncrypted property as you would normally, but also define the $mondocFieldAliases property.

<?php

class MyModelWithFieldAliases extends \District5\Mondoc\Db\Model\MondocAbstractModel
{
    /**
     * @var string
     */
    protected string $name;

    /**
     * @var DateTime
     */
    protected DateTime $dateOfBirth;

    /**
     * @var string
     */
    protected string $socialSecurityNumber;

    /**
     * @var string[]
     */
    protected array $mondocEncrypted = [
        'dateOfBirth',
        'socialSecurityNumber',
    ];

    /**
     * @var string[]
     */
    protected array $mondocFieldAliases = [
        'dob' => 'dateOfBirth',
        'ssn' => 'socialSecurityNumber',
    ];

    // add any getters/setters you need below
}

array(7) {
  ["topLevel"]=>
  bool(true)
  ["navTitle"]=>
  string(18) "Documentation home"
  ["view"]=>
  string(18) "documentation-view"
  ["pageName"]=>
  string(13) "Documentation"
  ["breadcrumb"]=>
  array(1) {
    ["Documentation"]=>
    NULL
  }
  ["text"]=>
  string(79) "The core documentation for Mondoc. This is the home page for the documentation."
  ["link"]=>
  string(14) "/documentation"
}
NULL