Glob.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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__.'\Glob class is deprecated since Symfony 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  12. use Symfony\Component\Finder\Glob as FinderGlob;
  13. /**
  14. * @author Jean-François Simon <contact@jfsimon.fr>
  15. */
  16. class Glob implements ValueInterface
  17. {
  18. private $pattern;
  19. /**
  20. * @param string $pattern
  21. */
  22. public function __construct($pattern)
  23. {
  24. $this->pattern = $pattern;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function render()
  30. {
  31. return $this->pattern;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function renderPattern()
  37. {
  38. return $this->pattern;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function getType()
  44. {
  45. return Expression::TYPE_GLOB;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function isCaseSensitive()
  51. {
  52. return true;
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function prepend($expr)
  58. {
  59. $this->pattern = $expr.$this->pattern;
  60. return $this;
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function append($expr)
  66. {
  67. $this->pattern .= $expr;
  68. return $this;
  69. }
  70. /**
  71. * Tests if glob is expandable ("*.{a,b}" syntax).
  72. *
  73. * @return bool
  74. */
  75. public function isExpandable()
  76. {
  77. return false !== strpos($this->pattern, '{')
  78. && false !== strpos($this->pattern, '}');
  79. }
  80. /**
  81. * @param bool $strictLeadingDot
  82. * @param bool $strictWildcardSlash
  83. *
  84. * @return Regex
  85. */
  86. public function toRegex($strictLeadingDot = true, $strictWildcardSlash = true)
  87. {
  88. $regex = FinderGlob::toRegex($this->pattern, $strictLeadingDot, $strictWildcardSlash, '');
  89. return new Regex($regex);
  90. }
  91. }