Skip to content

Use default options in constraint docs #4144

Closed
@webmozart

Description

@webmozart

Currently, the basic examples of constraints like GreaterThan don't use the short version for default options:

class Person
{
    /**
     * @Assert\GreaterThan(
     *     value = 18
     * )
     */
    protected $age;
}

The proper (short) way of writing this would be:

class Person
{
    /**
     * @Assert\GreaterThan(18)
     */
    protected $age;
}

I think the "Basic Usage" examples should be fixed in this direction. In addition, a new section "Message Customization" should be added that shows how to write the constraint when customizing the message:

class Person
{
    /**
     * @Assert\GreaterThan(
     *     value = 18,
     *     message = "Restricted to persons older than 18 years."
     * )
     */
    protected $age;
}

The above applies for all configuration styles (annotations, PHP, XML and YAML).

Metadata

Metadata

Assignees

No one assigned

    Labels

    ValidatoractionableClear and specific issues ready for anyone to take them.good first issueIdeal for your first contribution! (some Symfony experience may be required)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions