DataMapperInterface.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form;
  11. /**
  12. * @author Bernhard Schussek <bschussek@gmail.com>
  13. */
  14. interface DataMapperInterface
  15. {
  16. /**
  17. * Maps the view data of a compound form to its children.
  18. *
  19. * The method is responsible for calling {@link FormInterface::setData()}
  20. * on the children of compound forms, defining their underlying model data.
  21. *
  22. * @param mixed $viewData View data of the compound form being initialized
  23. * @param FormInterface[]|iterable $forms A list of {@link FormInterface} instances
  24. *
  25. * @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
  26. */
  27. public function mapDataToForms($viewData, iterable $forms);
  28. /**
  29. * Maps the model data of a list of children forms into the view data of their parent.
  30. *
  31. * This is the internal cascade call of FormInterface::submit for compound forms, since they
  32. * cannot be bound to any input nor the request as scalar, but their children may:
  33. *
  34. * $compoundForm->submit($arrayOfChildrenViewData)
  35. * // inside:
  36. * $childForm->submit($childViewData);
  37. * // for each entry, do the same and/or reverse transform
  38. * $this->dataMapper->mapFormsToData($compoundForm, $compoundInitialViewData)
  39. * // then reverse transform
  40. *
  41. * When a simple form is submitted the following is happening:
  42. *
  43. * $simpleForm->submit($submittedViewData)
  44. * // inside:
  45. * $this->viewData = $submittedViewData
  46. * // then reverse transform
  47. *
  48. * The model data can be an array or an object, so this second argument is always passed
  49. * by reference.
  50. *
  51. * @param FormInterface[]|iterable $forms A list of {@link FormInterface} instances
  52. * @param mixed $viewData The compound form's view data that get mapped
  53. * its children model data
  54. *
  55. * @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported
  56. */
  57. public function mapFormsToData(iterable $forms, &$viewData);
  58. }