|
1 | 1 | <?php |
| 2 | + |
| 3 | +/** |
| 4 | + * packagexmlsetup.php for PEAR2_Cache_SHM. |
| 5 | + * |
| 6 | + * PHP version 5.3 |
| 7 | + * |
| 8 | + * @category Caching |
| 9 | + * @package PEAR2_Cache_SHM |
| 10 | + * @author Vasil Rangelov <[email protected]> |
| 11 | + * @copyright 2011 Vasil Rangelov |
| 12 | + * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 |
| 13 | + * @version GIT: $Id$ |
| 14 | + * @link http://pear2.php.net/PEAR2_Cache_SHM |
| 15 | + */ |
| 16 | + |
| 17 | +/** |
| 18 | + * References the package in $package and/or $compatible. |
| 19 | + */ |
2 | 20 | use Pyrus\Developer\PackageFile\v2; |
3 | 21 |
|
| 22 | +/** |
| 23 | + * Configuration array. |
| 24 | + * |
| 25 | + * Each key is the task. |
| 26 | + * |
| 27 | + * The task "replace" uses an array where the key is the value to be searched |
| 28 | + * for, and the value is an array of additional attributes for the task, which |
| 29 | + * normally contain at least "type" (pear-config/package-info) and "to", which |
| 30 | + * specifies the value to replace it with. |
| 31 | + * |
| 32 | + * The task "eol" uses an array where the key is a filename pattern to be |
| 33 | + * matched, and the value is the target platform's EOL to be used for those |
| 34 | + * file names (windows/unix). |
| 35 | + * |
| 36 | + * Unrecognized tasks are ignored. |
| 37 | + * |
| 38 | + * @var array |
| 39 | + */ |
| 40 | +$config = array( |
| 41 | + 'replace' => array( |
| 42 | + '../src' => array( |
| 43 | + 'type' => 'pear-config', |
| 44 | + 'to' => 'php_dir' |
| 45 | + ), |
| 46 | + 'GIT: $Id$' => array( |
| 47 | + 'type' => 'package-info', |
| 48 | + 'to' => 'version' |
| 49 | + ) |
| 50 | + ), |
| 51 | + 'eol' => array( |
| 52 | + '*.bat' => 'windows' |
| 53 | + ) |
| 54 | +); |
| 55 | + |
| 56 | +if (!isset($package)) { |
| 57 | + die('This file must be executed via "pyrus.phar make".'); |
| 58 | +} |
| 59 | + |
4 | 60 | $packageGen = function ( |
| 61 | + array $config, |
5 | 62 | v2 $package, |
6 | 63 | v2 $compatible = null |
7 | 64 | ) { |
8 | | - $srcDirTask = array( |
9 | | - 'tasks:replace' => array( |
10 | | - array( |
11 | | - 'attribs' => array( |
12 | | - 'from' => '../src', |
13 | | - 'to' => 'php_dir', |
14 | | - 'type' => 'pear-config' |
15 | | - ) |
16 | | - ) |
17 | | - ) |
18 | | - ); |
19 | | - |
20 | | - $srcFileTasks = array( |
21 | | - 'tasks:replace' => array( |
22 | | - array( |
23 | | - 'attribs' => array( |
24 | | - 'from' => '~~summary~~', |
25 | | - 'to' => 'summary', |
26 | | - 'type' => 'package-info' |
27 | | - ) |
28 | | - ), |
29 | | - array( |
30 | | - 'attribs' => array( |
31 | | - 'from' => '~~description~~', |
32 | | - 'to' => 'description', |
33 | | - 'type' => 'package-info' |
34 | | - ) |
35 | | - ), |
36 | | - array( |
37 | | - 'attribs' => array( |
38 | | - 'from' => 'GIT: $Id$', |
39 | | - 'to' => 'version', |
40 | | - 'type' => 'package-info' |
41 | | - ) |
42 | | - ) |
43 | | - ) |
44 | | - ); |
45 | 65 |
|
46 | | - $package->files['tests/bootstrap.php'] = array_merge_recursive( |
47 | | - $package->files['tests/bootstrap.php']->getArrayCopy(), |
48 | | - $srcDirTask |
49 | | - ); |
| 66 | + $tasksNs = $package->getTasksNs(); |
| 67 | + $cTasksNs = $compatible ? $compatible->getTasksNs() : ''; |
50 | 68 |
|
51 | | - $package->files['docs/phpdoc.dist.xml'] = array_merge_recursive( |
52 | | - $package->files['docs/phpdoc.dist.xml']->getArrayCopy(), |
53 | | - $srcDirTask |
54 | | - ); |
55 | | - $package->files['docs/apigen.neon'] = array_merge_recursive( |
56 | | - $package->files['docs/apigen.neon']->getArrayCopy(), |
57 | | - $srcDirTask |
58 | | - ); |
| 69 | + $oldCwd = getcwd(); |
| 70 | + chdir(__DIR__); |
| 71 | + foreach (new RecursiveIteratorIterator( |
| 72 | + new RecursiveDirectoryIterator( |
| 73 | + '.', |
| 74 | + RecursiveDirectoryIterator::UNIX_PATHS |
| 75 | + | RecursiveDirectoryIterator::SKIP_DOTS |
| 76 | + ), |
| 77 | + RecursiveIteratorIterator::LEAVES_ONLY |
| 78 | + ) as $path) { |
| 79 | + $filename = substr($path->getPathname(), 2); |
| 80 | + $cFilename = str_replace('src/', 'php/', $filename); |
59 | 81 |
|
60 | | - $package->files['docs/doxygen.ini'] = array_merge_recursive( |
61 | | - $package->files['docs/doxygen.ini']->getArrayCopy(), |
62 | | - $srcDirTask, |
63 | | - array( |
64 | | - 'tasks:replace' => array( |
65 | | - array( |
66 | | - 'attribs' => array( |
67 | | - 'from' => 'GIT: $Id$', |
68 | | - 'to' => 'version', |
69 | | - 'type' => 'package-info' |
| 82 | + if (isset($package->files[$filename])) { |
| 83 | + $parsedFilename = pathinfo($filename); |
| 84 | + $as = (strpos($filename, 'examples/') === 0) |
| 85 | + ? $filename |
| 86 | + : substr($filename, strpos($filename, '/') + 1); |
| 87 | + if (strpos($filename, 'scripts/') === 0) { |
| 88 | + if (isset($parsedFilename['extension']) |
| 89 | + && 'php' === $parsedFilename['extension'] |
| 90 | + && !is_file( |
| 91 | + $parsedFilename['dirname'] . '/' . |
| 92 | + $parsedFilename['filename'] |
70 | 93 | ) |
71 | | - ) |
72 | | - ) |
73 | | - ) |
74 | | - ); |
75 | | - $hasCompatible = null !== $compatible; |
76 | | - if ($hasCompatible) { |
77 | | - $compatible->license = $package->license; |
78 | | - $compatible->files[ |
79 | | - "test/{$package->channel}/{$package->name}/bootstrap.php" |
80 | | - ] = array_merge_recursive( |
81 | | - $compatible->files[ |
82 | | - "test/{$package->channel}/{$package->name}/bootstrap.php" |
83 | | - ]->getArrayCopy(), |
84 | | - $srcDirTask |
85 | | - ); |
86 | | - |
87 | | - $compatible->files[ |
88 | | - "doc/{$package->channel}/{$package->name}/phpdoc.dist.xml" |
89 | | - ] = array_merge_recursive( |
90 | | - $compatible->files[ |
91 | | - "doc/{$package->channel}/{$package->name}/phpdoc.dist.xml" |
92 | | - ]->getArrayCopy(), |
93 | | - $srcDirTask |
94 | | - ); |
| 94 | + && is_file( |
| 95 | + $parsedFilename['dirname'] . '/' . |
| 96 | + $parsedFilename['filename'] . '.bat' |
| 97 | + ) |
| 98 | + ) { |
| 99 | + $as = substr($as, 0, -4); |
| 100 | + } |
| 101 | + } |
| 102 | + $package->getReleaseToInstall('php')->installAs($filename, $as); |
95 | 103 |
|
96 | | - $compatible->files["doc/{$package->channel}/{$package->name}/doxygen.ini"] |
97 | | - = array_merge_recursive( |
98 | | - $compatible->files[ |
99 | | - "doc/{$package->channel}/{$package->name}/doxygen.ini" |
100 | | - ]->getArrayCopy(), |
101 | | - $srcDirTask, |
102 | | - array( |
103 | | - 'tasks:replace' => array( |
| 104 | + $contents = file_get_contents($filename); |
| 105 | + foreach ($config['replace'] as $from => $attribs) { |
| 106 | + if (strpos($contents, $from) !== false) { |
| 107 | + $attribs['from'] = $from; |
| 108 | + $package->files[$filename] = array_merge_recursive( |
| 109 | + $package->files[$filename]->getArrayCopy(), |
104 | 110 | array( |
105 | | - 'attribs' => array( |
106 | | - 'from' => 'GIT: $Id$', |
107 | | - 'to' => 'version', |
108 | | - 'type' => 'package-info' |
| 111 | + "{$tasksNs}:replace" => array( |
| 112 | + array( |
| 113 | + 'attribs' => $attribs |
| 114 | + ) |
109 | 115 | ) |
110 | 116 | ) |
111 | | - ) |
112 | | - ) |
113 | | - ); |
114 | | - } |
| 117 | + ); |
115 | 118 |
|
116 | | - $oldCwd = getcwd(); |
117 | | - chdir(__DIR__); |
118 | | - foreach ( |
119 | | - new RecursiveIteratorIterator( |
120 | | - new RecursiveDirectoryIterator( |
121 | | - 'src', |
122 | | - RecursiveDirectoryIterator::UNIX_PATHS |
123 | | - | RecursiveDirectoryIterator::SKIP_DOTS |
124 | | - ), |
125 | | - RecursiveIteratorIterator::LEAVES_ONLY |
126 | | - ) as $path) { |
127 | | - $filename = $path->getPathname(); |
128 | | - |
129 | | - $package->files[$filename] = array_merge_recursive( |
130 | | - $package->files[$filename]->getArrayCopy(), |
131 | | - $srcFileTasks |
132 | | - ); |
133 | | - |
134 | | - if ($hasCompatible) { |
135 | | - $compatibleFilename = str_replace('src/', 'php/', $filename); |
136 | | - $compatible->files[$compatibleFilename] = array_merge_recursive( |
137 | | - $compatible->files[$compatibleFilename]->getArrayCopy(), |
138 | | - $srcFileTasks |
139 | | - ); |
140 | | - } |
141 | | - } |
| 119 | + if ($compatible) { |
| 120 | + $compatible->files[$cFilename] = array_merge_recursive( |
| 121 | + $compatible->files[$cFilename]->getArrayCopy(), |
| 122 | + array( |
| 123 | + "{$cTasksNs}:replace" => array( |
| 124 | + array( |
| 125 | + 'attribs' => $attribs |
| 126 | + ) |
| 127 | + ) |
| 128 | + ) |
| 129 | + ); |
| 130 | + } |
| 131 | + } |
| 132 | + } |
142 | 133 |
|
143 | | - foreach ( |
144 | | - new RecursiveIteratorIterator( |
145 | | - new RecursiveDirectoryIterator( |
146 | | - '.', |
147 | | - RecursiveDirectoryIterator::UNIX_PATHS |
148 | | - | RecursiveDirectoryIterator::SKIP_DOTS |
149 | | - ), |
150 | | - RecursiveIteratorIterator::LEAVES_ONLY |
151 | | - ) as $path) { |
152 | | - $filename = substr($path->getPathname(), 2); |
| 134 | + foreach ($config['eol'] as $pattern => $platform) { |
| 135 | + if (fnmatch($pattern, $filename)) { |
| 136 | + $package->files[$filename] = array_merge_recursive( |
| 137 | + $package->files[$filename]->getArrayCopy(), |
| 138 | + array( |
| 139 | + "{$tasksNs}:{$platform}eol" => array() |
| 140 | + ) |
| 141 | + ); |
153 | 142 |
|
154 | | - if (isset($package->files[$filename])) { |
155 | | - $as = (strpos($filename, 'examples') === 0) |
156 | | - ? $filename |
157 | | - : substr($filename, strpos($filename, '/') + 1); |
158 | | - $package->getReleaseToInstall('php')->installAs($filename, $as); |
| 143 | + if ($compatible) { |
| 144 | + $compatible->files[$cFilename] = array_merge_recursive( |
| 145 | + $compatible->files[$cFilename]->getArrayCopy(), |
| 146 | + array( |
| 147 | + "{$cTasksNs}:{$platform}eol" => array() |
| 148 | + ) |
| 149 | + ); |
| 150 | + } |
| 151 | + } |
| 152 | + } |
159 | 153 | } |
160 | 154 | } |
161 | 155 | chdir($oldCwd); |
162 | 156 | return array($package, $compatible); |
163 | 157 | }; |
164 | 158 |
|
165 | 159 | list($package, $compatible) = $packageGen( |
| 160 | + $config, |
166 | 161 | $package, |
167 | 162 | isset($compatible) ? $compatible : null |
168 | 163 | ); |
|
0 commit comments