ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
SubjectId.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29final readonly class SubjectId
30{
31 public const int MAX_LENGTH = 128;
32
33 private string $provider;
34 private string $provider_class;
35
36 public function __construct(SubjectProvider $provider, private string $id)
37 {
38 $this->provider = $provider->name();
39 $this->provider_class = $provider::class;
40
41 $this->assertIdentifier(
42 $this->provider,
44 '/^[a-z][a-z0-9_]*$/',
45 'Subject provider name'
46 );
47 $this->assertIdentifier($id, self::MAX_LENGTH, '/^[a-z0-9_]+$/', 'Subject id');
48 }
49
50 public function provider(): string
51 {
52 return $this->provider;
53 }
54
55 public function id(): string
56 {
57 return $this->id;
58 }
59
64 public function providerClass(): string
65 {
67 }
68
69 private function assertIdentifier(string $value, int $max_length, string $pattern, string $what): void
70 {
71 if ($value === '') {
72 throw new \InvalidArgumentException($what . ' must not be empty.');
73 }
74
75 $length = \mb_strlen($value, 'UTF-8');
76 if ($length > $max_length) {
77 throw new \InvalidArgumentException(
78 $what . ' must not exceed ' . $max_length . ' characters, got ' . $length . '.'
79 );
80 }
81
82 if (!\preg_match($pattern, $value)) {
83 throw new \InvalidArgumentException(
84 $what . ' must be a lowercase identifier, got "' . $value . '".'
85 );
86 }
87 }
88}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Identifies a subject within the provider that names it.
Definition: SubjectId.php:30
__construct(SubjectProvider $provider, private string $id)
Definition: SubjectId.php:36
assertIdentifier(string $value, int $max_length, string $pattern, string $what)
Definition: SubjectId.php:69
A component that names subjects, contributed via $contribute[\ILIAS\KeyValueStorage\Subject\SubjectPr...
name()
Unique among all providers, a lowercase identifier, e.g.