1<?php
2$peardir = '/home/cellog/workspace/pear-core';
3
4require_once 'PEAR/PackageFile.php';
5require_once 'PEAR/Config.php';
6require_once 'PHP/Archive/Creator.php';
7$config = &PEAR_Config::singleton();
8$pkg = &new PEAR_PackageFile($config);
9$pf = $pkg->fromPackageFile($peardir . DIRECTORY_SEPARATOR . 'package2.xml', PEAR_VALIDATE_NORMAL);
10$pearver = $pf->getVersion();
11
12$creator = new PHP_Archive_Creator('index.php', 'PEAR.phar', false);
13$commandcontents = file_get_contents(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'pearindex.php');
14$commandcontents = str_replace('@PEARVER@', $pearver, $commandcontents);
15$creator->addString($commandcontents, 'index.php');
16
17function replaceVersion($contents, $path)
18{
19    return str_replace(array('@PEAR-VER@', '@package_version@'), $GLOBALS['pearver'], $contents);
20}
21$commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . '/PEAR/Frontend.php');
22$commandcontents = str_replace(
23    array(
24        "\$file = str_replace('_', '/', \$uiclass) . '.php';"
25    ),
26    array(
27        "\$file = 'phar://PEAR.phar/' . str_replace('_', '/', \$uiclass) . '.php';"
28    ), $commandcontents);
29$commandcontents = replaceVersion($commandcontents, '');
30$creator->addString($commandcontents, 'PEAR/Frontend.php');
31
32$commandcontents = file_get_contents($peardir . DIRECTORY_SEPARATOR . '/PEAR/PackageFile/v2.php');
33$commandcontents = str_replace(
34    array(
35        '$fp = @fopen("PEAR/Task/$taskfile.php", \'r\', true);',
36    ),
37    array(
38        '$fp = @fopen("phar://PEAR.phar/PEAR/Task/$taskfile.php", \'r\', true);'
39    ), $commandcontents);
40$commandcontents = replaceVersion($commandcontents, '');
41$commandcontents = $creator->tokenMagicRequire($commandcontents, 'a.php');
42$creator->addString($commandcontents, 'PEAR/PackageFile/v2.php');
43
44$creator->addMagicRequireCallback(array($creator, 'limitedSmartMagicRequire'));
45$creator->addMagicRequireCallback('replaceVersion');
46$creator->addFile($peardir . '/PEAR/Command.php', 'PEAR/Command.php');
47
48$creator->clearMagicRequire();
49$creator->addMagicRequireCallback(array($creator, 'tokenMagicRequire'));
50$creator->addMagicRequireCallback('replaceVersion');
51$creator->addDir($peardir . DIRECTORY_SEPARATOR . 'PEAR', array(),
52    array(
53        '*PEAR/Dependency2.php',
54        '*PEAR/PackageFile/Generator/v1.php',
55        '*PEAR/PackageFile/Generator/v2.php',
56        '*PEAR/PackageFile/v2/Validator.php',
57        '*PEAR/Downloader/Package.php',
58        '*PEAR/Installer/Role.php',
59        '*PEAR/ChannelFile/Parser.php',
60        '*PEAR/Command/Install.xml',
61        '*PEAR/Command/Install.php',
62        '*PEAR/Command/Registry.xml',
63        '*PEAR/Command/Registry.php',
64        '*PEAR/Downloader/Package.php',
65        '*PEAR/Frontend/CLI.php',
66        '*PEAR/Installer/Role/Common.php',
67        '*PEAR/Installer/Role/Data.php',
68        '*PEAR/Installer/Role/Doc.php',
69        '*PEAR/Installer/Role/Php.php',
70        '*PEAR/Installer/Role/Script.php',
71        '*PEAR/Installer/Role/Test.php',
72        '*PEAR/Installer/Role/Data.xml',
73        '*PEAR/Installer/Role/Doc.xml',
74        '*PEAR/Installer/Role/Php.xml',
75        '*PEAR/Installer/Role/Script.xml',
76        '*PEAR/Installer/Role/Test.xml',
77        '*PEAR/PackageFile.php',
78        '*PEAR/PackageFile/v1.php',
79        '*PEAR/PackageFile/Parser/v1.php',
80        '*PEAR/PackageFile/Parser/v2.php',
81        '*PEAR/PackageFile/Generator/v1.php',
82        '*PEAR/REST.php',
83        '*PEAR/REST/10.php',
84        '*PEAR/Task/Common.php',
85        '*PEAR/Task/Postinstallscript.php',
86        '*PEAR/Task/Postinstallscript/rw.php',
87        '*PEAR/Task/Replace.php',
88        '*PEAR/Task/Replace/rw.php',
89        '*PEAR/Task/Windowseol.php',
90        '*PEAR/Task/Windowseol/rw.php',
91        '*PEAR/Task/Unixeol.php',
92        '*PEAR/Task/Unixeol/rw.php',
93        '*PEAR/Validator/PECL.php',
94        '*PEAR/ChannelFile.php',
95        '*PEAR/Command/Common.php',
96        '*PEAR/Common.php',
97        '*PEAR/Config.php',
98        '*PEAR/Dependency2.php',
99        '*PEAR/DependencyDB.php',
100        '*PEAR/Downloader.php',
101        '*PEAR/ErrorStack.php',
102        '*PEAR/Installer.php',
103        '*PEAR/Registry.php',
104        '*PEAR/Remote.php',
105        '*PEAR/Start.php',
106        '*PEAR/Start/CLI.php',
107        '*PEAR/Validate.php',
108        '*PEAR/XMLParser.php',
109    ), false, $peardir);
110$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'PEAR.php', 'PEAR.php');
111$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Archive/Tar.php', 'Archive/Tar.php');
112$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Console/Getopt.php', 'Console/Getopt.php');
113$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'System.php', 'System.php');
114$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'OS/Guess.php', 'OS/Guess.php');
115$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph.php', 'Structures/Graph.php');
116$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Node.php', 'Structures/Graph/Node.php');
117$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Manipulator/AcyclicTest.php', 'Structures/Graph/Manipulator/AcyclicTest.php');
118$creator->addFile($peardir . DIRECTORY_SEPARATOR . 'Structures_Graph/Structures/Graph/Manipulator/TopologicalSorter.php', 'Structures/Graph/Manipulator/TopologicalSorter.php');
119$creator->savePhar(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PEAR.phar');
120?>
121