ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\KeyValueStorage\Internal\StorageNamespace Class Reference

Isolates the keys of one consumer from every other consumer of a storage. More...

+ Inheritance diagram for ILIAS\KeyValueStorage\Internal\StorageNamespace:
+ Collaboration diagram for ILIAS\KeyValueStorage\Internal\StorageNamespace:

Public Member Functions

 __construct (array $segments)
 
 value ()
 
 __toString ()
 

Data Fields

const int MAX_LENGTH = 128
 

Private Attributes

const string SEPARATOR = '.'
 
const string FORBIDDEN_PATTERN = '/[\x00-\x1F\x7F' . self::SEPARATOR . KeyRules::SEPARATOR . ']/'
 Characters that must not appear inside a segment: the segment separator, {. More...
 
string $value
 

Detailed Description

Isolates the keys of one consumer from every other consumer of a storage.

Built from namespace segments so consumers of {

See also
\ILIAS\KeyValueStorage\Services} never choose the delimiter. Repositories receive this value object on the port boundary.

Segments are otherwise permissive: the only characters rejected are those that would break composition — the segment separator, the namespace/key separator used by repositories, and control characters.

Definition at line 36 of file StorageNamespace.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\KeyValueStorage\Internal\StorageNamespace::__construct ( array  $segments)
Parameters
list<string>$segments

Definition at line 53 of file StorageNamespace.php.

54 {
55 if ($segments === []) {
56 throw new \InvalidArgumentException('A storage namespace must not be empty.');
57 }
58
59 foreach ($segments as $index => $segment) {
60 if (!\is_string($segment)) {
61 throw new \InvalidArgumentException(
62 'A storage namespace segment must be a string, got ' . \get_debug_type($segment)
63 . ' at position ' . $index . '.'
64 );
65 }
66
67 if ($segment === '') {
68 throw new \InvalidArgumentException('A storage namespace segment must not be empty.');
69 }
70
71 if (\preg_match(self::FORBIDDEN_PATTERN, $segment) === 1) {
72 throw new \InvalidArgumentException(
73 'A storage namespace segment must not contain "' . self::SEPARATOR . '", "'
74 . KeyRules::SEPARATOR . '" or control characters, got "' . $segment . '".'
75 );
76 }
77 }
78
79 $value = \implode(self::SEPARATOR, $segments);
80
81 $length = \mb_strlen($value, 'UTF-8');
82 if ($length > self::MAX_LENGTH) {
83 throw new \InvalidArgumentException(
84 'A storage namespace must not be longer than ' . self::MAX_LENGTH
85 . ' characters, got ' . $length . '.'
86 );
87 }
88
89 $this->value = $value;
90 }

References ILIAS\KeyValueStorage\Internal\StorageNamespace\$value, ILIAS\KeyValueStorage\Internal\KeyRules\SEPARATOR, and ILIAS\KeyValueStorage\Internal\StorageNamespace\value().

+ Here is the call graph for this function:

Member Function Documentation

◆ __toString()

ILIAS\KeyValueStorage\Internal\StorageNamespace::__toString ( )

Definition at line 97 of file StorageNamespace.php.

97 : string
98 {
99 return $this->value;
100 }

References ILIAS\KeyValueStorage\Internal\StorageNamespace\$value.

◆ value()

ILIAS\KeyValueStorage\Internal\StorageNamespace::value ( )

Field Documentation

◆ $value

◆ FORBIDDEN_PATTERN

const string ILIAS\KeyValueStorage\Internal\StorageNamespace::FORBIDDEN_PATTERN = '/[\x00-\x1F\x7F' . self::SEPARATOR . KeyRules::SEPARATOR . ']/'
private

Characters that must not appear inside a segment: the segment separator, {.

See also
KeyRules::SEPARATOR}, and ASCII control characters.

Definition at line 46 of file StorageNamespace.php.

◆ MAX_LENGTH

◆ SEPARATOR

const string ILIAS\KeyValueStorage\Internal\StorageNamespace::SEPARATOR = '.'
private

Definition at line 40 of file StorageNamespace.php.


The documentation for this class was generated from the following file: