terrazza / validator
Terrazza Component Validator
Installs: 13
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
pkg:composer/terrazza/validator
Requires (Dev)
- phpunit/phpunit: ^9.3
 - terrazza/dev-logger: 1.*.*
 - vimeo/psalm: 4.x-dev
 
README
This component validates/approves content against schemas
Object/Classes
ObjectValueSchema
Properties:
- name (string, required)
 - type (string, required)
- number
 - integer
 - double
 - array
 - boolean
 - string
 - object
 - oneOf (require setChildSchemas)
 
 - required (bool, default=false)
 - nullable (bool, default=false)
 - patterns (string, optional)
only used for type: string - format (string, optional)
only used for type: string - minLength (int, optional)
only used for type: number, integer, double - maxLength (int, optional)
only used for type: number, integer, double - minItems (int, optional)
only used for type: array - maxItems (int, optional)
only used for type: array - minRange (float, optional)
only used for type: number, integer, double - maxRange (float, optional)
only used for type: number, integer, double - multipleOf (float, optional)
only used for type: number, integer, double - enum (scalar, optional)
only used for type: number, integer, double - childSchemas (arrayOf ObjectValueSchema, optional)
 
method: isMultipleType
verifies if the type is one of
- oneOf
 
ObjectValidator
method: isValid
calls method::validate but covered in a try/catch.
In case of catch the method returns false. Otherwise, the method returns true.
method: validate
Validate the content against
- contentType
 - validateArray
 - validateString
 - validateNumber
 - validateFormat
 - validateEnum
 - validateMultipleTypes (e.g. oneOf)
 
method: getEncodedValue
Method try to solve some content : schema mismatches that could be solved.
In case of being able to solve a mismatch, the method
- set the type of the schema to the converted one
 - returns the converted value
 
Examples
- expected type: integer, given "12"
 - expected type: boolean, given "yes"