"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php" between
symfony-4.4.14.tar.gz and symfony-4.4.15.tar.gz

About: Symfony is a web application framework for PHP projects. Source code (4.4 series).

FormValidator.php  (symfony-4.4.14):FormValidator.php  (symfony-4.4.15)
skipping to change at line 28 skipping to change at line 28
use Symfony\Component\Validator\Constraints\Valid; use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
*/ */
class FormValidator extends ConstraintValidator class FormValidator extends ConstraintValidator
{ {
private $resolvedGroups; private $resolvedGroups;
private $fieldFormConstraints;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function validate($form, Constraint $formConstraint) public function validate($form, Constraint $formConstraint)
{ {
if (!$formConstraint instanceof Form) { if (!$formConstraint instanceof Form) {
throw new UnexpectedTypeException($formConstraint, Form::class); throw new UnexpectedTypeException($formConstraint, Form::class);
} }
skipping to change at line 70 skipping to change at line 71
; ;
// Validate the data against the constraints defined in the form // Validate the data against the constraints defined in the form
/** @var Constraint[] $constraints */ /** @var Constraint[] $constraints */
$constraints = $config->getOption('constraints', []); $constraints = $config->getOption('constraints', []);
$hasChildren = $form->count() > 0; $hasChildren = $form->count() > 0;
if ($hasChildren && $form->isRoot()) { if ($hasChildren && $form->isRoot()) {
$this->resolvedGroups = new \SplObjectStorage(); $this->resolvedGroups = new \SplObjectStorage();
$this->fieldFormConstraints = [];
} }
if ($groups instanceof GroupSequence) { if ($groups instanceof GroupSequence) {
// Validate the data, the form AND nested fields in sequence // Validate the data, the form AND nested fields in sequence
$violationsCount = $this->context->getViolations()->count(); $violationsCount = $this->context->getViolations()->count();
foreach ($groups->groups as $group) { foreach ($groups->groups as $group) {
if ($validateDataGraph) { if ($validateDataGraph) {
$validator->atPath('data')->validate($data, null, $group ); $validator->atPath('data')->validate($data, null, $group );
} }
if ($groupedConstraints = self::getConstraintsInGroups($cons traints, $group)) { if ($groupedConstraints = self::getConstraintsInGroups($cons traints, $group)) {
$validator->atPath('data')->validate($data, $groupedCons traints, $group); $validator->atPath('data')->validate($data, $groupedCons traints, $group);
} }
foreach ($form->all() as $field) { foreach ($form->all() as $field) {
if ($field->isSubmitted()) { if ($field->isSubmitted()) {
// remember to validate this field is one group only // remember to validate this field in one group only
// otherwise resolving the groups would reuse the sa me // otherwise resolving the groups would reuse the sa me
// sequence recursively, thus some fields could fail // sequence recursively, thus some fields could fail
// in different steps without breaking early enough // in different steps without breaking early enough
$this->resolvedGroups[$field] = (array) $group; $this->resolvedGroups[$field] = (array) $group;
$fieldFormConstraint = new Form(); $fieldFormConstraint = new Form();
$fieldFormConstraint->groups = $group;
$this->fieldFormConstraints[] = $fieldFormConstraint
;
$this->context->setNode($this->context->getValue(), $field, $this->context->getMetadata(), $this->context->getPropertyPath()); $this->context->setNode($this->context->getValue(), $field, $this->context->getMetadata(), $this->context->getPropertyPath());
$validator->atPath(sprintf('children[%s]', $field->g etName()))->validate($field, $fieldFormConstraint); $validator->atPath(sprintf('children[%s]', $field->g etName()))->validate($field, $fieldFormConstraint, $group);
} }
} }
if ($violationsCount < $this->context->getViolations()->coun t()) { if ($violationsCount < $this->context->getViolations()->coun t()) {
break; break;
} }
} }
} else { } else {
if ($validateDataGraph) { if ($validateDataGraph) {
$validator->atPath('data')->validate($data, null, $groups); $validator->atPath('data')->validate($data, null, $groups);
skipping to change at line 139 skipping to change at line 143
} }
foreach ($groupedConstraints as $group => $constraint) { foreach ($groupedConstraints as $group => $constraint) {
$validator->atPath('data')->validate($data, $constraint, $gr oup); $validator->atPath('data')->validate($data, $constraint, $gr oup);
} }
foreach ($form->all() as $field) { foreach ($form->all() as $field) {
if ($field->isSubmitted()) { if ($field->isSubmitted()) {
$this->resolvedGroups[$field] = $groups; $this->resolvedGroups[$field] = $groups;
$fieldFormConstraint = new Form(); $fieldFormConstraint = new Form();
$this->fieldFormConstraints[] = $fieldFormConstraint;
$this->context->setNode($this->context->getValue(), $fie ld, $this->context->getMetadata(), $this->context->getPropertyPath()); $this->context->setNode($this->context->getValue(), $fie ld, $this->context->getMetadata(), $this->context->getPropertyPath());
$validator->atPath(sprintf('children[%s]', $field->getNa me()))->validate($field, $fieldFormConstraint); $validator->atPath(sprintf('children[%s]', $field->getNa me()))->validate($field, $fieldFormConstraint);
} }
} }
} }
if ($hasChildren && $form->isRoot()) { if ($hasChildren && $form->isRoot()) {
// destroy storage to avoid memory leaks // destroy storage to avoid memory leaks
$this->resolvedGroups = new \SplObjectStorage(); $this->resolvedGroups = new \SplObjectStorage();
$this->fieldFormConstraints = [];
} }
} elseif (!$form->isSynchronized()) { } elseif (!$form->isSynchronized()) {
$childrenSynchronized = true; $childrenSynchronized = true;
/** @var FormInterface $child */ /** @var FormInterface $child */
foreach ($form as $child) { foreach ($form as $child) {
if (!$child->isSynchronized()) { if (!$child->isSynchronized()) {
$childrenSynchronized = false; $childrenSynchronized = false;
$fieldFormConstraint = new Form(); $fieldFormConstraint = new Form();
$this->fieldFormConstraints[] = $fieldFormConstraint;
$this->context->setNode($this->context->getValue(), $child, $this->context->getMetadata(), $this->context->getPropertyPath()); $this->context->setNode($this->context->getValue(), $child, $this->context->getMetadata(), $this->context->getPropertyPath());
$validator->atPath(sprintf('children[%s]', $child->getName() ))->validate($child, $fieldFormConstraint); $validator->atPath(sprintf('children[%s]', $child->getName() ))->validate($child, $fieldFormConstraint);
} }
} }
// Mark the form with an error if it is not synchronized BUT all // Mark the form with an error if it is not synchronized BUT all
// of its children are synchronized. If any child is not // of its children are synchronized. If any child is not
// synchronized, an error is displayed there already and showing // synchronized, an error is displayed there already and showing
// a second error in its parent form is pointless, or worse, may // a second error in its parent form is pointless, or worse, may
// lead to duplicate errors if error bubbling is enabled on the // lead to duplicate errors if error bubbling is enabled on the
 End of changes. 8 change blocks. 
2 lines changed or deleted 10 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)