DataAccessorInterface.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * Writes and reads values to/from an object or array bound to a form.
  13. *
  14. * @author Yonel Ceruto <yonelceruto@gmail.com>
  15. */
  16. interface DataAccessorInterface
  17. {
  18. /**
  19. * Returns the value at the end of the property of the object graph.
  20. *
  21. * @param object|array $viewData The view data of the compound form
  22. * @param FormInterface $form The {@link FormInterface()} instance to check
  23. *
  24. * @return mixed The value at the end of the property
  25. *
  26. * @throws Exception\AccessException If unable to read from the given form data
  27. */
  28. public function getValue($viewData, FormInterface $form);
  29. /**
  30. * Sets the value at the end of the property of the object graph.
  31. *
  32. * @param object|array $viewData The view data of the compound form
  33. * @param mixed $value The value to set at the end of the object graph
  34. * @param FormInterface $form The {@link FormInterface()} instance to check
  35. *
  36. * @throws Exception\AccessException If unable to write the given value
  37. */
  38. public function setValue(&$viewData, $value, FormInterface $form): void;
  39. /**
  40. * Returns whether a value can be read from an object graph.
  41. *
  42. * Whenever this method returns true, {@link getValue()} is guaranteed not
  43. * to throw an exception when called with the same arguments.
  44. *
  45. * @param object|array $viewData The view data of the compound form
  46. * @param FormInterface $form The {@link FormInterface()} instance to check
  47. *
  48. * @return bool Whether the value can be read
  49. */
  50. public function isReadable($viewData, FormInterface $form): bool;
  51. /**
  52. * Returns whether a value can be written at a given object graph.
  53. *
  54. * Whenever this method returns true, {@link setValue()} is guaranteed not
  55. * to throw an exception when called with the same arguments.
  56. *
  57. * @param object|array $viewData The view data of the compound form
  58. * @param FormInterface $form The {@link FormInterface()} instance to check
  59. *
  60. * @return bool Whether the value can be set
  61. */
  62. public function isWritable($viewData, FormInterface $form): bool;
  63. }