No Description

Route.php 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 $name;
  23. private $requirements = array();
  24. private $options = array();
  25. private $defaults = array();
  26. private $host;
  27. private $methods = array();
  28. private $schemes = array();
  29. private $condition;
  30. /**
  31. * Constructor.
  32. *
  33. * @param array $data An array of key/value parameters.
  34. *
  35. * @throws \BadMethodCallException
  36. */
  37. public function __construct(array $data)
  38. {
  39. if (isset($data['value'])) {
  40. $data['path'] = $data['value'];
  41. unset($data['value']);
  42. }
  43. foreach ($data as $key => $value) {
  44. $method = 'set'.str_replace('_', '', $key);
  45. if (!method_exists($this, $method)) {
  46. throw new \BadMethodCallException(sprintf("Unknown property '%s' on annotation '%s'.", $key, get_class($this)));
  47. }
  48. $this->$method($value);
  49. }
  50. }
  51. /**
  52. * @deprecated Deprecated in 2.2, to be removed in 3.0. Use setPath instead.
  53. */
  54. public function setPattern($pattern)
  55. {
  56. $this->path = $pattern;
  57. }
  58. /**
  59. * @deprecated Deprecated in 2.2, to be removed in 3.0. Use getPath instead.
  60. */
  61. public function getPattern()
  62. {
  63. return $this->path;
  64. }
  65. public function setPath($path)
  66. {
  67. $this->path = $path;
  68. }
  69. public function getPath()
  70. {
  71. return $this->path;
  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 : array($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 : array($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. }