ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
UTFNormal.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Refinery\String;
22 
24 use Symfony\Polyfill\Intl\Normalizer\Normalizer as PolyfillNormalizer;
25 use Normalizer as NativeNormalizer;
26 
27 class UTFNormal
28 {
29  protected ?Transformation $form_c = null;
30  protected ?Transformation $form_d = null;
33 
37  public function formC(): Transformation
38  {
39  if ($this->form_c === null) {
40  $this->form_c = $this->getNormalizer(NativeNormalizer::FORM_C);
41  }
42 
43  return $this->form_c;
44  }
45 
49  public function formD(): Transformation
50  {
51  if ($this->form_d === null) {
52  $this->form_d = $this->getNormalizer(NativeNormalizer::FORM_D);
53  }
54 
55  return $this->form_d;
56  }
57 
61  public function formKD(): Transformation
62  {
63  if ($this->form_kd === null) {
64  $this->form_kd = $this->getNormalizer(NativeNormalizer::FORM_KD);
65  }
66 
67  return $this->form_kd;
68  }
69 
73  public function formKC(): Transformation
74  {
75  if ($this->form_kc === null) {
76  $this->form_kc = $this->getNormalizer(NativeNormalizer::FORM_KC);
77  }
78 
79  return $this->form_kc;
80  }
81 
82  protected function getNormalizer($form): Transformation
83  {
84  if ($this->normalizerExists()) {
85  $normalizer = fn($from) => NativeNormalizer::normalize($from, $form);
86  } else {
87  $normalizer = fn($from) => PolyfillNormalizer::normalize($from, $form);
88  }
89 
90  return new \ILIAS\Refinery\Custom\Transformation($normalizer);
91  }
92 
93  protected function normalizerExists(): bool
94  {
95  return class_exists(NativeNormalizer::class) && method_exists(NativeNormalizer::class, 'normalize');
96  }
97 }
formC()
Normalization Form C (NFC), also known as Canonical Decomposition followed by Canonical Composition...
Definition: UTFNormal.php:37
formKC()
Normalization Form KD (NFKD), also known as Compatibility Decomposition.
Definition: UTFNormal.php:73
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
formKD()
Normalization Form KC (NFKC), also known as Compatibility Decomposition followed by Canonical Composi...
Definition: UTFNormal.php:61
A transformation is a function from one datatype to another.
formD()
Normalization Form D (NFD), also known as Canonical Decomposition.
Definition: UTFNormal.php:49