Hi Bernhard

The exact use case is:

- I have an Entity model that uses data inheritance, i.e. each Entity
can inherit the data of its parent on /selected/ fields. So when
editing a form the field can be blank if the field is to be inherited.

  http://www.dantleech.com/form.png

- The form uses a special field group which automatically includes the
"inherit" checkbox as seen in the above screenshot and gets and sets
values with a custom path.

  https://gist.github.com/827346



So I think:

 - subclassing doesnt work because the state is dynamic
 - adding ..Valid methods for each field isnt very DRY in this case
(many different entities implementing data inheritance)

I /think/ the ExecutionContext method works best for me (thanks),
although will need to bite the bullet and upgrade my ageing Symfony2
checkout to use it :) Still, interested if anybody can think of any
other solutions or that I am still not understanding something ...
..

If I understand it correctly I could

On 15 February 2011 09:50, Bernhard Schussek <[email protected]> wrote:
> Hi Dan,
>
> Could you please tell me your exact use case? The cleanest way would
> probably be, as mentioned above, to create is...Valid() methods. If
> that's not feasible, maybe you should subclass your entity instead?
> (e.g. Post <- PublishedPost)
>
> If none of that is possible, you can use the Execute constraint to
> solve your problem:
>
> use Symfony\Component\Validator\ExecutionContext;
>
> /**
>  * @validation:Execute("validateEnabled")
>  */
> class SomeEntity
> {
>   /**
>    * @validation:NotBlank(groups="Enabled");
>    */
>   protected $foo;
>
>   /**
>    * When true we want to validate $foo
>    */
>   protected $enable_foo;
>
>    public function validateStrictIfEnabled(ExecutionContext $context)
>    {
>        if ($this->enable_foo) {
>            $metadata =
> $context->getMetadataFactory()->getClassMetadata(__CLASS__);
>            $propertyPath = $context->getPropertyPath();
>            $context->getGraphWalker()->walkObject($metadata, $this,
> 'Enabled', $propertyPath);
>        }
>    }
> }
>
> But, I must emphasize, look for a problem in your architecture before
> you use such measures.
>
> Bernhard
>
> --
> 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
>



-- 
Dan Leech

Web Developer
www.dantleech.com

-- 
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

Reply via email to