Drupal investigation

Expression.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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\Finder\Expression;
  11. @trigger_error('The '.__NAMESPACE__.'\Expression class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  12. /**
  13. * @author Jean-François Simon <contact@jfsimon.fr>
  14. */
  15. class Expression implements ValueInterface
  16. {
  17. const TYPE_REGEX = 1;
  18. const TYPE_GLOB = 2;
  19. /**
  20. * @var ValueInterface
  21. */
  22. private $value;
  23. /**
  24. * @param string $expr
  25. *
  26. * @return self
  27. */
  28. public static function create($expr)
  29. {
  30. return new self($expr);
  31. }
  32. /**
  33. * @param string $expr
  34. */
  35. public function __construct($expr)
  36. {
  37. try {
  38. $this->value = Regex::create($expr);
  39. } catch (\InvalidArgumentException $e) {
  40. $this->value = new Glob($expr);
  41. }
  42. }
  43. /**
  44. * @return string
  45. */
  46. public function __toString()
  47. {
  48. return $this->render();
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function render()
  54. {
  55. return $this->value->render();
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function renderPattern()
  61. {
  62. return $this->value->renderPattern();
  63. }
  64. /**
  65. * @return bool
  66. */
  67. public function isCaseSensitive()
  68. {
  69. return $this->value->isCaseSensitive();
  70. }
  71. /**
  72. * @return int
  73. */
  74. public function getType()
  75. {
  76. return $this->value->getType();
  77. }
  78. /**
  79. * {@inheritdoc}
  80. */
  81. public function prepend($expr)
  82. {
  83. $this->value->prepend($expr);
  84. return $this;
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function append($expr)
  90. {
  91. $this->value->append($expr);
  92. return $this;
  93. }
  94. /**
  95. * @return bool
  96. */
  97. public function isRegex()
  98. {
  99. return self::TYPE_REGEX === $this->value->getType();
  100. }
  101. /**
  102. * @return bool
  103. */
  104. public function isGlob()
  105. {
  106. return self::TYPE_GLOB === $this->value->getType();
  107. }
  108. /**
  109. * @return Glob
  110. *
  111. * @throws \LogicException
  112. */
  113. public function getGlob()
  114. {
  115. if (self::TYPE_GLOB !== $this->value->getType()) {
  116. throw new \LogicException('Regex can\'t be transformed to glob.');
  117. }
  118. return $this->value;
  119. }
  120. /**
  121. * @return Regex
  122. */
  123. public function getRegex()
  124. {
  125. return self::TYPE_REGEX === $this->value->getType() ? $this->value : $this->value->toRegex();
  126. }
  127. }