piece-of-kake / validator
OO validator
Installs: 603
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=7.1
- piece-of-kake/exception: dev-main
- piece-of-kake/value-object: dev-main
README
OO validator
Example:
return $validation ->parameter(function(ValidationParameter $parameter) { $parameter ->name('age') ->required() ->sanitizer(IntegerSanitizer::class) ->sanitizer(SomeOtherSanitizer::class) ->validator(AgeValidator::class) ->depends(function(ValidationDependency $dependency) { $dependency ->must('password') ->mustNot('facebook_id'); }); }) ->parameter(function(ValidationParameter $parameter) { $parameter ->name('password') ->required() ->default('Gabbals') ->validator(UsernameValidator::class); }) ->parameter(function(ValidationParameter $parameter) { $parameter ->name('facebook_id') ->required() ->default('Facebook Gabbals') ->validator(FacebookIdValidator::class) ->depends(function(ValidationDependency $dependency) { $dependency ->mustNot('username'); }); })
DEPENDENCY EXAMPLES
->parameter(function(ValidationParameter $parameter) { $parameter ->name('one_or') ->depends(function(ValidationDependency $dependency) { $dependency->orRequire('two_or'); }) ->validator(NonEmptyStringValidator::class) ->castTo(TypeString::class); }) ->parameter(function(ValidationParameter $parameter) { $parameter ->name('two_or') ->depends(function(ValidationDependency $dependency) { $dependency->orRequire('one_or'); }) ->validator(NonEmptyStringValidator::class) ->castTo(TypeString::class); }) ->parameter(function(ValidationParameter $parameter) { $parameter ->name('one_must') ->depends(function(ValidationDependency $dependency) { $dependency->must('two_must'); }) ->validator(NonEmptyStringValidator::class) ->castTo(TypeString::class); }) ->parameter(function(ValidationParameter $parameter) { $parameter ->name('two_must') ->validator(AbuseReportTypeValidator::class) ->castTo(TypeString::class); }) ->parameter(function(ValidationParameter $parameter) { $parameter ->name('one_must_not') ->depends(function(NonEmptyStringValidator $dependency) { $dependency->mustNot('two_must_not'); }) ->validator(AbuseReportTypeValidator::class) ->castTo(TypeString::class); }) ->parameter(function(ValidationParameter $parameter) { $parameter ->name('two_must_not') ->validator(NonEmptyStringValidator::class) ->castTo(TypeString::class); });