*/ private Map $inlineCount; /** * @var Map */ private Map $staticCount; public function __construct(?string $value = null) { if ($value === null || strlen($value) < self::MIN_BYTES) { $value = random_bytes(self::MIN_BYTES); $value = StringUtility::base64urlEncode($value); } $this->value = $value; $this->inlineCount = new Map(); $this->staticCount = new Map(); } public function __toString(): string { return $this->consumeInline(); } public function count(): int { return $this->countInline() + $this->countStatic(); } public function countInline(mixed $aspect = null): int { if ($aspect === null) { return array_sum($this->inlineCount->values()); } return $this->inlineCount[$aspect] ?? 0; } public function countStatic(mixed $aspect = null): int { if ($aspect === null) { return array_sum($this->staticCount->values()); } return $this->staticCount[$aspect] ?? 0; } /** * @internal consider using the more specific methods `consumeInline()` or `consumeStatic()` instead */ public function consume(): string { return $this->consumeInline(); } public function consumeInline(mixed $aspect = 'default'): string { // `\TYPO3\CMS\Core\Type\Map::offsetGet would` have to be `&offsetGet` for increments to work $this->inlineCount[$aspect] = ($this->inlineCount[$aspect] ?? 0) + 1; return $this->value; } public function consumeStatic(mixed $aspect = 'default'): string { // `\TYPO3\CMS\Core\Type\Map::offsetGet would` have to be `&offsetGet` for increments to work $this->staticCount[$aspect] = ($this->staticCount[$aspect] ?? 0) + 1; return $this->value; } }