/var/www/html/wp-content/plugins/woocommerce/vendor/automattic/jetpack-status/src/class-files.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
 * A modules class for Jetpack.
 *
 * @package automattic/jetpack-status
 */

namespace Automattic\Jetpack;

/**
 * Class Automattic\Jetpack\Files
 *
 * Used to retrieve information about files.
 */
class Files {
    
/**
     * Returns an array of all PHP files in the specified absolute path.
     * Equivalent to glob( "$absolute_path/*.php" ).
     *
     * @param string $absolute_path The absolute path of the directory to search.
     * @return array Array of absolute paths to the PHP files.
     */
    
public function glob_php$absolute_path ) {
        if ( 
function_exists'glob' ) ) {
            return 
glob"$absolute_path/*.php" );
        }

        
$absolute_path untrailingslashit$absolute_path );
        
$files         = array();
        
$dir           = @opendir$absolute_path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
        
if ( ! $dir ) {
            return 
$files;
        }

        
// phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition
        
while ( false !== $file readdir$dir ) ) {
            if ( 
str_starts_with$file'.' ) || ! str_ends_with$file'.php' ) ) {
                continue;
            }

            
$file "$absolute_path/$file";

            if ( ! 
is_file$file ) ) {
                continue;
            }

            
$files[] = $file;
        }

        
closedir$dir );

        return 
$files;
    }
}