vendor/friendsofsymfony/rest-bundle/Controller/Annotations/View.php line 74

  1. <?php
  2. /*
  3. * This file is part of the FOSRestBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\RestBundle\Controller\Annotations;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  12. if (class_exists(Template::class)) {
  13. /**
  14. * Compat class for applications where SensioFrameworkExtraBundle is installed, to be removed when compatibility with the bundle is no longer provided.
  15. *
  16. * @internal
  17. */
  18. abstract class CompatView extends Template
  19. {
  20. }
  21. } else {
  22. /**
  23. * Compat class for applications where SensioFrameworkExtraBundle is not installed.
  24. *
  25. * @internal
  26. */
  27. abstract class CompatView
  28. {
  29. /**
  30. * The controller (+action) this annotation is set to.
  31. *
  32. * @var array
  33. *
  34. * @note This property is declared within this compat class to not conflict with the {@see Template::$owner}
  35. * property when SensioFrameworkExtraBundle is present.
  36. */
  37. protected $owner = [];
  38. /**
  39. * @note This method is declared within this compat class to not conflict with the {@see Template::setOwner}
  40. * method when SensioFrameworkExtraBundle is present.
  41. */
  42. public function setOwner(array $owner)
  43. {
  44. $this->owner = $owner;
  45. }
  46. /**
  47. * The controller (+action) this annotation is attached to.
  48. *
  49. * @return array
  50. *
  51. * @note This method is declared within this compat class to not conflict with the {@see Template::getOwner}
  52. * method when SensioFrameworkExtraBundle is present.
  53. */
  54. public function getOwner()
  55. {
  56. return $this->owner;
  57. }
  58. }
  59. }
  60. /**
  61. * View annotation class.
  62. *
  63. * @Annotation
  64. * @Target({"METHOD","CLASS"})
  65. */
  66. #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
  67. class View extends CompatView
  68. {
  69. /**
  70. * @var int|null
  71. */
  72. protected $statusCode;
  73. /**
  74. * @var array
  75. */
  76. protected $serializerGroups;
  77. /**
  78. * @var bool
  79. */
  80. protected $serializerEnableMaxDepthChecks;
  81. /**
  82. * @param array|string $data
  83. */
  84. public function __construct(
  85. $data = [],
  86. array $vars = [],
  87. bool $isStreamable = false,
  88. array $owner = [],
  89. ?int $statusCode = null,
  90. array $serializerGroups = [],
  91. bool $serializerEnableMaxDepthChecks = false
  92. ) {
  93. if ($this instanceof Template) {
  94. trigger_deprecation('friendsofsymfony/rest-bundle', '3.7', 'Extending from "%s" in "%s" is deprecated, the $vars and $isStreamable constructor arguments will not be supported when "sensio/framework-extra-bundle" is not installed and will be removed completely in 4.0.', Template::class, static::class);
  95. parent::__construct($data, $vars, $isStreamable, $owner);
  96. } elseif ([] !== $vars) {
  97. trigger_deprecation('friendsofsymfony/rest-bundle', '3.7', 'Extending from "%s" in "%s" is deprecated and "sensio/framework-extra-bundle" is not installed, the $vars and $isStreamable constructor arguments will be ignored and removed completely in 4.0.', Template::class, static::class);
  98. }
  99. $values = is_array($data) ? $data : [];
  100. $this->statusCode = $values['statusCode'] ?? $statusCode;
  101. $this->serializerGroups = $values['serializerGroups'] ?? $serializerGroups;
  102. $this->serializerEnableMaxDepthChecks = $values['serializerEnableMaxDepthChecks'] ?? $serializerEnableMaxDepthChecks;
  103. // Use the setter to initialize the owner; when extending the Template class, the property will be private
  104. $this->setOwner($values['owner'] ?? $owner);
  105. }
  106. /**
  107. * @param int $statusCode
  108. */
  109. public function setStatusCode($statusCode)
  110. {
  111. $this->statusCode = $statusCode;
  112. }
  113. /**
  114. * @return int|null
  115. */
  116. public function getStatusCode()
  117. {
  118. return $this->statusCode;
  119. }
  120. /**
  121. * @param array $serializerGroups
  122. */
  123. public function setSerializerGroups($serializerGroups)
  124. {
  125. $this->serializerGroups = $serializerGroups;
  126. }
  127. /**
  128. * @return array
  129. */
  130. public function getSerializerGroups()
  131. {
  132. return $this->serializerGroups;
  133. }
  134. /**
  135. * @param bool $serializerEnableMaxDepthChecks
  136. */
  137. public function setSerializerEnableMaxDepthChecks($serializerEnableMaxDepthChecks)
  138. {
  139. $this->serializerEnableMaxDepthChecks = $serializerEnableMaxDepthChecks;
  140. }
  141. /**
  142. * @return bool
  143. */
  144. public function getSerializerEnableMaxDepthChecks()
  145. {
  146. return $this->serializerEnableMaxDepthChecks;
  147. }
  148. }