ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ILIAS\Validation\Factory Class Reference

Factory for creating constraints. More...

+ Collaboration diagram for ILIAS\Validation\Factory:

Public Member Functions

 __construct (Data\Factory $data_factory, \ilLanguage $lng)
 Factory constructor. More...
 
 sequential (array $others)
 Get a constraint that sequentially checks the supplied constraints. More...
 
 parallel (array $others)
 Get a constraint that checks the supplied constraints in parallel. More...
 
 not (Constraint $other)
 Get a negated constraint. More...
 
 or (array $others)
 Get a logical or constraint. More...
 
 isInt ()
 Get a constraint for an integer. More...
 
 isString ()
 Get a constraint for a string. More...
 
 isArrayOf (Constraint $on_element)
 Get a constraint for a array with constraint to all elements. More...
 
 greaterThan ($min)
 Get the constraint that some value is larger than $min. More...
 
 lessThan ($max)
 Get the constraint that some value is smaller then $max. More...
 
 isNumeric ()
 Get the constraint that some value is a number. More...
 
 isNull ()
 Get the constraint that some value is null. More...
 
 hasMinLength ($min_length)
 Get the constraint that some string has a minimum length. More...
 
 hasMaxLength ($max_length)
 Get the constraint that limits the maximum length of the string. More...
 
 custom (callable $is_ok, $error)
 Get a custom constraint. More...
 
 password ()
 Get the factory for password constraints. More...
 

Data Fields

const LANGUAGE_MODULE = "validation"
 

Protected Attributes

 $data_factory
 
 $lng
 

Detailed Description

Factory for creating constraints.

Definition at line 12 of file Factory.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Validation\Factory::__construct ( Data\Factory  $data_factory,
\ilLanguage  $lng 
)

Factory constructor.

Parameters
Data\Factory$data_factory

Definition at line 31 of file Factory.php.

References $lng.

32  {
33  $this->data_factory = $data_factory;
34  $this->lng = $lng;
35  $this->lng->loadLanguageModule(self::LANGUAGE_MODULE);
36  }
$lng

Member Function Documentation

◆ custom()

ILIAS\Validation\Factory::custom ( callable  $is_ok,
  $error 
)

Get a custom constraint.

If the provided value !$is_ok will either use the $error (if it is a string) or provide the value to the $error callback.

If $error is a callable it needs to take two parameters:

  • one callback $txt($lng_id, ($value, ...)) that retrieves the lang var with the given id and uses sprintf to replace placeholder if more values are provide
  • the $value for which the error message should be build.
Parameters
callable$is_okMUST return boolean
string | callable$error
Returns
Constraint

Definition at line 204 of file Factory.php.

205  {
206  return new Constraints\Custom($is_ok, $error, $this->data_factory, $this->lng);
207  }

◆ greaterThan()

ILIAS\Validation\Factory::greaterThan (   $min)

Get the constraint that some value is larger than $min.

Parameters
int$min
Returns
Constraint

Definition at line 130 of file Factory.php.

131  {
132  return new Constraints\GreaterThan($min, $this->data_factory, $this->lng);
133  }

◆ hasMaxLength()

ILIAS\Validation\Factory::hasMaxLength (   $max_length)

Get the constraint that limits the maximum length of the string.

Parameters
int$max_length
Returns
Constraint

Definition at line 183 of file Factory.php.

184  {
185  return new Constraints\HasMaxLength($max_length, $this->data_factory, $this->lng);
186  }

◆ hasMinLength()

ILIAS\Validation\Factory::hasMinLength (   $min_length)

Get the constraint that some string has a minimum length.

Parameters
int$min_length
Returns
Constraint

Definition at line 172 of file Factory.php.

173  {
174  return new Constraints\HasMinLength($min_length, $this->data_factory, $this->lng);
175  }

◆ isArrayOf()

ILIAS\Validation\Factory::isArrayOf ( Constraint  $on_element)

Get a constraint for a array with constraint to all elements.

Parameters
Constraint$on_element
Returns
Constraints

Definition at line 119 of file Factory.php.

120  {
121  return new Constraints\IsArrayOf($this->data_factory, $on_element, $this->lng);
122  }

◆ isInt()

ILIAS\Validation\Factory::isInt ( )

Get a constraint for an integer.

Returns
Constraint

Definition at line 95 of file Factory.php.

96  {
97  return new Constraints\IsInt($this->data_factory, $this->lng);
98  }

◆ isNull()

ILIAS\Validation\Factory::isNull ( )

Get the constraint that some value is null.

Returns
Constraint

Definition at line 161 of file Factory.php.

162  {
163  return new Constraints\IsNull($this->data_factory, $this->lng);
164  }

◆ isNumeric()

ILIAS\Validation\Factory::isNumeric ( )

Get the constraint that some value is a number.

Returns
Constraint

Definition at line 151 of file Factory.php.

152  {
153  return new Constraints\IsNumeric($this->data_factory, $this->lng);
154  }

◆ isString()

ILIAS\Validation\Factory::isString ( )

Get a constraint for a string.

Returns
Constraint

Definition at line 106 of file Factory.php.

107  {
108  return new Constraints\IsString($this->data_factory, $this->lng);
109  }

◆ lessThan()

ILIAS\Validation\Factory::lessThan (   $max)

Get the constraint that some value is smaller then $max.

Parameters
int$max
Returns
Constraint

Definition at line 141 of file Factory.php.

142  {
143  return new Constraints\LessThan($max, $this->data_factory, $this->lng);
144  }

◆ not()

ILIAS\Validation\Factory::not ( Constraint  $other)

Get a negated constraint.

Parameters
Constraint$other
Returns
Constraint

Definition at line 73 of file Factory.php.

74  {
75  return new Constraints\Not($other, $this->data_factory, $this->lng);
76  }

◆ or()

ILIAS\Validation\Factory::or ( array  $others)

Get a logical or constraint.

Parameters
Constraint[]$others
Returns
Constraint

Definition at line 83 of file Factory.php.

84  {
85  return new Constraints\LogicalOr($others, $this->data_factory, $this->lng);
86  }

◆ parallel()

ILIAS\Validation\Factory::parallel ( array  $others)

Get a constraint that checks the supplied constraints in parallel.

The new constraint tells the problems of all violated constraints.

Parameters
Constraint[]$others
Returns
Constraint

Definition at line 62 of file Factory.php.

63  {
64  return new Constraints\Parallel($others, $this->data_factory, $this->lng);
65  }

◆ password()

ILIAS\Validation\Factory::password ( )

Get the factory for password constraints.

Returns
ILIAS;

Definition at line 214 of file Factory.php.

215  {
216  return new Constraints\Password\Factory($this->data_factory, $this->lng);
217  }

◆ sequential()

ILIAS\Validation\Factory::sequential ( array  $others)

Get a constraint that sequentially checks the supplied constraints.

The new constraint tells the problem of the first violated constraint.

Parameters
Constraint[]$others
Returns
Constraint

Definition at line 49 of file Factory.php.

50  {
51  return new Constraints\Sequential($others, $this->data_factory, $this->lng);
52  }

Field Documentation

◆ $data_factory

ILIAS\Validation\Factory::$data_factory
protected

Definition at line 19 of file Factory.php.

◆ $lng

ILIAS\Validation\Factory::$lng
protected

Definition at line 24 of file Factory.php.

◆ LANGUAGE_MODULE

const ILIAS\Validation\Factory::LANGUAGE_MODULE = "validation"

Definition at line 14 of file Factory.php.


The documentation for this class was generated from the following file: