Route.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. *
  16. * @author Fabien Potencier <fabien@symfony.com>
  17. */
  18. class Route
  19. {
  20. private $path;
  21. private $name;
  22. private $requirements;
  23. private $options;
  24. private $defaults;
  25. private $host;
  26. private $methods;
  27. private $schemes;
  28. /**
  29. * Constructor.
  30. *
  31. * @param array $data An array of key/value parameters.
  32. *
  33. * @throws \BadMethodCallException
  34. */
  35. public function __construct(array $data)
  36. {
  37. $this->requirements = array();
  38. $this->options = array();
  39. $this->defaults = array();
  40. $this->methods = array();
  41. $this->schemes = array();
  42. if (isset($data['value'])) {
  43. $data['path'] = $data['value'];
  44. unset($data['value']);
  45. }
  46. foreach ($data as $key => $value) {
  47. $method = 'set'.str_replace('_', '', $key);
  48. if (!method_exists($this, $method)) {
  49. throw new \BadMethodCallException(sprintf("Unknown property '%s' on annotation '%s'.", $key, get_class($this)));
  50. }
  51. $this->$method($value);
  52. }
  53. }
  54. /**
  55. * @deprecated Deprecated in 2.2, to be removed in 3.0. Use setPath instead.
  56. */
  57. public function setPattern($pattern)
  58. {
  59. $this->path = $pattern;
  60. }
  61. /**
  62. * @deprecated Deprecated in 2.2, to be removed in 3.0. Use getPath instead.
  63. */
  64. public function getPattern()
  65. {
  66. return $this->path;
  67. }
  68. public function setPath($path)
  69. {
  70. $this->path = $path;
  71. }
  72. public function getPath()
  73. {
  74. return $this->path;
  75. }
  76. public function setHost($pattern)
  77. {
  78. $this->host = $pattern;
  79. }
  80. public function getHost()
  81. {
  82. return $this->host;
  83. }
  84. public function setName($name)
  85. {
  86. $this->name = $name;
  87. }
  88. public function getName()
  89. {
  90. return $this->name;
  91. }
  92. public function setRequirements($requirements)
  93. {
  94. $this->requirements = $requirements;
  95. }
  96. public function getRequirements()
  97. {
  98. return $this->requirements;
  99. }
  100. public function setOptions($options)
  101. {
  102. $this->options = $options;
  103. }
  104. public function getOptions()
  105. {
  106. return $this->options;
  107. }
  108. public function setDefaults($defaults)
  109. {
  110. $this->defaults = $defaults;
  111. }
  112. public function getDefaults()
  113. {
  114. return $this->defaults;
  115. }
  116. public function setSchemes($schemes)
  117. {
  118. $this->schemes = is_array($schemes) ? $schemes : array($schemes);
  119. }
  120. public function getSchemes()
  121. {
  122. return $this->schemes;
  123. }
  124. public function setMethods($methods)
  125. {
  126. $this->methods = is_array($methods) ? $methods : array($methods);
  127. }
  128. public function getMethods()
  129. {
  130. return $this->methods;
  131. }
  132. }