Hi, Thomas!
You understood this section of manual completely wrong. This is not
about adding validation to getters. This is about _using getters_ like
validation rules. For example adding constraint (true ===
$user->isPasswordLegal()) to validation with custom error message (The
password cannot match your first name)
So isPasswordLegal() function really returns boolean true (return
($this->firstName != $this->password)). And we ensure this function
returns true here:
# src/Acme/BlogBundle/Resources/config/validation.yml
Acme\BlogBundle\Entity\Author:
getters:
passwordLegal:
- "True": { message: "The password cannot match your first name" }
On Mon, Aug 13, 2012 at 2:56 PM, Thomas Lundquist
<[email protected]> wrote:
>
> Dear fellow developers.
>
>
> First, I am happy that we can do validation outside forms pretty easily
> and that's a very good thing.
>
> But I have a hard time understanding this one:
>
> http://symfony.com/doc/master/book/validation.html#getters
>
> This is about adding validation to the getters.
>
> My question is simple: Could someone please explain to me why the validation
> is on the getter and not the setter?
>
> When it's set it's already too late to handle the exception properly.
>
> I would rather like to know that something is wrong with my data/value when
> I *set* the value, not when I am about to use it.
>
>
> And secondly; I would expect a true from a function with the name
> "isPasswordLegal" means the password *is* legal and not ending up with a
> validation error message.
>
> So, am I just missing some logic here? I'd like to be educated.
>
>
> Thomas.
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en