FormRendererInterface.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. */
  31. public function setTheme(FormView $view, $themes);
  32. /**
  33. * Renders a named block of the form theme.
  34. *
  35. * @param FormView $view The view for which to render the block
  36. * @param string $blockName The name of the block
  37. * @param array $variables The variables to pass to the template
  38. *
  39. * @return string The HTML markup
  40. */
  41. public function renderBlock(FormView $view, $blockName, array $variables = array());
  42. /**
  43. * Searches and renders a block for a given name suffix.
  44. *
  45. * The block is searched by combining the block names stored in the
  46. * form view with the given suffix. If a block name is found, that
  47. * block is rendered.
  48. *
  49. * If this method is called recursively, the block search is continued
  50. * where a block was found before.
  51. *
  52. * @param FormView $view The view for which to render the block
  53. * @param string $blockNameSuffix The suffix of the block name
  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, $blockNameSuffix, array $variables = array());
  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 = $this->get('security.csrf.token_generator');
  70. * if (!$csrfProvider->isCsrfTokenValid('rm_user_'.$user->getId(), $token)) {
  71. * throw new \RuntimeException('CSRF attack detected.');
  72. * }
  73. *
  74. * @param string $tokenId The ID of the CSRF token
  75. *
  76. * @return string A CSRF token
  77. */
  78. public function renderCsrfToken($tokenId);
  79. /**
  80. * Makes a technical name human readable.
  81. *
  82. * Sequences of underscores are replaced by single spaces. The first letter
  83. * of the resulting string is capitalized, while all other letters are
  84. * turned to lowercase.
  85. *
  86. * @param string $text The text to humanize
  87. *
  88. * @return string The humanized text
  89. */
  90. public function humanize($text);
  91. }