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: 3.0.0-rc1
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}}
{{/isContainer}}
{{^isContainer}}
    {{#isDate}}
        $asserts[] = new Assert\Date();
    {{/isDate}}
    {{#isDateTime}}
        $asserts[] = new Assert\DateTime();
    {{/isDateTime}}
    {{^isDate}}
    {{^isDateTime}}
    {{#isFile}}
        $asserts[] = new Assert\File();
    {{/isFile}}
    {{^isFile}}
        $asserts[] = new Assert\Type("{{dataType}}");
    {{/isFile}}
    {{/isDateTime}}
    {{/isDate}}
{{/isContainer}}
{{#hasValidation}}
    {{#maxLength}}
        $asserts[] = new Assert\Length([
            'max' => {{maxLength}}
        ]);
    {{/maxLength}}
    {{#minLength}}
        $asserts[] = new Assert\Length([
            'min' => {{minLength}}
        ]);
    {{/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}}/");
    {{/pattern}}
    {{#maxItems}}
        $asserts[] = new Assert\Count([
            'max' => {{maxItems}}
        ]);
    {{/maxItems}}
    {{#minItems}}
        $asserts[] = new Assert\Count([
            'min' => {{minItems}}
        ]);
    {{/minItems}}
{{/hasValidation}}
        $response = $this->validate(${{paramName}}, $asserts);
        if ($response instanceof Response) {
            return $response;
        }
{{/allParams}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy