PHP Class Tools\Model\Behavior\BitmaskedBehavior

An implementation of bitwise masks for row-level operations. You can submit/register flags in different ways. The easiest way is using a static model function. It should contain the bits like so (starting with 1): 1 => w, 2 => x, 4 => y, 8 => z, ... (bits as keys - names as values) The order doesn't matter, as long as no bit is used twice. The theoretical limit for a 64-bit integer would be 64 bits (2^64). But if you actually seem to need more than a hand full you obviously do something wrong and should better use a joined table etc.
Inheritance: extends Cake\ORM\Behavior
Exibir arquivo Open project: dereuromark/cakephp-tools Class Usage Examples

Protected Properties

Property Type Description
$_defaultConfig array Default config

Public Methods

Method Description
beforeFind ( Cake\Event\Event $event, Query $query ) : void
beforeRules ( Cake\Event\Event $event, Cake\ORM\Entity $entity, ArrayObject $options ) : void
beforeSave ( Cake\Event\Event $event, Cake\ORM\Entity $entity, ArrayObject $options ) : void
containsBit ( integer | array $bits ) : array
containsNotBit ( integer | array $bits ) : array
decodeBitmask ( integer $value ) : array
encodeBitmask ( array $value, mixed $defaultValue = null ) : integer
encodeBitmaskConditions ( Query $query ) : void
encodeBitmaskData ( Cake\ORM\Entity $entity ) : void
initialize ( array $config = [] ) : void Behavior configuration
isBit ( integer | array $bits ) : array
isNotBit ( integer | array $bits ) : array

Protected Methods

Method Description
_containsBit ( integer | array $bits, boolean $contain = true ) : array

Method Details

_containsBit() protected method

protected _containsBit ( integer | array $bits, boolean $contain = true ) : array
$bits integer | array
$contain boolean
return array SQL snippet.

beforeFind() public method

public beforeFind ( Cake\Event\Event $event, Query $query ) : void
$event Cake\Event\Event
$query Cake\ORM\Query
return void

beforeRules() public method

public beforeRules ( Cake\Event\Event $event, Cake\ORM\Entity $entity, ArrayObject $options ) : void
$event Cake\Event\Event
$entity Cake\ORM\Entity
$options ArrayObject
return void

beforeSave() public method

public beforeSave ( Cake\Event\Event $event, Cake\ORM\Entity $entity, ArrayObject $options ) : void
$event Cake\Event\Event
$entity Cake\ORM\Entity
$options ArrayObject
return void

containsBit() public method

public containsBit ( integer | array $bits ) : array
$bits integer | array
return array SQL snippet.

containsNotBit() public method

public containsNotBit ( integer | array $bits ) : array
$bits integer | array
return array SQL snippet.

decodeBitmask() public method

public decodeBitmask ( integer $value ) : array
$value integer Bitmask.
return array Bitmask array (from DB to APP).

encodeBitmask() public method

public encodeBitmask ( array $value, mixed $defaultValue = null ) : integer
$value array Bitmask array.
$defaultValue mixed Default bitmask value.
return integer Bitmask (from APP to DB).

encodeBitmaskConditions() public method

public encodeBitmaskConditions ( Query $query ) : void
$query Cake\ORM\Query
return void

encodeBitmaskData() public method

public encodeBitmaskData ( Cake\ORM\Entity $entity ) : void
$entity Cake\ORM\Entity
return void

initialize() public method

Behavior configuration
public initialize ( array $config = [] ) : void
$config array
return void

isBit() public method

public isBit ( integer | array $bits ) : array
$bits integer | array
return array SQL snippet.

isNotBit() public method

public isNotBit ( integer | array $bits ) : array
$bits integer | array
return array SQL snippet.

Property Details

$_defaultConfig protected_oe property

Default config
protected array $_defaultConfig
return array