diff --git a/README.md b/README.md index 4c785ec..290436a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ JSON API support turned on by default - see `Turn off JSON API support` section * [Tree structures](#user-content-tree-structures) * [Finite-state machine](#user-content-finite-state-machine) * [Spell check](#user-content-spell-check) +* [Bit mask](#user-content-bit-mask) * [Custom SQL](#user-content-custom-sql) * [Conversions to RAML](#user-content-conversions-to-raml) @@ -964,6 +965,75 @@ You'll get the `meta` content back with filled array of failed checks in it: } ``` +### Bit Mask +To use bit mask with automatic flags fragmentation/defragmentation +You can define additional facets to an integer field like this: +```RAML + permissions: + type: integer + required: false + maximum: 20 + facets: + bit_mask: + publisher: 1 + editor: 2 + manager: 4 + photo_reporter: 8 + admin: 16 +``` +thus the config entity `bit_mask` will be generated and used on runtime within requests to process data. + +Generated config snippet: +```php +'bit_mask'=> [ + 'user'=> [ + 'permissions'=> [ + 'enabled' => true, + 'flags'=> [ + 'publisher' => 1, + 'editor' => 2, + 'manager' => 4, + 'photo_reporter' => 8, + 'admin' => 16, + ], + ], + ], +], +``` + +And the request/response will be: +```json +{ + "data": { + "type":"user", + "attributes": { + "publisher": false, + "editor": true, + "manager": false, + "photo_reporter": true, + "admin": true + } + } +} +``` + +```json +{ + "data": { + "type": "user", + "id": "1", + "attributes": { + "first_name": "Alice", + "last_name": "Hacker", + "permissions": 26, + "publisher": false, + "editor": true, + "manager": false, + "photo_reporter": true, + "admin": true, +``` +Recall that U can always hide ex.: `permissions` field in index/view GET requests if U'd like. + ### Custom SQL If by any reason You need to use custom sql query - just define it in `Modules/V1/Config/config.php`: ```php diff --git a/src/blocks/ConfigTrait.php b/src/blocks/ConfigTrait.php index 6d93480..3779878 100644 --- a/src/blocks/ConfigTrait.php +++ b/src/blocks/ConfigTrait.php @@ -94,7 +94,6 @@ private function openBitMask(string $entity, string $field) $this->openEntity(strtolower($entity), 2); $this->openEntity(strtolower($field), 3); $this->setParam(ConfigInterface::ENABLED, PhpInterface::PHP_TYPES_BOOL_TRUE, 4); - $this->setParam(ConfigInterface::HIDE_MASK, PhpInterface::PHP_TYPES_BOOL_TRUE, 4); $this->openEntity(ConfigInterface::FLAGS, 4); }