ILIAS  trunk Revision v11.0_alpha-1843-g9e1fad99175
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
CertificateId.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
26 {
27  private const UUID_LENGTH = 36;
28  private const UUID_SEPARATOR_COUNT = 4;
29 
30  private readonly string $certificate_id;
31 
32  public function __construct(string $certificate_id)
33  {
34  if ($certificate_id === '') {
35  throw new InvalidArgumentException('certificate_id cannot be empty.');
36  }
37 
38  if (strlen($certificate_id) !== self::UUID_LENGTH) {
39  throw new InvalidArgumentException(sprintf(
40  'certificate_id must be a valid UUID. UUID must be %s characters long.',
41  self::UUID_LENGTH
42  ));
43  }
44 
45  if (substr_count($certificate_id, '-') !== 4) {
46  throw new InvalidArgumentException(sprintf(
47  'certificate_id must be a valid UUID. UUID must contain %s "-" characters.',
48  self::UUID_SEPARATOR_COUNT
49  ));
50  }
51  $this->certificate_id = $certificate_id;
52  }
53 
54  public function asString(): string
55  {
56  return $this->certificate_id;
57  }
58 }