Capabilities

class \TYPO3\CMS\Core\Resource\Capabilities

Extends
BitSet

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

Table of Contents

Constants

CAPABILITY_BROWSABLE  : mixed = 1
Capability for being browsable by (backend) users
CAPABILITY_HIERARCHICAL_IDENTIFIERS  : mixed = 8
Whether identifiers contain hierarchy information (folder structure).
CAPABILITY_PUBLIC  : mixed = 2
Capability for publicly accessible storages (= accessible from the web)
CAPABILITY_WRITABLE  : mixed = 4
Capability for writable storages. This only signifies writability in general - this might also be further limited by configuration.

Properties

$set  : int

Methods

__construct()  : mixed
__toInt()  : int
Returns the integer representation of the internal set.
__toString()  : string
Returns the (binary) string representation of the internal (integer) set.
addCapabilities()  : $this
and()  : void
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.
andNot()  : void
Clears all of the bits in this BitSet whose corresponding bit is set in the specified BitSet.
clear()  : void
Sets all of the bits in this BitSet to false.
get()  : bool
hasCapability()  : bool
or()  : void
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.
removeCapability()  : $this
set()  : void
Performs the same operation as {@see or()} without the need to create a BitSet instance from an integer value.
setValue()  : void
unset()  : void
Performs the same operation as {@see andNot()} without the need to create a BitSet instance from an integer value.
xor()  : void
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:

Constants

CAPABILITY_BROWSABLE

Capability for being browsable by (backend) users

public mixed CAPABILITY_BROWSABLE = 1

CAPABILITY_HIERARCHICAL_IDENTIFIERS

Whether identifiers contain hierarchy information (folder structure).

public mixed CAPABILITY_HIERARCHICAL_IDENTIFIERS = 8

CAPABILITY_PUBLIC

Capability for publicly accessible storages (= accessible from the web)

public mixed CAPABILITY_PUBLIC = 2

CAPABILITY_WRITABLE

Capability for writable storages. This only signifies writability in general - this might also be further limited by configuration.

public mixed CAPABILITY_WRITABLE = 4

Properties

Methods

__construct()

public __construct([int $set = 0 ]) : mixed

Parameters

$set : int = 0

__toInt()

Returns the integer representation of the internal set.

public __toInt() : int

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

Return values

int

__toString()

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

public __toString() : string

Return values

string

addCapabilities()

public addCapabilities(self::CAPABILITY_* ...$capabilities) : $this

Parameters

$capabilities : self::CAPABILITY_*

Return values

$this

and()

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.

public and(BitSet $set) : void

Parameters

$set : BitSet

andNot()

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

public andNot(BitSet $set) : void

Parameters

$set : BitSet

clear()

Sets all of the bits in this BitSet to false.

public clear() : void

get()

public get(int $bitIndex) : bool

Parameters

$bitIndex : int

Return values

bool

hasCapability()

public hasCapability(self::CAPABILITY_* $capability) : bool

Parameters

$capability : self::CAPABILITY_*

Return values

bool

or()

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.

public or(BitSet $set) : void

Parameters

$set : BitSet

removeCapability()

public removeCapability(self::CAPABILITY_* $capability) : $this

Parameters

$capability : self::CAPABILITY_*

Return values

$this

set()

Performs the same operation as {@see or()} without the need to create a BitSet instance from an integer value.

public set(int $bitIndex) : void

Parameters

$bitIndex : int

setValue()

public setValue(int $bitIndex, bool $value) : void

Parameters

$bitIndex : int
$value : bool

unset()

Performs the same operation as {@see andNot()} without the need to create a BitSet instance from an integer value.

public unset(int $bitIndex) : void

Parameters

$bitIndex : int

xor()

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:

public xor(BitSet $set) : void
  • 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

$set : BitSet
On this page