all-in-one-wp-migration
/
lib
/
vendor
/
servmask
/
iterator
/
class-ai1wm-recursive-directory-iterator.php
class-ai1wm-recursive-directory-iterator.php
1 year ago
class-ai1wm-recursive-iterator-iterator.php
1 year ago
class-ai1wm-recursive-directory-iterator.php
76 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright (C) 2014-2025 ServMask Inc. |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * Attribution: This code is part of the All-in-One WP Migration plugin, developed by |
| 19 | * |
| 20 | * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗ |
| 21 | * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝ |
| 22 | * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝ |
| 23 | * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗ |
| 24 | * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗ |
| 25 | * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ |
| 26 | */ |
| 27 | |
| 28 | if ( ! defined( 'ABSPATH' ) ) { |
| 29 | die( 'Kangaroos cannot jump here' ); |
| 30 | } |
| 31 | |
| 32 | class Ai1wm_Recursive_Directory_Iterator extends RecursiveDirectoryIterator { |
| 33 | |
| 34 | public function __construct( $path ) { |
| 35 | parent::__construct( $path ); |
| 36 | |
| 37 | // Skip current and parent directory |
| 38 | $this->skipdots(); |
| 39 | } |
| 40 | |
| 41 | #[\ReturnTypeWillChange] |
| 42 | public function rewind() { |
| 43 | parent::rewind(); |
| 44 | |
| 45 | // Skip current and parent directory |
| 46 | $this->skipdots(); |
| 47 | } |
| 48 | |
| 49 | #[\ReturnTypeWillChange] |
| 50 | public function next() { |
| 51 | parent::next(); |
| 52 | |
| 53 | // Skip current and parent directory |
| 54 | $this->skipdots(); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns whether current entry is a directory and not '.' or '..' |
| 59 | * |
| 60 | * Explicitly set allow links flag, because RecursiveDirectoryIterator::FOLLOW_SYMLINKS |
| 61 | * is not supported by <= PHP 5.3.0 |
| 62 | * |
| 63 | * @return bool |
| 64 | */ |
| 65 | #[\ReturnTypeWillChange] |
| 66 | public function hasChildren( $allow_links = true ) { |
| 67 | return parent::hasChildren( $allow_links ); |
| 68 | } |
| 69 | |
| 70 | protected function skipdots() { |
| 71 | while ( $this->isDot() ) { |
| 72 | parent::next(); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 |