class-backup-utilities.php
1.5 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace HM\BackUpWordPress;
use Symfony\Component\Process\Process as Process;
/**
* A set of Backup Utility functions
*/
class Backup_Utilities {
/**
* Checks whether Safe Mode is currently on
*
* @param string $ini_get_callback By default we use `ini_get` to check for
* the Safe Mode setting but this can be
* overridden for testing purposes.
*
* @return boolean Whether Safe Mode is on or off.
*/
public static function is_safe_mode_on( $ini_get_callback = 'ini_get' ) {
$safe_mode = @call_user_func( $ini_get_callback, 'safe_mode' );
if ( $safe_mode && strtolower( $safe_mode ) !== 'off' ) {
return true;
}
return false;
}
/**
* Attempt to work out path to a cli executable.
*
* @param array $paths An array of paths to check against.
*
* @return string|false The path to the executable.
*/
public static function get_executable_path( $paths ) {
if ( ! function_exists( 'proc_open' ) || ! function_exists( 'proc_close' ) ) {
return false;
}
$paths = array_map( 'wp_normalize_path', $paths );
foreach ( $paths as $path ) {
/**
* Attempt to call `--version` on each path, the one which works
* must be the correct path.
*/
$process = new Process( $path . ' --version' );
try {
$process->run();
} catch ( \Exception $e ) {
return false;
}
if ( $process->isSuccessful() ) {
return $path;
}
}
return false;
}
}