Route.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. public function setPath($path)
  52. {
  53. $this->path = $path;
  54. }
  55. public function getPath()
  56. {
  57. return $this->path;
  58. }
  59. public function setHost($pattern)
  60. {
  61. $this->host = $pattern;
  62. }
  63. public function getHost()
  64. {
  65. return $this->host;
  66. }
  67. public function setName($name)
  68. {
  69. $this->name = $name;
  70. }
  71. public function getName()
  72. {
  73. return $this->name;
  74. }
  75. public function setRequirements($requirements)
  76. {
  77. $this->requirements = $requirements;
  78. }
  79. public function getRequirements()
  80. {
  81. return $this->requirements;
  82. }
  83. public function setOptions($options)
  84. {
  85. $this->options = $options;
  86. }
  87. public function getOptions()
  88. {
  89. return $this->options;
  90. }
  91. public function setDefaults($defaults)
  92. {
  93. $this->defaults = $defaults;
  94. }
  95. public function getDefaults()
  96. {
  97. return $this->defaults;
  98. }
  99. public function setSchemes($schemes)
  100. {
  101. $this->schemes = is_array($schemes) ? $schemes : array($schemes);
  102. }
  103. public function getSchemes()
  104. {
  105. return $this->schemes;
  106. }
  107. public function setMethods($methods)
  108. {
  109. $this->methods = is_array($methods) ? $methods : array($methods);
  110. }
  111. public function getMethods()
  112. {
  113. return $this->methods;
  114. }
  115. public function setCondition($condition)
  116. {
  117. $this->condition = $condition;
  118. }
  119. public function getCondition()
  120. {
  121. return $this->condition;
  122. }
  123. }