|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class PHPCompatibility_Install { |
|
|
|
|
|
|
4
|
|
|
static function enable() { |
|
|
|
|
|
|
5
|
|
|
echo "Enabling PHPCompatibility\n"; |
|
6
|
|
|
self::make_copy(); |
|
7
|
|
|
self::register_in_cs(); |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
static function disable() { |
|
|
|
|
|
|
11
|
|
|
echo "Disabling PHPCompatibility\n"; |
|
12
|
|
|
self::remove_copy(); |
|
13
|
|
|
self::unregister_from_cs(); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
static function register_in_cs() { |
|
|
|
|
|
|
17
|
|
|
if (PHP_CodeSniffer::getConfigData('installed_paths') === NULL) { |
|
18
|
|
|
PHP_CodeSniffer::setConfigData('installed_paths', __DIR__); |
|
19
|
|
|
echo "Registered our path in PHP CodeSniffer\n"; |
|
20
|
|
|
} else if (PHP_CodeSniffer::getConfigData('installed_paths') === __DIR__ ) { |
|
21
|
|
|
echo "Our path is already registered in PHP CodeSniffer\n";; |
|
22
|
|
|
} else { |
|
23
|
|
|
throw new Exception("Another path is registered in Code Sniffer conf :("); |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
static function unregister_from_cs() { |
|
|
|
|
|
|
28
|
|
|
if (PHP_CodeSniffer::getConfigData('installed_paths') === __DIR__) { |
|
29
|
|
|
PHP_CodeSniffer::setConfigData('installed_paths', NULL); |
|
30
|
|
|
echo "Unregistered our path in PHP CodeSniffer\n"; |
|
31
|
|
|
} else { |
|
32
|
|
|
echo "No path registered in Code Sniffer\n"; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
static function make_copy() { |
|
|
|
|
|
|
37
|
|
|
$srcDir = __DIR__; |
|
38
|
|
|
$copy = __DIR__ .DIRECTORY_SEPARATOR.'PHPCompatibility'; |
|
39
|
|
|
|
|
40
|
|
|
if ( file_exists ($copy)) { |
|
41
|
|
|
echo "Copy hack is already in place\n"; |
|
42
|
|
|
return; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
mkdir($copy); |
|
46
|
|
|
copy(__DIR__ .DIRECTORY_SEPARATOR.'ruleset.xml', $copy.DIRECTORY_SEPARATOR.'ruleset.xml'); |
|
47
|
|
|
copy(__DIR__ .DIRECTORY_SEPARATOR.'Sniff.php', $copy.DIRECTORY_SEPARATOR.'Sniff.php'); |
|
48
|
|
|
|
|
49
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
50
|
|
|
$copy = str_replace('/', DIRECTORY_SEPARATOR, $copy); |
|
51
|
|
|
$srcDir = str_replace('/', DIRECTORY_SEPARATOR, $srcDir); |
|
52
|
|
|
passthru('xcopy "'.$srcDir .DIRECTORY_SEPARATOR.'Sniffs" "'.$copy.DIRECTORY_SEPARATOR.'Sniffs" /S /E /I'); |
|
53
|
|
|
} else { |
|
54
|
|
|
passthru('cp -r "'.$srcDir .DIRECTORY_SEPARATOR.'Sniffs" "'.$copy.DIRECTORY_SEPARATOR.'Sniffs"'); |
|
55
|
|
|
} |
|
56
|
|
|
echo "Created copy hack\n"; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
static function remove_copy() { |
|
|
|
|
|
|
60
|
|
|
$copy = __DIR__ .DIRECTORY_SEPARATOR.'PHPCompatibility'; |
|
61
|
|
|
|
|
62
|
|
|
if ( ! file_exists ($copy)) { |
|
63
|
|
|
echo "No copy hack to remove\n"; |
|
64
|
|
|
return; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
|
68
|
|
|
$copy = str_replace('/', DIRECTORY_SEPARATOR, $copy); |
|
69
|
|
|
passthru('rmdir /S /Q "'.$copy.'"'); |
|
70
|
|
|
} else { |
|
71
|
|
|
passthru('rm -rf "'.$copy.'"'); |
|
72
|
|
|
} |
|
73
|
|
|
echo "Copy hack removed\n"; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.