No Description

Route.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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\Routing\Annotation;
  11. /**
  12. * Annotation class for @Route().
  13. *
  14. * @Annotation
  15. * @Target({"CLASS", "METHOD"})
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class Route
  20. {
  21. private $path;
  22. private $localizedPaths = [];
  23. private $name;
  24. private $requirements = [];
  25. private $options = [];
  26. private $defaults = [];
  27. private $host;
  28. private $methods = [];
  29. private $schemes = [];
  30. private $condition;
  31. /**
  32. * @param array $data An array of key/value parameters
  33. *
  34. * @throws \BadMethodCallException
  35. */
  36. public function __construct(array $data)
  37. {
  38. if (isset($data['localized_paths'])) {
  39. throw new \BadMethodCallException(sprintf('Unknown property "localized_paths" on annotation "%s".', static::class));
  40. }
  41. if (isset($data['value'])) {
  42. $data[\is_array($data['value']) ? 'localized_paths' : 'path'] = $data['value'];
  43. unset($data['value']);
  44. }
  45. if (isset($data['path']) && \is_array($data['path'])) {
  46. $data['localized_paths'] = $data['path'];
  47. unset($data['path']);
  48. }
  49. if (isset($data['locale'])) {
  50. $data['defaults']['_locale'] = $data['locale'];
  51. unset($data['locale']);
  52. }
  53. if (isset($data['format'])) {
  54. $data['defaults']['_format'] = $data['format'];
  55. unset($data['format']);
  56. }
  57. if (isset($data['utf8'])) {
  58. $data['options']['utf8'] = filter_var($data['utf8'], \FILTER_VALIDATE_BOOLEAN) ?: false;
  59. unset($data['utf8']);
  60. }
  61. foreach ($data as $key => $value) {
  62. $method = 'set'.str_replace('_', '', $key);
  63. if (!method_exists($this, $method)) {
  64. throw new \BadMethodCallException(sprintf('Unknown property "%s" on annotation "%s".', $key, static::class));
  65. }
  66. $this->$method($value);
  67. }
  68. }
  69. public function setPath($path)
  70. {
  71. $this->path = $path;
  72. }
  73. public function getPath()
  74. {
  75. return $this->path;
  76. }
  77. public function setLocalizedPaths(array $localizedPaths)
  78. {
  79. $this->localizedPaths = $localizedPaths;
  80. }
  81. public function getLocalizedPaths(): array
  82. {
  83. return $this->localizedPaths;
  84. }
  85. public function setHost($pattern)
  86. {
  87. $this->host = $pattern;
  88. }
  89. public function getHost()
  90. {
  91. return $this->host;
  92. }
  93. public function setName($name)
  94. {
  95. $this->name = $name;
  96. }
  97. public function getName()
  98. {
  99. return $this->name;
  100. }
  101. public function setRequirements($requirements)
  102. {
  103. $this->requirements = $requirements;
  104. }
  105. public function getRequirements()
  106. {
  107. return $this->requirements;
  108. }
  109. public function setOptions($options)
  110. {
  111. $this->options = $options;
  112. }
  113. public function getOptions()
  114. {
  115. return $this->options;
  116. }
  117. public function setDefaults($defaults)
  118. {
  119. $this->defaults = $defaults;
  120. }
  121. public function getDefaults()
  122. {
  123. return $this->defaults;
  124. }
  125. public function setSchemes($schemes)
  126. {
  127. $this->schemes = \is_array($schemes) ? $schemes : [$schemes];
  128. }
  129. public function getSchemes()
  130. {
  131. return $this->schemes;
  132. }
  133. public function setMethods($methods)
  134. {
  135. $this->methods = \is_array($methods) ? $methods : [$methods];
  136. }
  137. public function getMethods()
  138. {
  139. return $this->methods;
  140. }
  141. public function setCondition($condition)
  142. {
  143. $this->condition = $condition;
  144. }
  145. public function getCondition()
  146. {
  147. return $this->condition;
  148. }
  149. }