|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Install functions |
|
5
|
|
|
* |
|
6
|
|
|
* Used through vendor/bin/phpcompat_(en|dis)able |
|
7
|
|
|
* |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
class PHPCompatibility_Install { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Files which need to be copied over and live in the root directory of this project. |
|
14
|
|
|
* |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
public static $root_dir_files = array( |
|
18
|
|
|
'ruleset.xml', |
|
19
|
|
|
'Sniff.php', |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
static function enable() { |
|
|
|
|
|
|
23
|
|
|
echo "(Re-)Enabling PHPCompatibility\n"; |
|
24
|
|
|
self::make_copy(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
static function disable() { |
|
|
|
|
|
|
28
|
|
|
self::remove_copy(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
static function update() { |
|
|
|
|
|
|
32
|
|
|
self::disable(); |
|
33
|
|
|
self::enable(); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
static function make_copy() { |
|
|
|
|
|
|
37
|
|
|
$srcDir = dirname(__DIR__); |
|
38
|
|
|
$copy = dirname(__DIR__).DIRECTORY_SEPARATOR.'PHPCompatibility'; |
|
39
|
|
|
|
|
40
|
|
|
if ( file_exists ($copy)) { |
|
41
|
|
|
echo "Copy workaround is already in place\n"; |
|
42
|
|
|
return; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if (mkdir($copy) === true) { |
|
46
|
|
|
foreach (self::$root_dir_files as $filename) { |
|
47
|
|
|
copy($srcDir.DIRECTORY_SEPARATOR.$filename, $copy.DIRECTORY_SEPARATOR.$filename); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
51
|
|
|
$copy = str_replace('/', DIRECTORY_SEPARATOR, $copy); |
|
52
|
|
|
$srcDir = str_replace('/', DIRECTORY_SEPARATOR, $srcDir); |
|
53
|
|
|
passthru('xcopy "'.$srcDir .DIRECTORY_SEPARATOR.'Sniffs" "'.$copy.DIRECTORY_SEPARATOR.'Sniffs" /S /E /I'); |
|
54
|
|
|
} else { |
|
55
|
|
|
passthru('cp -r "'.$srcDir .DIRECTORY_SEPARATOR.'Sniffs" "'.$copy.DIRECTORY_SEPARATOR.'Sniffs"'); |
|
56
|
|
|
} |
|
57
|
|
|
echo "Created copy workaround\n"; |
|
58
|
|
|
} else { |
|
59
|
|
|
echo "Failed to create the $copy directory\n"; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
static function remove_copy() { |
|
|
|
|
|
|
64
|
|
|
$copy = dirname(__DIR__).DIRECTORY_SEPARATOR.'PHPCompatibility'; |
|
65
|
|
|
|
|
66
|
|
|
if ( ! file_exists ($copy)) { |
|
67
|
|
|
echo "No copy workaround to remove\n"; |
|
68
|
|
|
return; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
72
|
|
|
$copy = str_replace('/', DIRECTORY_SEPARATOR, $copy); |
|
73
|
|
|
passthru('rmdir /S /Q "'.$copy.'"'); |
|
74
|
|
|
} else { |
|
75
|
|
|
passthru('rm -rf "'.$copy.'"'); |
|
76
|
|
|
} |
|
77
|
|
|
echo "Copy workaround removed\n"; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.