ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
DataValidatorService.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
28 {
31  protected LangValidator $lang;
33  protected NullValidator $null;
37 
38  public function __construct(
39  VocabulariesInterface $vocabularies,
40  DataHelperInterface $data_helper
41  ) {
42  $this->datetime = new DatetimeValidator($data_helper);
43  $this->duration = new DurationValidator($data_helper);
44  $this->lang = new LangValidator($data_helper);
45  $this->non_neg_int = new NonNegIntValidator();
46  $this->null = new NullValidator();
47  $this->string = new StringValidator();
48  $this->vocab_source = new VocabSourceValidator($vocabularies);
49  $this->vocab_value = new VocabValueValidator($vocabularies);
50  }
51 
52  public function validator(Type $type): DataValidatorInterface
53  {
54  switch ($type) {
55  case Type::NULL:
56  return $this->null;
57 
58  case Type::STRING:
59  return $this->string;
60 
61  case Type::LANG:
62  return $this->lang;
63 
64  case Type::VOCAB_SOURCE:
65  return $this->vocab_source;
66 
67  case Type::VOCAB_VALUE:
68  return $this->vocab_value;
69 
70  case Type::DATETIME:
71  return $this->datetime;
72 
73  case Type::NON_NEG_INT:
74  return $this->non_neg_int;
75 
76  case Type::DURATION:
77  return $this->duration;
78  }
79  throw new \ilMDRepositoryException(
80  'Unhandled data type when validating.'
81  );
82  }
83 }
__construct(VocabulariesInterface $vocabularies, DataHelperInterface $data_helper)