‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Type\BitSet Class Reference
Inheritance diagram for TYPO3\CMS\Core\Type\BitSet:
TYPO3\CMS\Core\Authentication\JsConfirmation TYPO3\CMS\Core\Resource\Capabilities TYPO3\CMS\Core\Type\Bitmask\BackendGroupMountOption TYPO3\CMS\Core\Type\Bitmask\PageTranslationVisibility TYPO3\CMS\Core\Type\Bitmask\Permission TYPO3\CMS\Extbase\Reflection\ClassSchema\PropertyCharacteristics

Public Member Functions

 __construct (int $set=0)
 
 set (int $bitIndex)
 
 setValue (int $bitIndex, bool $value)
 
 unset (int $bitIndex)
 
 get (int $bitIndex)
 
 clear ()
 
 and (BitSet $set)
 
 or (BitSet $set)
 
 xor (BitSet $set)
 
 andNot (BitSet $set)
 
 __toInt ()
 
 __toString ()
 

Protected Attributes

int $set
 

Detailed Description

The BitSet class is a helper class to manage bit sets. It eases the work with bits and bitwise operations by providing a reliable and tested API.

The class can be used standalone or as a parent for more verbose classes that handle bit sets.

The functionality is best described by an example:

define('PERMISSIONS_NONE', 0b0); // 0
define('PERMISSIONS_PAGE_SHOW', 0b1); // 1
define('PERMISSIONS_PAGE_EDIT', 0b10); // 2
define('PERMISSIONS_PAGE_DELETE', 0b100); // 4
$bitSet = new \TYPO3\CMS\Core\Type\BitSet(PERMISSIONS_PAGE_SHOW | PERMISSIONS_PAGE_EDIT);
$bitSet->get(PERMISSIONS_PAGE_SHOW); // true
$bitSet->get(PERMISSIONS_PAGE_DELETE); // false

Another example shows how to possibly extend the class:

class Permissions extends ‪\TYPO3\CMS\Core\Type\BitSet
{
public const NONE = 0b0; // 0
public const PAGE_SHOW = 0b1; // 1
public function isGranted(int $permission): bool
{
return $this->get($permission);
}
public function grant(int $permission): void
{
$this->set($permission);
}
}
$permissions = new Permissions();
$permissions->isGranted(Permissions::PAGE_SHOW); // false
$permissions->grant(Permissions::PAGE_SHOW);
$permissions->isGranted(Permissions::PAGE_SHOW); // true

Definition at line 65 of file BitSet.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Type\BitSet::__construct ( int  $set = 0)

Definition at line 71 of file BitSet.php.

References TYPO3\CMS\Core\Type\BitSet\$set.

Member Function Documentation

◆ __toInt()

TYPO3\CMS\Core\Type\BitSet::__toInt ( )

Returns the integer representation of the internal set. (As PHP does not know a byte type, the internal set is already handled as an integer and can therefore directly be returned)

Definition at line 165 of file BitSet.php.

References TYPO3\CMS\Core\Type\BitSet\$set.

Referenced by TYPO3\CMS\Core\Type\BitSet\and(), TYPO3\CMS\Core\Type\BitSet\andNot(), TYPO3\CMS\Core\Type\BitSet\or(), and TYPO3\CMS\Core\Type\BitSet\xor().

◆ __toString()

TYPO3\CMS\Core\Type\BitSet::__toString ( )

Returns the (binary) string representation of the internal (integer) set.

Definition at line 173 of file BitSet.php.

◆ and()

TYPO3\CMS\Core\Type\BitSet::and ( BitSet  $set)

Performs a logical AND of this target bit set with the argument bit set. This bit set is modified so that each bit in it has the value true if and only if it both initially had the value true and the corresponding bit in the bit set argument also had the value true.

Definition at line 121 of file BitSet.php.

References TYPO3\CMS\Core\Type\BitSet\__toInt().

◆ andNot()

TYPO3\CMS\Core\Type\BitSet::andNot ( BitSet  $set)

Clears all of the bits in this BitSet whose corresponding bit is set in the specified BitSet.

Definition at line 155 of file BitSet.php.

References TYPO3\CMS\Core\Type\BitSet\__toInt().

◆ clear()

TYPO3\CMS\Core\Type\BitSet::clear ( )

Sets all of the bits in this BitSet to false.

Definition at line 111 of file BitSet.php.

◆ get()

TYPO3\CMS\Core\Type\BitSet::get ( int  $bitIndex)

Definition at line 103 of file BitSet.php.

◆ or()

TYPO3\CMS\Core\Type\BitSet::or ( BitSet  $set)

Performs a logical OR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if it either already had the value true or the corresponding bit in the bit set argument has the value true.

Definition at line 131 of file BitSet.php.

References TYPO3\CMS\Core\Type\BitSet\__toInt().

◆ set()

TYPO3\CMS\Core\Type\BitSet::set ( int  $bitIndex)

Performs the same operation as {

See also
or()} without the need to create a BitSet instance from an integer value.

Definition at line 80 of file BitSet.php.

◆ setValue()

TYPO3\CMS\Core\Type\BitSet::setValue ( int  $bitIndex,
bool  $value 
)

Definition at line 85 of file BitSet.php.

References TYPO3\CMS\Core\Type\BitSet\unset().

◆ unset()

TYPO3\CMS\Core\Type\BitSet::unset ( int  $bitIndex)

Performs the same operation as {

See also
andNot()} without the need to create a BitSet instance from an integer value.

Definition at line 98 of file BitSet.php.

Referenced by TYPO3\CMS\Core\Resource\Capabilities\removeCapability(), and TYPO3\CMS\Core\Type\BitSet\setValue().

◆ xor()

TYPO3\CMS\Core\Type\BitSet::xor ( BitSet  $set)

Performs a logical XOR of this bit set with the bit set argument. This bit set is modified so that a bit in it has the value true if and only if one of the following statements holds:

  • ‪The bit initially has the value true, and the corresponding bit in the argument has the value false.
  • ‪The bit initially has the value false, and the corresponding bit in the argument has the value true.
Parameters
BitSet$set

Definition at line 147 of file BitSet.php.

References TYPO3\CMS\Core\Type\BitSet\__toInt().

Referenced by TYPO3\CMS\Core\Type\Bitmask\PageTranslationVisibility\shouldHideTranslationIfNoTranslatedRecordExists().

Member Data Documentation

◆ $set

int TYPO3\CMS\Core\Type\BitSet::$set
protected
‪TYPO3\CMS\Core\Type\BitSet
Definition: BitSet.php:66