All Downloads are FREE. Search and download functionalities are using the official Maven repository.

php-symfony.api_input_validation.mustache Maven / Gradle / Ivy

There is a newer version: 7.7.0
Show newest version
{{#allParams}}
        $asserts = [];
{{#required}}
        $asserts[] = new Assert\NotNull();
{{/required}}
{{#isEnum}}
    {{#isContainer}}
        $asserts[] = new Assert\All([
    {{#items}}
            new Assert\Choice([ {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}} ])
    {{/items}}
        ]);
    {{/isContainer}}
    {{^isContainer}}
        $asserts[] = new Assert\Choice([ {{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}} ]);
    {{/isContainer}}
{{/isEnum}}
{{#isContainer}}
    {{#items}}
        $asserts[] = new Assert\All([
            new Assert\Type("{{dataType}}"),
        ]);
    {{/items}}
    {{^isPrimitiveType}}
        $asserts[] = new Assert\Valid();
    {{/isPrimitiveType}}
{{/isContainer}}
{{^isContainer}}
    {{#isDate}}
        $asserts[] = new Assert\Date();
    {{/isDate}}
    {{#isDateTime}}
        $asserts[] = new Assert\Type("DateTime");
    {{/isDateTime}}
    {{^isDate}}
    {{^isDateTime}}
    {{#isFile}}
        $asserts[] = new Assert\File();
    {{/isFile}}
    {{^isFile}}
    {{#isEnumRef}}
        $asserts[] = new Assert\Type("\{{modelPackage}}\{{dataType}}");
    {{/isEnumRef}}
    {{^isEnumRef}}
        $asserts[] = new Assert\Type("{{dataType}}");
        {{^isPrimitiveType}}
        $asserts[] = new Assert\Valid();
        {{/isPrimitiveType}}
    {{/isEnumRef}}
    {{/isFile}}
    {{/isDateTime}}
    {{/isDate}}
{{/isContainer}}
{{#hasValidation}}
    {{#maxLength}}
        $asserts[] = new Assert\Length([
            'max' => {{.}}
        ]);
    {{/maxLength}}
    {{#minLength}}
        $asserts[] = new Assert\Length([
            'min' => {{.}}
        ]);
    {{/minLength}}
    {{#minimum}}
    {{#exclusiveMinimum}}
        $asserts[] = new Assert\GreaterThan({{minimum}});
    {{/exclusiveMinimum}}
    {{^exclusiveMinimum}}
        $asserts[] = new Assert\GreaterThanOrEqual({{minimum}});
    {{/exclusiveMinimum}}
    {{/minimum}}
    {{#maximum}}
    {{#exclusiveMaximum}}
        $asserts[] = new Assert\LessThan({{maximum}});
    {{/exclusiveMaximum}}
    {{^exclusiveMaximum}}
        $asserts[] = new Assert\LessThanOrEqual({{maximum}});
    {{/exclusiveMaximum}}
    {{/maximum}}
    {{#pattern}}
        $asserts[] = new Assert\Regex("/{{.}}/");
    {{/pattern}}
    {{#maxItems}}
        $asserts[] = new Assert\Count([
            'max' => {{.}}
        ]);
    {{/maxItems}}
    {{#minItems}}
        $asserts[] = new Assert\Count([
            'min' => {{.}}
        ]);
    {{/minItems}}
{{/hasValidation}}
        $response = $this->validate(${{paramName}}, $asserts);
        if ($response instanceof Response) {
            return $response;
        }
{{/allParams}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy