Skip to content

Commit 5b4aad0

Browse files
committed
Use PHP to fetch the pear phar
1 parent 8664b5d commit 5b4aad0

File tree

2 files changed

+65
-11
lines changed

2 files changed

+65
-11
lines changed

pear/Makefile.frag

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ peardir=$(PEAR_INSTALLDIR)
44

55
# Skip all php.ini files altogether
66
PEAR_INSTALL_FLAGS = -n -dshort_open_tag=0 -dsafe_mode=0 -dopen_basedir= -derror_reporting=E_ALL -dmemory_limit=-1 -ddetect_unicode=0
7-
WGET = `which wget 2>/dev/null`
8-
FETCH = `which fetch 2>/dev/null`
97

108
install-pear-installer: $(SAPI_CLI_PATH)
119
@$(top_builddir)/sapi/cli/php $(PEAR_INSTALL_FLAGS) $(builddir)/install-pear-nozlib.phar -d "$(peardir)" -b "$(bindir)"
@@ -16,15 +14,7 @@ install-pear:
1614
if test -f $(srcdir)/install-pear-nozlib.phar; then \
1715
cp $(srcdir)/install-pear-nozlib.phar $(builddir)/install-pear-nozlib.phar; \
1816
else \
19-
if test ! -z "$(WGET)" && test -x "$(WGET)"; then \
20-
"$(WGET)" http://pear.php.net/install-pear-nozlib.phar -nd -P $(builddir)/; \
21-
elif test ! -z "$(FETCH)" && test -x "$(FETCH)"; then \
22-
"$(FETCH)" -o $(builddir)/ http://pear.php.net/install-pear-nozlib.phar; \
23-
else \
24-
echo ""; \
25-
echo "No download utilities found. Don't know how to download PEAR archive."; \
26-
echo ""; \
27-
fi \
17+
$(top_builddir)/sapi/cli/php -n $(srcdir)/fetch.php http://pear.php.net/install-pear-nozlib.phar $(builddir)/install-pear-nozlib.phar; \
2818
fi \
2919
fi
3020
@if test -f $(builddir)/install-pear-nozlib.phar && $(mkinstalldirs) $(INSTALL_ROOT)$(peardir); then \

pear/fetch.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
function usage($argv) {
3+
echo "Usage:\n";
4+
printf("\tphp %s <http://example.com/file> <localfile>\n", $argv[0]);
5+
exit(1);
6+
}
7+
8+
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
9+
static $filesize = null;
10+
11+
switch($notification_code) {
12+
case STREAM_NOTIFY_RESOLVE:
13+
case STREAM_NOTIFY_AUTH_REQUIRED:
14+
case STREAM_NOTIFY_COMPLETED:
15+
case STREAM_NOTIFY_FAILURE:
16+
case STREAM_NOTIFY_AUTH_RESULT:
17+
/* Ignore */
18+
break;
19+
20+
case STREAM_NOTIFY_REDIRECTED:
21+
echo "Being redirected to: ", $message, "\n";
22+
break;
23+
24+
case STREAM_NOTIFY_CONNECT:
25+
echo "Conntected...\n";
26+
break;
27+
28+
case STREAM_NOTIFY_FILE_SIZE_IS:
29+
$filesize = $bytes_max;
30+
echo "Filesize: ", $filesize, "\n";
31+
break;
32+
33+
case STREAM_NOTIFY_MIME_TYPE_IS:
34+
echo "Mime-type: ", $message, "\n";
35+
break;
36+
37+
case STREAM_NOTIFY_PROGRESS:
38+
if ($bytes_transferred > 0) {
39+
if (!isset($filesize)) {
40+
printf("\rUnknown filesize.. %2d kb done..", $bytes_transferred/1024);
41+
} else {
42+
$length = (int)(($bytes_transferred/$filesize)*100);
43+
printf("\r[%-100s] %d%% (%2d/%2d kb)", str_repeat("=", $length). ">", $length, ($bytes_transferred/1024), $filesize/1024);
44+
}
45+
}
46+
break;
47+
}
48+
}
49+
50+
isset($argv[1], $argv[2]) or usage($argv);
51+
52+
$ctx = stream_context_create(null, array("notification" => "stream_notification_callback"));
53+
54+
$fp = fopen($argv[1], "r", false, $ctx);
55+
if (is_resource($fp) && file_put_contents($argv[2], $fp)) {
56+
echo "\nDone!\n";
57+
exit(0);
58+
}
59+
60+
$err = error_get_last();
61+
echo "\nErrrrrorr..\n", $err["message"], "\n";
62+
exit(1);
63+
64+

0 commit comments

Comments
 (0)