. */ /** * Maarch IVS - Validation Facets * * @package MaarchIVS * @author Cyril Vazquez (Maarch) */ class DataTypeRestriction { public $minLength; public $maxLength; public $minInclusive; public $maxInclusive; public $minExclusive; public $maxExclusive; public $length; public $enumeration; public $pattern; public $totalDigit; public $fractionDigit; /** * Add a facet * @param string $name The facet name * @param mixed $value The facet value */ public function addFacet($name, $value) { switch ($name) { case 'minLength': case 'maxLength': case 'minInclusive': case 'maxInclusive': case 'minExclusive': case 'maxExclusive': $this->{$name} = $value; break; case 'length': case 'enumeration': case 'pattern': case 'totalDigit': case 'fractionDigit': if (is_array($value)) { $this->{$name} = array_merge($this->{$name}, $value); } else { $this->{$name}[] = $value; } break; } } /** * Extend a base restriction * @param DataTypeRestriction $base */ public function extend($base) { foreach ($base as $name => $value) { switch ($name) { case 'minLength': case 'maxLength': case 'minInclusive': case 'maxInclusive': case 'minExclusive': case 'maxExclusive': if (!isset($this->{$name})) { $this->{$name} = $value; } break; case 'length': case 'enumeration': case 'pattern': case 'totalDigit': case 'fractionDigit': $this->{$name} = array_merge($this->{$name}, $value); break; } } } }