Skip to content

Commit

Permalink
* #79. del hide_mask conf + readme
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Jun 27, 2017
1 parent c1153ae commit 06f34de
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/blocks/ConfigTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 06f34de

Please sign in to comment.