ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Factory.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3/* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5namespace ILIAS\Validation;
6
7use ILIAS\Data;
8
13{
14 const LANGUAGE_MODULE = "validation";
15
19 protected $data_factory;
20
24 protected $lng;
25
31 public function __construct(Data\Factory $data_factory, \ilLanguage $lng)
32 {
33 $this->data_factory = $data_factory;
34 $this->lng = $lng;
35 $this->lng->loadLanguageModule(self::LANGUAGE_MODULE);
36 }
37
38
39 // COMBINATORS
40
49 public function sequential(array $others)
50 {
51 return new Constraints\Sequential($others, $this->data_factory, $this->lng);
52 }
53
62 public function parallel(array $others)
63 {
64 return new Constraints\Parallel($others, $this->data_factory, $this->lng);
65 }
66
73 public function not(Constraint $other)
74 {
75 return new Constraints\Not($other, $this->data_factory, $this->lng);
76 }
77
83 public function or(array $others)
84 {
85 return new Constraints\LogicalOr($others, $this->data_factory, $this->lng);
86 }
87
88 // SOME RESTRICTIONS
89
95 public function isInt()
96 {
97 return new Constraints\IsInt($this->data_factory, $this->lng);
98 }
99
100
106 public function isString()
107 {
108 return new Constraints\IsString($this->data_factory, $this->lng);
109 }
110
111
119 public function isArrayOf(Constraint $on_element)
120 {
121 return new Constraints\IsArrayOf($this->data_factory, $on_element, $this->lng);
122 }
123
130 public function greaterThan($min)
131 {
132 return new Constraints\GreaterThan($min, $this->data_factory, $this->lng);
133 }
134
141 public function lessThan($max)
142 {
143 return new Constraints\LessThan($max, $this->data_factory, $this->lng);
144 }
145
151 public function isNumeric()
152 {
153 return new Constraints\IsNumeric($this->data_factory, $this->lng);
154 }
155
161 public function isNull()
162 {
163 return new Constraints\IsNull($this->data_factory, $this->lng);
164 }
165
172 public function hasMinLength($min_length)
173 {
174 return new Constraints\HasMinLength($min_length, $this->data_factory, $this->lng);
175 }
176
183 public function hasMaxLength($max_length)
184 {
185 return new Constraints\HasMaxLength($max_length, $this->data_factory, $this->lng);
186 }
187
204 public function custom(callable $is_ok, $error)
205 {
206 return new Constraints\Custom($is_ok, $error, $this->data_factory, $this->lng);
207 }
208
214 public function password()
215 {
216 return new Constraints\Password\Factory($this->data_factory, $this->lng);
217 }
218}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:15
isInt()
Get a constraint for an integer.
Definition: Factory.php:95
__construct(Data\Factory $data_factory, \ilLanguage $lng)
Factory constructor.
Definition: Factory.php:31
parallel(array $others)
Get a constraint that checks the supplied constraints in parallel.
Definition: Factory.php:62
password()
Get the factory for password constraints.
Definition: Factory.php:214
isNull()
Get the constraint that some value is null.
Definition: Factory.php:161
not(Constraint $other)
Get a negated constraint.
Definition: Factory.php:73
hasMaxLength($max_length)
Get the constraint that limits the maximum length of the string.
Definition: Factory.php:183
custom(callable $is_ok, $error)
Get a custom constraint.
Definition: Factory.php:204
lessThan($max)
Get the constraint that some value is smaller then $max.
Definition: Factory.php:141
isArrayOf(Constraint $on_element)
Get a constraint for a array with constraint to all elements.
Definition: Factory.php:119
hasMinLength($min_length)
Get the constraint that some string has a minimum length.
Definition: Factory.php:172
isString()
Get a constraint for a string.
Definition: Factory.php:106
sequential(array $others)
Get a constraint that sequentially checks the supplied constraints.
Definition: Factory.php:49
greaterThan($min)
Get the constraint that some value is larger than $min.
Definition: Factory.php:130
isNumeric()
Get the constraint that some value is a number.
Definition: Factory.php:151
or(array $others)
Get a logical or constraint.
Definition: Factory.php:83
language handling
A constraint encodes some resrtictions on values.
Definition: Constraint.php:15
$lng