Route.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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".', \get_class($this)));
  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. foreach ($data as $key => $value) {
  50. $method = 'set'.str_replace('_', '', $key);
  51. if (!method_exists($this, $method)) {
  52. throw new \BadMethodCallException(sprintf('Unknown property "%s" on annotation "%s".', $key, \get_class($this)));
  53. }
  54. $this->$method($value);
  55. }
  56. }
  57. public function setPath($path)
  58. {
  59. $this->path = $path;
  60. }
  61. public function getPath()
  62. {
  63. return $this->path;
  64. }
  65. public function setLocalizedPaths(array $localizedPaths)
  66. {
  67. $this->localizedPaths = $localizedPaths;
  68. }
  69. public function getLocalizedPaths(): array
  70. {
  71. return $this->localizedPaths;
  72. }
  73. public function setHost($pattern)
  74. {
  75. $this->host = $pattern;
  76. }
  77. public function getHost()
  78. {
  79. return $this->host;
  80. }
  81. public function setName($name)
  82. {
  83. $this->name = $name;
  84. }
  85. public function getName()
  86. {
  87. return $this->name;
  88. }
  89. public function setRequirements($requirements)
  90. {
  91. $this->requirements = $requirements;
  92. }
  93. public function getRequirements()
  94. {
  95. return $this->requirements;
  96. }
  97. public function setOptions($options)
  98. {
  99. $this->options = $options;
  100. }
  101. public function getOptions()
  102. {
  103. return $this->options;
  104. }
  105. public function setDefaults($defaults)
  106. {
  107. $this->defaults = $defaults;
  108. }
  109. public function getDefaults()
  110. {
  111. return $this->defaults;
  112. }
  113. public function setSchemes($schemes)
  114. {
  115. $this->schemes = \is_array($schemes) ? $schemes : [$schemes];
  116. }
  117. public function getSchemes()
  118. {
  119. return $this->schemes;
  120. }
  121. public function setMethods($methods)
  122. {
  123. $this->methods = \is_array($methods) ? $methods : [$methods];
  124. }
  125. public function getMethods()
  126. {
  127. return $this->methods;
  128. }
  129. public function setCondition($condition)
  130. {
  131. $this->condition = $condition;
  132. }
  133. public function getCondition()
  134. {
  135. return $this->condition;
  136. }
  137. }