FormRendererInterface.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. * Renders a form into HTML.
  13. *
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. */
  16. interface FormRendererInterface
  17. {
  18. /**
  19. * Returns the engine used by this renderer.
  20. *
  21. * @return FormRendererEngineInterface The renderer engine
  22. */
  23. public function getEngine();
  24. /**
  25. * Sets the theme(s) to be used for rendering a view and its children.
  26. *
  27. * @param FormView $view The view to assign the theme(s) to
  28. * @param mixed $themes The theme(s). The type of these themes
  29. * is open to the implementation.
  30. * @param bool $useDefaultThemes If true, will use default themes specified
  31. * in the renderer
  32. */
  33. public function setTheme(FormView $view, $themes, bool $useDefaultThemes = true);
  34. /**
  35. * Renders a named block of the form theme.
  36. *
  37. * @param FormView $view The view for which to render the block
  38. * @param array $variables The variables to pass to the template
  39. *
  40. * @return string The HTML markup
  41. */
  42. public function renderBlock(FormView $view, string $blockName, array $variables = []);
  43. /**
  44. * Searches and renders a block for a given name suffix.
  45. *
  46. * The block is searched by combining the block names stored in the
  47. * form view with the given suffix. If a block name is found, that
  48. * block is rendered.
  49. *
  50. * If this method is called recursively, the block search is continued
  51. * where a block was found before.
  52. *
  53. * @param FormView $view The view for which to render the block
  54. * @param array $variables The variables to pass to the template
  55. *
  56. * @return string The HTML markup
  57. */
  58. public function searchAndRenderBlock(FormView $view, string $blockNameSuffix, array $variables = []);
  59. /**
  60. * Renders a CSRF token.
  61. *
  62. * Use this helper for CSRF protection without the overhead of creating a
  63. * form.
  64. *
  65. * <input type="hidden" name="token" value="<?php $renderer->renderCsrfToken('rm_user_'.$user->getId()) ?>">
  66. *
  67. * Check the token in your action using the same token ID.
  68. *
  69. * // $csrfProvider being an instance of Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface
  70. * if (!$csrfProvider->isCsrfTokenValid('rm_user_'.$user->getId(), $token)) {
  71. * throw new \RuntimeException('CSRF attack detected.');
  72. * }
  73. *
  74. * @return string A CSRF token
  75. */
  76. public function renderCsrfToken(string $tokenId);
  77. /**
  78. * Makes a technical name human readable.
  79. *
  80. * Sequences of underscores are replaced by single spaces. The first letter
  81. * of the resulting string is capitalized, while all other letters are
  82. * turned to lowercase.
  83. *
  84. * @return string The humanized text
  85. */
  86. public function humanize(string $text);
  87. }