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

The rules every storage key has to follow. More...

+ Collaboration diagram for ILIAS\KeyValueStorage\Internal\KeyRules:

Public Member Functions

 check (string $key)
 

Data Fields

const int MAX_LENGTH = 255
 
const string SEPARATOR = ':'
 

Private Attributes

const string FORBIDDEN_PATTERN = '/[\x00-\x1F\x7F' . self::SEPARATOR . ']/'
 

Detailed Description

The rules every storage key has to follow.

Keys are deliberately permissive: they are handed in by consumers, often derived from class names or object ids, and this component is not a PSR-16 cache that would have to keep its keys interchangeable with one.

Only what would break a storage is rejected: the colon, which separates namespace from key when a repository has to compose both into one identifier, and control characters, which cannot be stored or compared reliably.

Definition at line 36 of file KeyRules.php.

Member Function Documentation

◆ check()

ILIAS\KeyValueStorage\Internal\KeyRules::check ( string  $key)

Definition at line 44 of file KeyRules.php.

44 : void
45 {
46 if ($key === '') {
47 throw new \InvalidArgumentException('A storage key must not be empty.');
48 }
49
50 if (\mb_strlen($key, 'UTF-8') > self::MAX_LENGTH) {
51 throw new \InvalidArgumentException(
52 'A storage key must not be longer than ' . self::MAX_LENGTH . ' characters, got '
53 . \mb_strlen($key, 'UTF-8') . '.'
54 );
55 }
56
57 if (\preg_match(self::FORBIDDEN_PATTERN, $key) === 1) {
58 throw new \InvalidArgumentException(
59 'A storage key must not contain "' . self::SEPARATOR . '" or control characters.'
60 );
61 }
62 }

Field Documentation

◆ FORBIDDEN_PATTERN

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

Definition at line 42 of file KeyRules.php.

◆ MAX_LENGTH

◆ SEPARATOR


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