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