addType('itemId', 'integer'); $this->addType('vaultId', 'integer'); $this->addType('permissions', 'integer'); } /** * Checks wether a user matches one or more permissions at once * @param $permission * @return bool */ public function hasPermission($permission) { $tmp = $this->getPermissions(); $tmp = $tmp & $permission; return $tmp == $permission; } /** * Adds the given permission or permissions set to the user current permissions * @param $permission */ public function addPermission($permission) { $tmp = $this->getPermissions(); $tmp = $tmp | $permission; $this->setPermissions($tmp); } /** * Takes the given permission or permissions out from the user * @param $permission */ public function removePermission($permission) { $tmp = $this->getPermissions(); $tmp = $tmp & !$permission; $this->setPermissions($tmp); } /** * Specify data which should be serialized to JSON * @link http://php.net/manual/en/jsonserializable.jsonserialize.php * @return mixed data which can be serialized by json_encode, * which is a value of any type other than a resource. * @since 5.4.0 */ function jsonSerialize() { return [ 'req_id' => $this->getId(), 'item_id' => $this->getItemId(), 'item_guid' => $this->getItemGuid(), 'shared_key' => $this->getSharedKey(), 'permissions' => $this->getPermissions(), 'created' => $this->getCreated(), ]; } }