Skip to content

Instantly share code, notes, and snippets.

@Allisone
Created May 30, 2012 11:39
Show Gist options
  • Save Allisone/2835716 to your computer and use it in GitHub Desktop.
Save Allisone/2835716 to your computer and use it in GitHub Desktop.
Why and where is this a breaking change
[!!!][BUGFIX] Avoid validating instances more often than needed
The GenericObjectValidator uses a static variable to store objects being
validated. Objects were still validated over and over because at the
end of isValid() they were detached again.
This change replaces that detach() call with another concept. Now
any validator implementing the new ObjectValidatorInterface can be
given an SplObjectStorage to keep track of instances already
validated.
If you reset that container when it makes sense (before you
actively validate objects) you can avoid validating single instances
more than once in one validation run but still validate at various
points on your logic flow.
This is a breaking change in situations where you would have a deeply
nested model hierarchy. In onFlush there is an iterator that iterates
through all entities that have to be persisted. Having an object A that
has a B, that has a C, the iterator gets a list of 3 entities to go
through for validation, namely A, B and C.
But because A has a pointer to B and B to C, validating A means also
validating B and validating B means also validating C.
So before the fix there would be a validation for A+B+C, then for B+C, then for C.
With the fix we now only validate A,B and C once.
Change-Id: I7f437207e27593425b1fbdfc340a442e685a317f
Fixes: #37363
Related: #34154
Releases: 1.1, 1.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment