|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* PEAR package builder |
|
4
|
|
|
* |
|
5
|
|
|
* Inspired by Twig's create_pear_package.php. |
|
6
|
|
|
* @link https://raw.github.com/fabpot/Twig/master/bin/create_pear_package.php |
|
7
|
|
|
* @author Twig Team |
|
8
|
|
|
* @license BSD license |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
if (!isset($argv[1]) || $argv[1] === '-h' || $argv[1] === '--help') { |
|
12
|
|
|
echo 'usage: php ' . $argv[0] . ' <version> <stability>' . PHP_EOL; |
|
13
|
|
|
echo PHP_EOL; |
|
14
|
|
|
echo ' version:' . PHP_EOL; |
|
15
|
|
|
echo ' Version of the package, in the form of major.minor.bug' . PHP_EOL; |
|
16
|
|
|
echo PHP_EOL; |
|
17
|
|
|
echo ' stability:' . PHP_EOL; |
|
18
|
|
|
echo ' One of alpha, beta, stable' . PHP_EOL; |
|
19
|
|
|
die(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
if (!isset($argv[2])) { |
|
23
|
|
|
die('You must provide the stability (alpha, beta, or stable)'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
$context = array( |
|
27
|
|
|
'date' => gmdate('Y-m-d'), |
|
28
|
|
|
'time' => gmdate('H:m:00'), |
|
29
|
|
|
'version' => $argv[1], |
|
30
|
|
|
'api_version' => $argv[1], |
|
31
|
|
|
'stability' => $argv[2], |
|
32
|
|
|
'api_stability' => $argv[2], |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
$context['files'] = ''; |
|
36
|
|
|
$path = realpath(dirname(__FILE__).'/../library/Requests'); |
|
37
|
|
|
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { |
|
|
|
|
|
|
38
|
|
|
if (preg_match('/\.php$/', $file)) { |
|
39
|
|
|
$name = str_replace($path . DIRECTORY_SEPARATOR, '', $file); |
|
40
|
|
|
$name = str_replace(DIRECTORY_SEPARATOR, '/', $name); |
|
41
|
|
|
$context['files'][] = "\t\t\t\t\t" . '<file install-as="Requests/' . $name . '" name="' . $name . '" role="php" />'; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$context['files'] = implode("\n", $context['files']); |
|
46
|
|
|
|
|
47
|
|
|
$template = file_get_contents(dirname(__FILE__).'/../package.xml.tpl'); |
|
48
|
|
|
$content = preg_replace_callback('/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/', 'replace_parameters', $template); |
|
49
|
|
|
file_put_contents(dirname(__FILE__).'/../package.xml', $content); |
|
50
|
|
|
|
|
51
|
|
|
function replace_parameters($matches) { |
|
52
|
|
|
global $context; |
|
53
|
|
|
|
|
54
|
|
|
return isset($context[$matches[1]]) ? $context[$matches[1]] : null; |
|
55
|
|
|
} |
|
56
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.