Drupal investigation

FilePathsIterator.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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\Iterator;
  11. @trigger_error('The '.__NAMESPACE__.'\FilePathsIterator class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
  12. use Symfony\Component\Finder\SplFileInfo;
  13. /**
  14. * Iterate over shell command result.
  15. *
  16. * @author Jean-François Simon <contact@jfsimon.fr>
  17. *
  18. * @deprecated since 2.8, to be removed in 3.0.
  19. */
  20. class FilePathsIterator extends \ArrayIterator
  21. {
  22. /**
  23. * @var string
  24. */
  25. private $baseDir;
  26. /**
  27. * @var int
  28. */
  29. private $baseDirLength;
  30. /**
  31. * @var string
  32. */
  33. private $subPath;
  34. /**
  35. * @var string
  36. */
  37. private $subPathname;
  38. /**
  39. * @var SplFileInfo
  40. */
  41. private $current;
  42. /**
  43. * @param array $paths List of paths returned by shell command
  44. * @param string $baseDir Base dir for relative path building
  45. */
  46. public function __construct(array $paths, $baseDir)
  47. {
  48. $this->baseDir = $baseDir;
  49. $this->baseDirLength = strlen($baseDir);
  50. parent::__construct($paths);
  51. }
  52. /**
  53. * @param string $name
  54. * @param array $arguments
  55. *
  56. * @return mixed
  57. */
  58. public function __call($name, array $arguments)
  59. {
  60. return call_user_func_array(array($this->current(), $name), $arguments);
  61. }
  62. /**
  63. * Return an instance of SplFileInfo with support for relative paths.
  64. *
  65. * @return SplFileInfo File information
  66. */
  67. public function current()
  68. {
  69. return $this->current;
  70. }
  71. /**
  72. * @return string
  73. */
  74. public function key()
  75. {
  76. return $this->current->getPathname();
  77. }
  78. public function next()
  79. {
  80. parent::next();
  81. $this->buildProperties();
  82. }
  83. public function rewind()
  84. {
  85. parent::rewind();
  86. $this->buildProperties();
  87. }
  88. /**
  89. * @return string
  90. */
  91. public function getSubPath()
  92. {
  93. return $this->subPath;
  94. }
  95. /**
  96. * @return string
  97. */
  98. public function getSubPathname()
  99. {
  100. return $this->subPathname;
  101. }
  102. private function buildProperties()
  103. {
  104. $absolutePath = parent::current();
  105. if ($this->baseDir === substr($absolutePath, 0, $this->baseDirLength)) {
  106. $this->subPathname = ltrim(substr($absolutePath, $this->baseDirLength), '/\\');
  107. $dir = dirname($this->subPathname);
  108. $this->subPath = '.' === $dir ? '' : $dir;
  109. } else {
  110. $this->subPath = $this->subPathname = '';
  111. }
  112. $this->current = new SplFileInfo(parent::current(), $this->subPath, $this->subPathname);
  113. }
  114. }