Automattic\WooCommerce\Internal\Utilities

FilesystemUtil::file_is_in_directoryprivate staticWC 1.0

Check if a given file is inside a given directory.

Метод класса: FilesystemUtil{}

Хуков нет.

Возвращает

true|false. True if the file is inside the directory.

Использование

$result = FilesystemUtil::file_is_in_directory( $file_path, $directory ): bool;
$file_path(строка) (обязательный)
The full path of the file to check.
$directory(строка) (обязательный)
The path of the directory to check.

Код FilesystemUtil::file_is_in_directory() WC 9.9.4

private static function file_is_in_directory( string $file_path, string $directory ): bool {
	// Extract protocol if it exists.
	$protocol = '';
	if ( preg_match( '#^([a-z0-9]+://)#i', $file_path, $matches ) ) {
		$protocol  = $matches[1];
		$file_path = preg_replace( '#^[a-z0-9]+://#i', '', $file_path );
	}

	$file_path = (string) new URL( $file_path ); // This resolves '/../' sequences.
	$file_path = preg_replace( '/^file:\\/\\//', $protocol, $file_path );
	$file_path = preg_replace( '/^file:\\/\\//', '', $file_path );

	return 0 === stripos( wp_normalize_path( $file_path ), trailingslashit( wp_normalize_path( $directory ) ) );
}