vendor/sensio/framework-extra-bundle/src/Configuration/Template.php line 21

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <[email protected]>
  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 Sensio\Bundle\FrameworkExtraBundle\Configuration;
  11. /**
  12. * The Template class handles the Template annotation parts.
  13. *
  14. * @author Fabien Potencier <[email protected]>
  15. * @Annotation
  16. */
  17. #[\Attribute(\Attribute::TARGET_METHOD)]
  18. class Template extends ConfigurationAnnotation
  19. {
  20. /**
  21. * The template.
  22. *
  23. * @var string
  24. */
  25. protected $template;
  26. /**
  27. * The associative array of template variables.
  28. *
  29. * @var array
  30. */
  31. private $vars = [];
  32. /**
  33. * Should the template be streamed?
  34. *
  35. * @var bool
  36. */
  37. private $streamable = false;
  38. /**
  39. * The controller (+action) this annotation is set to.
  40. *
  41. * @var array
  42. */
  43. private $owner = [];
  44. /**
  45. * @param array|string $data
  46. */
  47. public function __construct(
  48. $data = [],
  49. array $vars = [],
  50. bool $isStreamable = false,
  51. array $owner = []
  52. ) {
  53. $values = [];
  54. if (\is_string($data)) {
  55. $values['template'] = $data;
  56. } else {
  57. $values = $data;
  58. }
  59. $values['isStreamable'] = $values['isStreamable'] ?? $isStreamable;
  60. $values['vars'] = $values['vars'] ?? $vars;
  61. $values['owner'] = $values['owner'] ?? $owner;
  62. parent::__construct($values);
  63. }
  64. /**
  65. * Returns the array of templates variables.
  66. *
  67. * @return array
  68. */
  69. public function getVars()
  70. {
  71. return $this->vars;
  72. }
  73. /**
  74. * @param bool $streamable
  75. */
  76. public function setIsStreamable($streamable)
  77. {
  78. $this->streamable = $streamable;
  79. }
  80. /**
  81. * @return bool
  82. */
  83. public function isStreamable()
  84. {
  85. return (bool) $this->streamable;
  86. }
  87. /**
  88. * Sets the template variables.
  89. *
  90. * @param array $vars The template variables
  91. */
  92. public function setVars($vars)
  93. {
  94. $this->vars = $vars;
  95. }
  96. /**
  97. * Sets the template logic name.
  98. *
  99. * @param string $template The template logic name
  100. */
  101. public function setValue($template)
  102. {
  103. $this->setTemplate($template);
  104. }
  105. /**
  106. * Returns the template.
  107. *
  108. * @return string
  109. */
  110. public function getTemplate()
  111. {
  112. return $this->template;
  113. }
  114. /**
  115. * Sets the template.
  116. *
  117. * @param string $template The template
  118. */
  119. public function setTemplate($template)
  120. {
  121. $this->template = $template;
  122. }
  123. /**
  124. * Returns the annotation alias name.
  125. *
  126. * @return string
  127. *
  128. * @see ConfigurationInterface
  129. */
  130. public function getAliasName()
  131. {
  132. return 'template';
  133. }
  134. /**
  135. * Only one template directive is allowed.
  136. *
  137. * @return bool
  138. *
  139. * @see ConfigurationInterface
  140. */
  141. public function allowArray()
  142. {
  143. return false;
  144. }
  145. public function setOwner(array $owner)
  146. {
  147. $this->owner = $owner;
  148. }
  149. /**
  150. * The controller (+action) this annotation is attached to.
  151. *
  152. * @return array
  153. */
  154. public function getOwner()
  155. {
  156. return $this->owner;
  157. }
  158. }