Skip to content
Newer
Older
100644 171 lines (140 sloc) 5.82 KB
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
1 <?php
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
2 error_reporting(1803);
3
b75499e add instructions/doc comment
cellog authored Sep 5, 2005
4 /**
0aca976 fix problems with phar creation
cellog authored May 29, 2007
5 * go-pear.phar creator. Requires PHP_Archive version 0.11.0 or newer
b75499e add instructions/doc comment
cellog authored Sep 5, 2005
6 *
7 * PHP version 5.1+
8 *
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
9 * To use, in pear-core create a directory
b75499e add instructions/doc comment
cellog authored Sep 5, 2005
10 * named go-pear-tarballs, and run these commands in the directory
11 *
12 * <pre>
a03ee94 Add required packages for the phar generators as svn externals and up…
dufuz authored Aug 2, 2009
13 * $ pear download -Z PEAR Archive_Tar Console_Getopt Structures_Graph XML_Util
b75499e add instructions/doc comment
cellog authored Sep 5, 2005
14 * </pre>
15 *
16 * finally, run this script using PHP 5.1's cli php
1ef51a4 use the bsd license
dufuz authored Feb 24, 2009
17
b75499e add instructions/doc comment
cellog authored Sep 5, 2005
18 *
19 * @category pear
20 * @package PEAR
21 * @author Greg Beaver <cellog@php.net>
66c2e34 properly update to new bsd license
dufuz authored Feb 24, 2009
22 * @copyright 2005-2009 The Authors
23 * @license http://opensource.org/licenses/bsd-license.php New BSD License
b75499e add instructions/doc comment
cellog authored Sep 5, 2005
24 * @version CVS: $Id$
25 */
26
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
27 $y = array();
28 foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
29 if ($path == '.') {
30 continue;
31 }
32
33 $y[] = $path;
34 }
35
36 // remove current dir, we will otherwise include git files, which is not good
37 set_include_path(implode(PATH_SEPARATOR, $y));
38 require_once 'PEAR/PackageFile.php';
39 require_once 'PEAR/Config.php';
40 require_once 'PHP/Archive/Creator.php';
41 $config = &PEAR_Config::singleton();
42
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
43 function replaceVersion($contents, $path)
44 {
45 return str_replace(array('@PEAR-VER@', '@package_version@'), $GLOBALS['pearver'], $contents);
46 }
47
48 $outputFile = 'go-pear.phar';
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
49
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
50 $tardir = __DIR__ . '/go-pear-tarballs';
51 $dp = @scandir($tardir);
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
52 if ($dp === false) {
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
53 die("while locating packages to install: scandir('" . $tardir. "') failed\n");
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
54 }
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
55
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
56 $required = array('Archive_Tar', 'Console_Getopt', 'PEAR', 'Structures_Graph', 'XML_Util');
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
57 $packages = array();
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
58 foreach ($dp as $entry) {
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
59 if ($entry{0} == '.' || !in_array(substr($entry, -4), array('.tar'))) {
60 continue;
61 }
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
62
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
63 $package = strstr($entry, '-', true);
64 $key = array_search($package, $required);
65 if ($key !== false) {
66 unset($required[$key]);
67 }
68
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
69 $packages[] = $entry;
70 }
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
71
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
72 if (!empty($required)) {
73 die('Following packages were not available in tar format in go-pear-tarballs: ' . implode(', ', $required). "\n");
74 }
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
75
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
76 if (!file_exists("$tardir/tmp")) {
77 mkdir("$tardir/tmp");
abd3abe fixes needed to make go-pear.phar work
cellog authored Oct 31, 2006
78 }
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
79
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
80 // Use the tar files for required Phar files
81 require_once 'Archive/Tar.php';
82 require_once 'System.php';
83
84 foreach ($packages as $package) {
85 $name = substr($package, 0, -4);
86 $tar = new Archive_Tar("$tardir/$package");
87 $tar->extractModify("$tardir/tmp", $name);
88 }
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
89
7a0f87c Quick cleanup - Requires PHP 5.3 to generate the phar archives now (n…
dufuz authored Jan 23, 2011
90 chdir(__DIR__);
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
91
567e684 Remove assignment of new by reference. Add newline to die message.
saltybeagle authored Sep 4, 2009
92 $pkg = new PEAR_PackageFile($config);
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
93 $pf = $pkg->fromPackageFile($tardir . '/tmp/package2.xml', PEAR_VALIDATE_NORMAL);
abd3abe fixes needed to make go-pear.phar work
cellog authored Oct 31, 2006
94 if (PEAR::isError($pf)) {
95 foreach ($pf->getUserInfo() as $warn) {
96 echo $warn['message'] . "\n";
97 }
7a0f87c Quick cleanup - Requires PHP 5.3 to generate the phar archives now (n…
dufuz authored Jan 23, 2011
98
abd3abe fixes needed to make go-pear.phar work
cellog authored Oct 31, 2006
99 die($pf->getMessage());
100 }
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
101 $pearver = $pf->getVersion();
102
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
103 $creator = new PHP_Archive_Creator('index.php', $outputFile); // no compression
0aca976 fix problems with phar creation
cellog authored May 29, 2007
104 $creator->useDefaultFrontController('PEAR.php');
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
105 $creator->useSHA1Signature();
106
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
107 foreach ($packages as $package) {
6a27ce8 more fixes to phar generation
cellog authored Aug 2, 2009
108 echo "adding PEAR/go-pear-tarballs/$package\n";
109 $creator->addFile("go-pear-tarballs/$package", "PEAR/go-pear-tarballs/$package");
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
110 }
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
111
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
112 $commandcontents = file_get_contents(__DIR__ . '/go-pear-phar.php');
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
113 $commandcontents = str_replace('require_once \'', 'require_once \'phar://' . $outputFile . '/', $commandcontents);
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
114 $creator->addString($commandcontents, 'index.php');
115
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
116 $commandcontents = file_get_contents($tardir . '/tmp/PEAR/Frontend.php');
0aca976 fix problems with phar creation
cellog authored May 29, 2007
117 $commandcontents = str_replace(
118 array(
119 "\$file = str_replace('_', '/', \$uiclass) . '.php';"
120 ),
121 array(
d850599 oops, need double quote instead of single quote
cellog authored Aug 2, 2009
122 "\$file = 'phar://" . $outputFile . "/' . str_replace('_', '/', \$uiclass) . '.php';"
0aca976 fix problems with phar creation
cellog authored May 29, 2007
123 ), $commandcontents);
124 $commandcontents = replaceVersion($commandcontents, '');
125 $creator->addString($commandcontents, 'PEAR/Frontend.php');
126
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
127 $commandcontents = file_get_contents($tardir . '/tmp/PEAR/PackageFile/v2.php');
0aca976 fix problems with phar creation
cellog authored May 29, 2007
128 $commandcontents = str_replace(
129 array(
130 '$fp = @fopen("PEAR/Task/$taskfile.php", \'r\', true);',
131 ),
132 array(
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
133 '$fp = @fopen("phar://' . $outputFile . '/PEAR/Task/$taskfile.php", \'r\', true);'
0aca976 fix problems with phar creation
cellog authored May 29, 2007
134 ), $commandcontents);
135 $commandcontents = replaceVersion($commandcontents, '');
136 $commandcontents = $creator->tokenMagicRequire($commandcontents, 'a.php');
137 $creator->addString($commandcontents, 'PEAR/PackageFile/v2.php');
687dbb9 tweak OS_Guess addition (include_once 'System.php' needs
cellog authored Aug 14, 2005
138
4c53005 streamline script immensely
cellog authored May 19, 2007
139 $creator->addMagicRequireCallback(array($creator, 'limitedSmartMagicRequire'));
140 $creator->addMagicRequireCallback('replaceVersion');
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
141 $creator->addFile($tardir . '/tmp/PEAR/Command.php', 'PEAR/Command.php');
22d833a add the .phar creation script for go-pear.phar
cellog authored Jul 20, 2005
142
4c53005 streamline script immensely
cellog authored May 19, 2007
143 $creator->clearMagicRequire();
144 $creator->addMagicRequireCallback(array($creator, 'tokenMagicRequire'));
145 $creator->addMagicRequireCallback('replaceVersion');
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
146
147 $creator->addDir($tardir . '/tmp/PEAR', array(), array('*PEAR/*'), false, $tardir . '/tmp');
148
149 $creator->addFile($tardir . '/tmp/PEAR.php', 'PEAR.php');
150 $creator->addFile($tardir . '/tmp/PEAR5.php', 'PEAR5.php');
151 $creator->addFile($tardir . '/tmp/System.php', 'System.php');
152 $creator->addFile($tardir . '/tmp/OS/Guess.php', 'OS/Guess.php');
7a0f87c Quick cleanup - Requires PHP 5.3 to generate the phar archives now (n…
dufuz authored Jan 23, 2011
153
154 // Other packages
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
155 $creator->addFile($tardir . '/tmp/PEAR/Exception.php', 'PEAR/Exception.php');
156 $creator->addFile($tardir . '/tmp/Archive/Tar.php', 'Archive/Tar.php');
157 $creator->addFile($tardir . '/tmp/Util.php', 'XML/Util.php');
158 $creator->addFile($tardir . '/tmp/Console/Getopt.php', 'Console/Getopt.php');
159 $creator->addFile($tardir . '/tmp/Structures/Graph.php', 'Structures/Graph.php');
160 $creator->addFile($tardir . '/tmp/Structures/Graph/Node.php', 'Structures/Graph/Node.php');
161 $creator->addFile($tardir . '/tmp/Structures/Graph/Manipulator/AcyclicTest.php', 'Structures/Graph/Manipulator/AcyclicTest.php');
162 $creator->addFile($tardir . '/tmp/Structures/Graph/Manipulator/TopologicalSorter.php', 'Structures/Graph/Manipulator/TopologicalSorter.php');
163
164 // Include Start scripts speficially since they are never in the releases
165 $creator->addFile(__DIR__ . '/PEAR/Start.php', 'PEAR/Start.php');
166 $creator->addFile(__DIR__ . '/PEAR/Start/CLI.php', 'PEAR/Start/CLI.php');
3d42a09 Sync the generation scripts as much as possible + various cosmetics
dufuz authored Jul 29, 2009
167
5c0b7e8 set SHA1 signature, will avoid future problems with phar.require_hash=1
cellog authored Jul 1, 2009
168 $creator->useSHA1Signature();
7a0f87c Quick cleanup - Requires PHP 5.3 to generate the phar archives now (n…
dufuz authored Jan 23, 2011
169 $creator->savePhar(__DIR__ . DIRECTORY_SEPARATOR . $outputFile);
08b66a2 @helgi - Move boilerplate include_path handling to top
helgi authored Dec 29, 2011
170
171 System::rm(array("-rf", "$tardir/tmp"));
Something went wrong with that request. Please try again.