Skip to content

[Validation] Add "hasser" support #3418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2014
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions book/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,11 @@ Getters

Constraints can also be applied to the return value of a method. Symfony2
allows you to add a constraint to any public method whose name starts with
"get" or "is". In this guide, both of these types of methods are referred
to as "getters".
"get", "is" or "has". In this guide, these types of methods are referred to
as "getters".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a versionadded directive for the "hasser" support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this yesterday, see commit below.


.. versionadded:: 2.5
Support for methods starting with ``has`` is new in Symfony 2.5.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was introduced in Symfony 2.5.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it makes sense to also fix the wording in 2.3 and 2.4, or is it a new convention?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a new convention and as the versionadded directives are removed quite quickly, we decided not to invest time in updating the others. We can better document the missing things! 👏


The benefit of this technique is that it allows you to validate your object
dynamically. For example, suppose you want to make sure that a password field
Expand Down Expand Up @@ -665,9 +668,9 @@ Now, create the ``isPasswordLegal()`` method, and include the logic you need::
.. note::

The keen-eyed among you will have noticed that the prefix of the getter
("get" or "is") is omitted in the mapping. This allows you to move the
constraint to a property with the same name later (or vice versa) without
changing your validation logic.
("get", "is" or "has") is omitted in the mapping. This allows you to move
the constraint to a property with the same name later (or vice versa)
without changing your validation logic.

.. _validation-class-target:

Expand Down