Skip to content

Commit 5da35ec

Browse files
committed
PHAR stub changes:
Changed the SAPI detection; Added a PHAR extension warning.
1 parent 5957150 commit 5da35ec

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

stub.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
'@PACKAGE_NAME@-@PACKAGE_VERSION@' . DIRECTORY_SEPARATOR . 'src'
66
. DIRECTORY_SEPARATOR . 'PEAR2' . DIRECTORY_SEPARATOR . 'Autoload.php';
77
} else {
8-
$isNotCli = PHP_SAPI !== 'cli';
9-
if ($isNotCli) {
8+
$isHttp = isset($_SERVER['REQUEST_URI']);
9+
if ($isHttp) {
1010
header('Content-Type: text/plain;charset=UTF-8');
1111
}
1212
echo "PEAR2_Cache_SHM @PACKAGE_VERSION@\n";
@@ -17,30 +17,32 @@
1717
}
1818

1919
$available_extensions = array();
20-
foreach (array('phar', 'apc', 'wincache') as $ext) {
20+
foreach (array('apc', 'wincache') as $ext) {
2121
if (extension_loaded($ext)) {
2222
$available_extensions[] = $ext;
2323
}
2424
}
2525

26-
if (in_array('phar', $available_extensions)) {
26+
if (extension_loaded('phar')) {
2727
$phar = new Phar(__FILE__);
2828
$sig = $phar->getSignature();
2929
echo "{$sig['hash_type']} hash: {$sig['hash']}\n\n";
30-
31-
unset($available_extensions[
32-
array_search('phar', $available_extensions)
33-
]);
30+
} else {
31+
echo <<<HEREDOC
32+
If you wish to use this package from this archive, you need to install and
33+
enable the PHAR extension. Otherwise, you must extract this archive, and include
34+
the autoloader instead.
35+
HEREDOC;
3436
}
3537

3638
if (in_array('apc', $available_extensions)) {
3739
if (version_compare(phpversion('apc'), '3.0.13', '>=')) {
3840
echo "A compatible APC version is available on this server.\n";
39-
if ($isNotCli || 1 == ini_get('apc.enable_cli')) {
41+
if ($isHttp || 1 == ini_get('apc.enable_cli')) {
4042
echo "You should be able to use it under this SAPI (", PHP_SAPI,
4143
").\n";
4244
} else {
43-
echo "You can't use it under this SAPI (cli).\n";
45+
echo "You can't use it under this SAPI (", PHP_SAPI, ").\n";
4446
}
4547
echo "\n";
4648
}
@@ -49,24 +51,25 @@
4951
if (in_array('wincache', $available_extensions)) {
5052
if (version_compare(phpversion('wincache'), '1.1.0', '>=')) {
5153
echo "A compatible WinCache version is available on this server.\n";
52-
if ($isNotCli) {
54+
if ($isHttp) {
5355
echo "You should be able to use it under this SAPI (", PHP_SAPI,
5456
").\n";
5557
} else {
56-
echo "You can't use it under this SAPI (cli).\n";
58+
echo "You can't use it under this SAPI (", PHP_SAPI, ").\n";
5759
}
5860
echo "\n";
5961
}
6062
}
6163

62-
if ($isNotCli) {
64+
if ($isHttp) {
6365
if (empty($available_extensions)) {
6466
echo "You don't have any compatible extensions for this SAPI (",
6567
PHP_SAPI,
6668
").\nInstall one of APC (>= 3.0.13) or WinCache (>= 1.1.0).";
6769
}
6870
} else {
69-
echo "You can use the Placebo adapter under this SAPI (cli).\n";
71+
echo "You should be able to use the Placebo adapter under this SAPI (",
72+
PHP_SAPI, ").\n";
7073
}
7174
}
7275

0 commit comments

Comments
 (0)