Route.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * @param array $data An array of key/value parameters
  32. *
  33. * @throws \BadMethodCallException
  34. */
  35. public function __construct(array $data)
  36. {
  37. if (isset($data['value'])) {
  38. $data['path'] = $data['value'];
  39. unset($data['value']);
  40. }
  41. foreach ($data as $key => $value) {
  42. $method = 'set'.str_replace('_', '', $key);
  43. if (!method_exists($this, $method)) {
  44. throw new \BadMethodCallException(sprintf('Unknown property "%s" on annotation "%s".', $key, get_class($this)));
  45. }
  46. $this->$method($value);
  47. }
  48. }
  49. public function setPath($path)
  50. {
  51. $this->path = $path;
  52. }
  53. public function getPath()
  54. {
  55. return $this->path;
  56. }
  57. public function setHost($pattern)
  58. {
  59. $this->host = $pattern;
  60. }
  61. public function getHost()
  62. {
  63. return $this->host;
  64. }
  65. public function setName($name)
  66. {
  67. $this->name = $name;
  68. }
  69. public function getName()
  70. {
  71. return $this->name;
  72. }
  73. public function setRequirements($requirements)
  74. {
  75. $this->requirements = $requirements;
  76. }
  77. public function getRequirements()
  78. {
  79. return $this->requirements;
  80. }
  81. public function setOptions($options)
  82. {
  83. $this->options = $options;
  84. }
  85. public function getOptions()
  86. {
  87. return $this->options;
  88. }
  89. public function setDefaults($defaults)
  90. {
  91. $this->defaults = $defaults;
  92. }
  93. public function getDefaults()
  94. {
  95. return $this->defaults;
  96. }
  97. public function setSchemes($schemes)
  98. {
  99. $this->schemes = is_array($schemes) ? $schemes : array($schemes);
  100. }
  101. public function getSchemes()
  102. {
  103. return $this->schemes;
  104. }
  105. public function setMethods($methods)
  106. {
  107. $this->methods = is_array($methods) ? $methods : array($methods);
  108. }
  109. public function getMethods()
  110. {
  111. return $this->methods;
  112. }
  113. public function setCondition($condition)
  114. {
  115. $this->condition = $condition;
  116. }
  117. public function getCondition()
  118. {
  119. return $this->condition;
  120. }
  121. }