src/Jms/YamlValidatorConverter.php
private function loadValidatorType(array &$property, Type $type, $arrayized = false)
    {
        $rules = [];

        if (($restrictions = $type->getRestriction()) && $checks = $restrictions->getChecks()) {

            foreach ($checks as $key => $check) {
                switch ($key) {
                    case 'enumeration':
                        $rules[] = [
                            'Choice' => [
                                'choices' => array_map(function ($enum) {
                                    return $enum['value'];
                                }, $check)
                            ]
                        ];
                        break;
//                    fractionDigits totalDigits validation makes no sense in object validation
//                    mainly because they are represented as floats
//                    case 'fractionDigits':
//                        foreach ($check as $item) {
//                            if ($item['value']>0) {
//                                $rules[] = [
//                                    'Regex' => "/^\-?(\\d+\\.\\d{{$item['value']}})|\\d*$/"
//                                ];
//                            }
//                        }
//                        break;
//                    case 'totalDigits':
//                        foreach ($check as $item) {
//                            $rules[] = [
//                                'Regex' => "/^([^\d]*\d){{$item['value']}}[^\d]*$/"
//                            ];
//                        }
//                        break;
                    case 'length':
                        foreach ($check as $item) {
                            $rules[] = [
                                'Length' => [
                                    'min' => $item['value'],
                                    'max' => $item['value']
                                ]
                            ];
                        }
                        break;
                    case 'maxLength':
                        foreach ($check as $item) {
                            $rules[] = [
                                'Length' => [
                                    'max' => $item['value']
                                ]
                            ];
                        }
                        break;
                    case 'minLength':
                        foreach ($check as $item) {
                            $rules[] = [
                                'Length' => [
                                    'min' => $item['value']
                                ]
                            ];
                        }
                        break;
                    case 'pattern':
                        foreach ($check as $item) {
                            $rules[] = [
                                'Regex' => ['pattern' => "/{$item['value']}/"]
                            ];
                        }
                        break;
                    case 'maxExclusive':
                        foreach ($check as $item) {
                            $rules[] = [
                                'LessThan' => ['value' => $item['value']]
                            ];
                        }
                        break;
                    case 'maxInclusive':
                        foreach ($check as $item) {
                            $rules[] = [
                                'LessThanOrEqual' => ['value' => $item['value']]
                            ];
                        }
                        break;
                    case 'minExclusive':
                        foreach ($check as $item) {
                            $rules[] = [
                                'GreaterThan' => ['value' => $item['value']]
                            ];
                        }
                        break;
                    case 'minInclusive':
                        foreach ($check as $item) {
                            $rules[] = [
                                'GreaterThanOrEqual' => ['value' => $item['value']]
                            ];
                        }
                        break;
                }
            }
        }

        if (!$arrayized) {
            $property['validation'] = array_merge(!empty($property['validation']) ? $property['validation'] : [], $rules);
        }

        return $rules;
    }
private function loadValidatorType(array &$property, Type $type, $arrayized = false)
    {
        $rules = [];

        if (($restrictions = $type->getRestriction()) && $checks = $restrictions->getChecks()) {

            foreach ($checks as $key => $check) {
                switch ($key) {
                    case 'enumeration':
                        $rules[] = [
                            'Choice' => [
                                'choices' => array_map(function ($enum) {
                                    return $enum['value'];
                                }, $check)
                            ]
                        ];
                        break;
//                    fractionDigits totalDigits validation makes no sense in object validation
//                    mainly because they are represented as floats
//                    case 'fractionDigits':
//                        foreach ($check as $item) {
//                            if ($item['value']>0) {
//                                $rules[] = [
//                                    'Regex' => "/^\-?(\\d+\\.\\d{{$item['value']}})|\\d*$/"
//                                ];
//                            }
//                        }
//                        break;
//                    case 'totalDigits':
//                        foreach ($check as $item) {
//                            $rules[] = [
//                                'Regex' => "/^([^\d]*\d){{$item['value']}}[^\d]*$/"
//                            ];
//                        }
//                        break;
                    case 'length':
                        foreach ($check as $item) {
                            $rules[] = [
                                'Length' => [
                                    'min' => $item['value'],
                                    'max' => $item['value']
                                ]
                            ];
                        }
                        break;
                    case 'maxLength':
                        foreach ($check as $item) {
                            $rules[] = [
                                'Length' => [
                                    'max' => $item['value']
                                ]
                            ];
                        }
                        break;
                    case 'minLength':
                        foreach ($check as $item) {
                            $rules[] = [
                                'Length' => [
                                    'min' => $item['value']
                                ]
                            ];
                        }
                        break;
                    case 'pattern':
                        foreach ($check as $item) {
                            $rules[] = [
                                'Regex' => ['pattern' => "/{$item['value']}/"]
                            ];
                        }
                        break;
                    case 'maxExclusive':
                        foreach ($check as $item) {
                            $rules[] = [
                                'LessThan' => ['value' => $item['value']]
                            ];
                        }
                        break;
                    case 'maxInclusive':
                        foreach ($check as $item) {
                            $rules[] = [
                                'LessThanOrEqual' => ['value' => $item['value']]
                            ];
                        }
                        break;
                    case 'minExclusive':
                        foreach ($check as $item) {
                            $rules[] = [
                                'GreaterThan' => ['value' => $item['value']]
                            ];
                        }
                        break;
                    case 'minInclusive':
                        foreach ($check as $item) {
                            $rules[] = [
                                'GreaterThanOrEqual' => ['value' => $item['value']]
                            ];
                        }
                        break;
                }
            }
        }

        if (!$arrayized) {
            $property['validation'] = array_merge(!empty($property['validation']) ? $property['validation'] : [], $rules);
        }

        return $rules;
    }
private function loadValidatorType ( array & $ property , Type $ type , $ arrayized = false ) { $ rules = [ ] ; if ( ( $ restrictions = $ type -> getRestriction ( ) ) && $ checks = $ restrictions -> getChecks ( ) ) { foreach ( $ checks as $ key => $ check ) { switch ( $ key ) { case 'enumeration' : $ rules [ ] = [ 'Choice' => [ 'choices' => array_map ( function ( $ enum ) { return $ enum [ 'value' ] ; } , $ check ) ] ] ; break ; //                    fractionDigits totalDigits validation makes no sense in object validation //                    mainly because they are represented as floats //                    case 'fractionDigits': //                        foreach ($check as $item) { //                            if ($item['value']>0) { //                                $rules[] = [ //                                    'Regex' => "/^\-?(\\d+\\.\\d{{$item['value']}})|\\d*$/" //                                ]; //                            } //                        } //                        break; //                    case 'totalDigits': //                        foreach ($check as $item) { //                            $rules[] = [ //                                'Regex' => "/^([^\d]*\d){{$item['value']}}[^\d]*$/" //                            ]; //                        } //                        break; case 'length' : foreach ( $ check as $ item ) { $ rules [ ] = [ 'Length' => [ 'min' => $ item [ 'value' ] , 'max' => $ item [ 'value' ] ] ] ; } break ; case 'maxLength' : foreach ( $ check as $ item ) { $ rules [ ] = [ 'Length' => [ 'max' => $ item [ 'value' ] ] ] ; } break ; case 'minLength' : foreach ( $ check as $ item ) { $ rules [ ] = [ 'Length' => [ 'min' => $ item [ 'value' ] ] ] ; } break ; case 'pattern' : foreach ( $ check as $ item ) { $ rules [ ] = [ 'Regex' => [ 'pattern' => "/{$item['value']}/" ] ] ; } break ; case 'maxExclusive' : foreach ( $ check as $ item ) { $ rules [ ] = [ 'LessThan' => [ 'value' => $ item [ 'value' ] ] ] ; } break ; case 'maxInclusive' : foreach ( $ check as $ item ) { $ rules [ ] = [ 'LessThanOrEqual' => [ 'value' => $ item [ 'value' ] ] ] ; } break ; case 'minExclusive' : foreach ( $ check as $ item ) { $ rules [ ] = [ 'GreaterThan' => [ 'value' => $ item [ 'value' ] ] ] ; } break ; case 'minInclusive' : foreach ( $ check as $ item ) { $ rules [ ] = [ 'GreaterThanOrEqual' => [ 'value' => $ item [ 'value' ] ] ] ; } break ; } } } if ( ! $ arrayized ) { $ property [ 'validation' ] = array_merge ( ! empty ( $ property [ 'validation' ] ) ? $ property [ 'validation' ] : [ ] , $ rules ) ; } return $ rules ; }
Load and convert XSD' restrictions to Symfony Validation Constraints
from a schema type

@param array $property
@param Type $type
@param boolean $arrayized
Load and convert XSD restrictions to Symfony Validation Constraints from a schema type