PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.0.2
WindPress – Tailwind CSS integration for WordPress v3.0.2
3.2.90 3.2.89 3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 All 144 releases
windpress / vendor / symfony / finder / Iterator / RecursiveDirectoryIterator.php

RecursiveDirectoryIterator.php in WindPress – Tailwind CSS integration for WordPress 3.0.2, at vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php

135 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace WindPressPackages\Symfony\Component\Finder\Iterator;
12
13 use WindPressPackages\Symfony\Component\Finder\Exception\AccessDeniedException;
14 use WindPressPackages\Symfony\Component\Finder\SplFileInfo;
15 /**
16 * Extends the \RecursiveDirectoryIterator to support relative paths.
17 *
18 * @author Victor Berchet <victor@suumit.com>
19 */
20 class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
21 {
22 /**
23 * @var bool
24 */
25 private $ignoreUnreadableDirs;
26 /**
27 * @var bool
28 */
29 private $ignoreFirstRewind = \true;
30 // these 3 properties take part of the performance optimization to avoid redoing the same work in all iterations
31 private $rootPath;
32 private $subPath;
33 private $directorySeparator = '/';
34 /**
35 * @throws \RuntimeException
36 */
37 public function __construct(string $path, int $flags, bool $ignoreUnreadableDirs = \false)
38 {
39 if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) {
40 throw new \RuntimeException('This iterator only support returning current as fileinfo.');
41 }
42 parent::__construct($path, $flags);
43 $this->ignoreUnreadableDirs = $ignoreUnreadableDirs;
44 $this->rootPath = $path;
45 if ('/' !== \DIRECTORY_SEPARATOR && !($flags & self::UNIX_PATHS)) {
46 $this->directorySeparator = \DIRECTORY_SEPARATOR;
47 }
48 }
49 /**
50 * Return an instance of SplFileInfo with support for relative paths.
51 *
52 * @return SplFileInfo
53 */
54 #[\ReturnTypeWillChange]
55 public function current()
56 {
57 // the logic here avoids redoing the same work in all iterations
58 if (null === $subPathname = $this->subPath) {
59 $subPathname = $this->subPath = $this->getSubPath();
60 }
61 if ('' !== $subPathname) {
62 $subPathname .= $this->directorySeparator;
63 }
64 $subPathname .= $this->getFilename();
65 if ('/' !== $basePath = $this->rootPath) {
66 $basePath .= $this->directorySeparator;
67 }
68 return new SplFileInfo($basePath . $subPathname, $this->subPath, $subPathname);
69 }
70 /**
71 * @param bool $allowLinks
72 *
73 * @return bool
74 */
75 #[\ReturnTypeWillChange]
76 public function hasChildren($allowLinks = \false)
77 {
78 $hasChildren = parent::hasChildren($allowLinks);
79 if (!$hasChildren || !$this->ignoreUnreadableDirs) {
80 return $hasChildren;
81 }
82 try {
83 parent::getChildren();
84 return \true;
85 } catch (\UnexpectedValueException $e) {
86 // If directory is unreadable and finder is set to ignore it, skip children
87 return \false;
88 }
89 }
90 /**
91 * @return \RecursiveDirectoryIterator
92 *
93 * @throws AccessDeniedException
94 */
95 #[\ReturnTypeWillChange]
96 public function getChildren()
97 {
98 try {
99 $children = parent::getChildren();
100 if ($children instanceof self) {
101 // parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore
102 $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
103 // performance optimization to avoid redoing the same work in all children
104 $children->rootPath = $this->rootPath;
105 }
106 return $children;
107 } catch (\UnexpectedValueException $e) {
108 throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
109 }
110 }
111 /**
112 * @return void
113 */
114 #[\ReturnTypeWillChange]
115 public function next()
116 {
117 $this->ignoreFirstRewind = \false;
118 parent::next();
119 }
120 /**
121 * @return void
122 */
123 #[\ReturnTypeWillChange]
124 public function rewind()
125 {
126 // some streams like FTP are not rewindable, ignore the first rewind after creation,
127 // as newly created DirectoryIterator does not need to be rewound
128 if ($this->ignoreFirstRewind) {
129 $this->ignoreFirstRewind = \false;
130 return;
131 }
132 parent::rewind();
133 }
134 }
135