48 public static function start() {
52 'notNull' => NotNullValidator::class,
53 'isNull' => IsNullValidator::class,
54 'notEmpty' => NotEmptyValidator::class,
55 'isEmpty' => IsEmptyValidator::class,
56 'isTrue' => IsTrueValidator::class,
57 'isFalse' => IsFalseValidator::class,
58 'isBool' => IsBooleanValidator::class,
59 'equals' => EqualsValidator::class,
60 'type' => TypeValidator::class,
61 'greaterThan' => GreaterThanValidator::class,
62 'greaterThanOrEqual' => GreaterThanOrEqualValidator::class,
63 'lessThan' => LessThanValidator::class,
64 'lessThanOrEqual' => LessThanOrEqualValidator::class,
65 'length' => LengthValidator::class,
66 'id' => IdValidator::class,
67 'regex' => RegexValidator::class,
68 'email' => EmailValidator::class,
69 'url' => UrlValidator::class,
70 'ip' => IpValidator::class,
71 'range' => RangeValidator::class,
72 'date' => DateValidator::class,
73 'dateTime' => DateTimeValidator::class,
74 'time' => TimeValidator::class,
75 'match'=>MatchWithValidator::class
86 foreach ( $validators as $member => $validators ) {
88 if (\count ( $filteredValidators ) > 0) {
89 $result [$member] = $filteredValidators;
97 foreach ( $validators as $validator ) {
98 if (isset ( $validator [
'group'] ) && $validator [
'group'] === $group) {
99 $result [] = $validator;
114 public static function validate($instance, $group =
'', $excludedValidators = [ ]) {
115 $class = \get_class ( $instance );
134 public static function getUIConstraints($instance, $group =
'', $excludedValidators = [ ]) {
135 $class = \get_class ( $instance );
155 if (\count ( $instances ) > 0) {
156 $instance = \current ( $instances );
157 $class = \get_class ( $instance );
162 $cache = self::$instanceValidators [$class];
171 foreach ( $instances as $instance ) {
172 foreach ( $members as $accessor => $validators ) {
173 foreach ( $validators as $validator ) {
174 $valid = $validator->validate_ ( $instance->$accessor () );
175 if ($valid !==
true) {
184 protected static function validate_($instance, $members, $excludedValidators = [ ]) {
186 foreach ( $members as $member => $validators ) {
187 $accessor =
'get' . \ucfirst ( $member );
188 if (\method_exists ( $instance, $accessor )) {
189 foreach ( $validators as $validator ) {
190 $typeV = $validator [
'type'];
191 if (! isset ( $excludedValidators [$typeV] )) {
193 if ($validatorInstance !==
false) {
194 $validatorInstance->setValidationParameters ( $member, $validator [
'constraints'] ?? [ ], $validator [
'severity'] ??
null, $validator [
'message'] ??
null);
195 $valid = $validatorInstance->validate_ ( $instance->$accessor () );
196 if ($valid !==
true) {
209 foreach ( $members as $member => $validators ) {
210 $result [$member]=[];
211 $accessor =
'get' . \ucfirst ( $member );
212 if (\method_exists ( $instance, $accessor )) {
213 foreach ( $validators as $validator ) {
214 $typeV = $validator [
'type'];
215 if (! isset ( $excludedValidators [$typeV] )) {
217 if ($validatorInstance !==
false) {
218 $validatorInstance->setValidationParameters ( $member, $validator [
'constraints'] ?? [ ], $validator [
'severity'] ??
null, $validator [
'message'] ??
null);
219 $result [$member] = \array_merge_recursive($result[$member],$validatorInstance->asUI ());
Manager for caches (Router, Rest, models).
static getGroupMemberValidators(array $validators, $group)
static validate($instance, $group='', $excludedValidators=[])
Validates an instance.
static $instanceValidators
static validateInstances($instances, $group='')
Validates an array of objects.
static getCacheInfo($model)
static validate_($instance, $members, $excludedValidators=[])
static getUIConstraints_($instance, $members, $excludedValidators=[])
static getUIConstraints($instance, $group='', $excludedValidators=[])
Returns an array of UI rules for Javascript validation.
static validateInstances_($instances, $members)
static getGroupArrayValidators(array $validators, $group)
static initInstancesValidators($instance, $members, $group='')
static getUIConstraintsFromCache_($instance, $members, $excludedValidators=[])
static validateFromCache_($instance, $members, $excludedValidators=[])
static getValidatorInstance($type)
static getClassCacheValidators($class, $group='')
Ubiquity\contents\validation\validators\comparison$EqualsValidator This class is part of Ubiquity.
Ubiquity\contents\validation\validators\comparison$GreaterThanValidator This class is part of Ubiquit...
Ubiquity\contents\validation\validators\comparison$LessThanOrEqualValidator This class is part of Ubi...
Ubiquity\contents\validation\validators\comparison$MatchWithValidator This class is part of Ubiquity.
Check if a value is in a range.
Validate int identifiers (notNull positive integer).
Validate Strings length using min, max, charset,notNull parameters.
Validates an email address Usage @validator("email")
Validates an address ip Usage @validator("ip","4") Inspired from Bernhard Schussek Symfony IpValidato...
Validates a string with a regex Usage @validator("regex",pattern)
Validates an URL Usage @validator("url","constraints"=>["relative"=>false,"protocols"=>["http",...
Abstract class for logging Ubiquity\log$Logger This class is part of Ubiquity.