PageRenderTime 6ms CodeModel.GetById 3ms app.highlight 12ms RepoModel.GetById 0ms app.codeStats 1ms

/php-pear-PHP-CompatInfo-1.9.0/PHP_CompatInfo-1.9.0/scripts/configure.php

#
PHP | 564 lines | 305 code | 73 blank | 186 comment | 43 complexity | 0a0b44b17894b65a27bd39bb68dccf22 MD5 | raw file
  1#!@php_bin@
  2<?php
  3/**
  4 * The Predefined Classes/Constants array script generator.
  5 *
  6 * PHP version 5
  7 *
  8 * @category PHP
  9 * @package  PHP_CompatInfo
 10 * @author   Laurent Laville <pear@laurent-laville.org>
 11 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
 12 * @version  CVS: $Id: configure.php,v 1.8 2008/12/26 18:50:51 farell Exp $
 13 * @link     http://pear.php.net/package/PHP_CompatInfo
 14 * @since    File available since Release 1.9.0b1
 15 */
 16
 17if (version_compare(PHP_VERSION, '5.0.0') < 0) {
 18    print basename(__FILE__) . " require PHP5 or better to run. "
 19        . "Your current PHP version is " . PHP_VERSION
 20        . PHP_EOL;
 21    exit(1);
 22}
 23
 24require_once 'Console/Getargs.php';
 25
 26$ds = DIRECTORY_SEPARATOR;
 27
 28$opts = array('enable' =>
 29                  array('short'   => 'e',
 30                        'desc'    => 'A comma separated list of extensions '
 31                                   . 'you want only',
 32                        'default' => '',
 33                        'min'     => 0 , 'max' => 1),
 34              'disable' =>
 35                  array('short'   => 'd',
 36                        'desc'    => 'A comma separated list of extensions '
 37                                   . 'you want to disable',
 38                        'default' => '',
 39                        'min'     => 0 , 'max' => 1),
 40              'sapi' =>
 41                  array('short'   => 's',
 42                        'desc'    => 'A comma separated list of SAPI '
 43                                   . 'you want only',
 44                        'default' => 'apache2handler,cgi,cli',
 45                        'min'     => 0 , 'max' => 1),
 46              'exceptions' =>
 47                  array('short'   => 'x',
 48                        'desc'    => 'File that provides exceptions results',
 49                        'default' => 'exceptions.conf.php',
 50                        'min'     => 0 , 'max' => 1),
 51              'output' =>
 52                  array('short'   => 'o',
 53                        'desc'    => 'Target directory where to write results',
 54                        'default' => '@'.'php_dir@/PHP/CompatInfo',
 55                        'min'     => 0 , 'max' => 1),
 56              'verbose' =>
 57                  array('short'   => 'v',
 58                        'desc'    => 'Set the verbose level',
 59                        'default' => 1,
 60                        'min'     => 0 , 'max' => 1),
 61              'version' =>
 62                  array('short' => 'V',
 63                        'desc'  => 'Print version information',
 64                        'max'   => 0),
 65              'help' =>
 66                  array('short' => 'h',
 67                        'desc'  => 'Show this help',
 68                        'max'   => 0)
 69              );
 70
 71$args = Console_Getargs::factory($opts);
 72
 73if (PEAR::isError($args)) {
 74    $header = "PHP_CompatInfo Extensions Support List build system \n".
 75              'Usage: '.basename($_SERVER['SCRIPT_NAME'])." [options]\n\n";
 76    if ($args->getCode() === CONSOLE_GETARGS_ERROR_USER) {
 77        echo Console_Getargs::getHelp($opts, $header, $args->getMessage())."\n";
 78    } else if ($args->getCode() === CONSOLE_GETARGS_HELP) {
 79        echo Console_Getargs::getHelp($opts, $header)."\n";
 80    }
 81    exit(1);
 82}
 83
 84// version
 85if ($args->isDefined('V')) {
 86    echo 'PHP_CompatInfo Extensions Support List build system version @package_version@';
 87    exit(0);
 88}
 89
 90// verbose
 91if ($args->isDefined('v')) {
 92    $verbose = $args->getValue('v');
 93} else {
 94    $verbose = 1;
 95}
 96
 97// output
 98if ($args->isDefined('o')) {
 99    $o = $args->getValue('o');
100    if (strpos($o, '@'.'php_dir@')) {
101        $o = str_replace('@'.'php_dir@', '@php_dir@', $o);
102    }
103    if (is_dir($o) && (is_writable($o))) {
104        /* Directory where to write
105           all "*_const_array.php" and "*_class_array.php" files
106           Must ended with a trailing directory separator */
107        if (substr($o, -1, 1) !== $ds) {
108            $o .= $ds;
109        }
110        $target_directory = $o;
111    } else {
112        echo 'Invalid (or not writable) target directory';
113        exit(1);
114    }
115} else {
116    $target_directory = '@php_dir@' . $ds . 'PHP' .$ds . 'CompatInfo' . $ds;
117}
118
119// enable
120if ($args->isDefined('e')) {
121    $extensions = explode(',', $args->getValue('e'));
122} else {
123    $extensions = get_loaded_extensions();
124}
125
126// disable
127if ($args->isDefined('d')) {
128    $d          = explode(',', $args->getValue('d'));
129    $extensions = array_diff($extensions, $d);
130}
131
132// sapi
133if ($args->isDefined('s')) {
134    $sapis = explode(',', $args->getValue('s'));
135} else {
136    $sapis = array('apache2handler', 'cgi', 'cli');
137}
138
139// exceptions
140if ($args->isDefined('x')) {
141    $x = $args->getValue('x');
142    if (file_exists($x)) {
143        include_once $x;
144        if (!function_exists('getExceptions')) {
145            echo 'getExceptions() function does not exists';
146            exit(1);
147        }
148    } else {
149        echo 'Exceptions file does not exists';
150        exit(1);
151    }
152} else {
153    include_once dirname(__FILE__) . $ds . 'scripts' . $ds . 'exceptions.conf.php';
154}
155
156$const_glob_list = array();
157$class_glob_list = array();
158$func_glob_list  = array();
159
160// PHP Core constants
161$extName           = 'internal';
162$extConstants      = get_defined_constants(true);
163$const_glob_list[] = $extName;
164
165// default version to apply to each internal constant
166$ver = getExceptions($extName, 'version');
167if ($ver === false) {
168    $ver = '4.0.0';
169}
170
171$constants = array();
172foreach ($extConstants[$extName] as $cst => $val) {
173    $constants[$cst]['init'] = $ver;
174    $constants[$cst]['name'] = $cst;
175}
176
177$exceptions = getExceptions($extName, 'constant');
178if ($exceptions === false) {
179    // no constant exceptions for this extension
180} else {
181    // apply exceptions to give final constant results
182    $constants = array_merge($constants, $exceptions);
183}
184ksort($constants);
185
186file_put_contents($target_directory . $extName . '_const_array.php',
187                  "<?php
188/**
189 * Internal Constant dictionary for PHP_CompatInfo 1.9.0a1 or better
190 *
191 * PHP versions 4 and 5
192 *
193 * @category PHP
194 * @package  PHP_CompatInfo
195 * @author   Davey Shafik <davey@php.net>
196 * @author   Laurent Laville <pear@laurent-laville.org>
197 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
198 * @version  CVS: \$Id: configure.php,v 1.8 2008/12/26 18:50:51 farell Exp $
199 * @link     http://pear.php.net/package/PHP_CompatInfo
200 * @since    version 1.9.0b2 (2008-12-19)
201 */
202
203\$GLOBALS['_PHP_COMPATINFO_CONST_" . strtoupper($extName) . "'] = " .
204        var_export($constants, true) . ";
205?>");
206
207foreach ($extensions as $extension) {
208
209    if (!extension_loaded($extension)) {
210        continue;  // skip this extension if not loaded : prevent error
211    }
212
213    $ext = new ReflectionExtension($extension);
214
215    // name of the current Extension
216    $extName = $ext->getName();
217
218    // version of the current Extension
219    $extVers = $ext->getVersion();
220
221    if ($verbose > 0) {
222        print 'Found '. $extName;
223        if ($extVers) {
224            print ' version '. $extVers;
225        }
226        print PHP_EOL;
227    }
228
229    // default version to apply to each constant and class predefined
230    $ver = getExceptions($extName, 'version');
231    if ($ver === false) {
232        $ver = '4.0.0';
233    }
234
235    // constants described by the Extension interface
236    $extConstants = $ext->getConstants();
237    if (count($extConstants) > 0) {
238        $const_glob_list[] = $extName;
239
240        $constants = array();
241        foreach ($extConstants as $cst => $val) {
242            $constants[$cst]['init'] = $ver;
243            $constants[$cst]['name'] = $cst;
244        }
245
246        $exceptions = getExceptions($extName, 'constant');
247        if ($exceptions === false) {
248            // no constant exceptions for this extension
249        } else {
250            // apply exceptions to give final constant results
251            $constants = array_merge($constants, $exceptions);
252        }
253        ksort($constants);
254
255        file_put_contents($target_directory . $extName . '_const_array.php',
256                          "<?php
257/**
258 * $extName extension Constant dictionary for PHP_CompatInfo 1.9.0a1 or better
259 *
260 * PHP versions 4 and 5
261 *
262 * @category PHP
263 * @package  PHP_CompatInfo
264 * @author   Davey Shafik <davey@php.net>
265 * @author   Laurent Laville <pear@laurent-laville.org>
266 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
267 * @version  CVS: \$Id: configure.php,v 1.8 2008/12/26 18:50:51 farell Exp $
268 * @link     http://pear.php.net/package/PHP_CompatInfo
269 * @since    version 1.9.0a1 (2008-11-23)
270 */
271
272\$GLOBALS['_PHP_COMPATINFO_CONST_" . strtoupper($extName) . "'] = " .
273        var_export($constants, true) . ";
274?>");
275
276    }
277
278    // classes described by the Extension interface
279    $extClasses = $ext->getClassNames();
280    if (count($extClasses) > 0) {
281        $class_glob_list[] = $extName;
282
283        $classes = array();
284        foreach ($extClasses as $i => $cls) {
285            $classes[$cls]['init'] = $ver;
286            $classes[$cls]['name'] = $cls;
287            $classes[$cls]['ext']  = $extName;
288            $classes[$cls]['pecl'] = false;
289        }
290
291        $exceptions = getExceptions($extName, 'class');
292        if ($exceptions === false) {
293            // no class exceptions for this extension
294        } else {
295            // apply exceptions to give final class results
296            $classes = array_merge($classes, $exceptions);
297        }
298        ksort($classes);
299
300        file_put_contents($target_directory . $extName . '_class_array.php',
301                          "<?php
302/**
303 * $extName extension Class dictionary for PHP_CompatInfo 1.9.0a1 or better
304 *
305 * PHP versions 4 and 5
306 *
307 * @category PHP
308 * @package  PHP_CompatInfo
309 * @author   Davey Shafik <davey@php.net>
310 * @author   Laurent Laville <pear@laurent-laville.org>
311 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
312 * @version  CVS: \$Id: configure.php,v 1.8 2008/12/26 18:50:51 farell Exp $
313 * @link     http://pear.php.net/package/PHP_CompatInfo
314 * @since    version 1.9.0a1 (2008-11-23)
315 */
316
317\$GLOBALS['_PHP_COMPATINFO_CLASS_" . strtoupper($extName) . "'] = " .
318        var_export($classes, true) . ";
319?>");
320
321    }
322
323    // functions described by the Extension interface
324    $extFunctions = $ext->getFunctions();
325    if (count($extFunctions) > 0) {
326        $func_glob_list[] = $extName;
327
328        $functions = array();
329        foreach ($extFunctions as $oFunction) {
330            $func                     = $oFunction->getName();
331            $functions[$func]['init'] = $ver;
332            $functions[$func]['name'] = $func;
333            $functions[$func]['ext']  = $extName;
334            $functions[$func]['pecl'] = false;
335        }
336
337        $exceptions = getExceptions($extName, 'function');
338        if ($exceptions === false) {
339            // no class exceptions for this extension
340        } else {
341            // apply exceptions to give final function results
342            $functions = array_merge($functions, $exceptions);
343        }
344        ksort($functions);
345
346        file_put_contents($target_directory . $extName . '_func_array.php',
347                          "<?php
348/**
349 * $extName extension Function dictionary for PHP_CompatInfo 1.9.0b2 or better
350 *
351 * PHP versions 4 and 5
352 *
353 * @category PHP
354 * @package  PHP_CompatInfo
355 * @author   Davey Shafik <davey@php.net>
356 * @author   Laurent Laville <pear@laurent-laville.org>
357 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
358 * @version  CVS: \$Id: configure.php,v 1.8 2008/12/26 18:50:51 farell Exp $
359 * @link     http://pear.php.net/package/PHP_CompatInfo
360 * @since    version 1.9.0b2 (2008-12-19)
361 */
362
363\$GLOBALS['_PHP_COMPATINFO_FUNC_" . strtoupper($extName) . "'] = " .
364        var_export($functions, true) . ";
365?>");
366
367    }
368}
369
370$sapi_glob_list  = array();
371
372foreach ($sapis as $sapi) {
373
374    $functions = getExceptions($sapi, 'function');
375    if ($functions === false) {
376        // no sapi functions
377        continue;
378    }
379
380    if ($verbose > 0) {
381        print 'Found SAPI '. $sapi . PHP_EOL;
382    }
383
384    $sapi_glob_list[] = $sapi;
385    ksort($functions);
386
387    file_put_contents($target_directory . $sapi . '_sapi_array.php',
388                      "<?php
389/**
390 * $sapi SAPI Function dictionary for PHP_CompatInfo 1.9.0b2 or better
391 *
392 * PHP versions 4 and 5
393 *
394 * @category PHP
395 * @package  PHP_CompatInfo
396 * @author   Davey Shafik <davey@php.net>
397 * @author   Laurent Laville <pear@laurent-laville.org>
398 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
399 * @version  CVS: \$Id: configure.php,v 1.8 2008/12/26 18:50:51 farell Exp $
400 * @link     http://pear.php.net/package/PHP_CompatInfo
401 * @since    version 1.9.0b2 (2008-12-19)
402 */
403
404\$GLOBALS['_PHP_COMPATINFO_SAPI_" . strtoupper($sapi) . "'] = " .
405        var_export($functions, true) . ";
406?>");
407
408}
409
410$const_glob_list = array_unique($const_glob_list);
411natcasesort($const_glob_list);
412
413$requires = '';
414$globals  = '';
415foreach ($const_glob_list as $cstExt) {
416    $requires .= "require_once 'PHP/CompatInfo/" . $cstExt . "_const_array.php';"
417              . PHP_EOL;
418    $globals  .= "    \$GLOBALS['_PHP_COMPATINFO_CONST_" . strtoupper($cstExt)
419              . "'], " . PHP_EOL;
420}
421$globals  = rtrim($globals, ", ".PHP_EOL);
422$globals .= PHP_EOL;
423
424file_put_contents($target_directory . 'const_array.php',
425
426"<?php
427/**
428 * Constant dictionary for PHP_CompatInfo 1.1.1 or better
429 *
430 * PHP versions 4 and 5
431 *
432 * @category PHP
433 * @package  PHP_CompatInfo
434 * @author   Davey Shafik <davey@php.net>
435 * @author   Laurent Laville <pear@laurent-laville.org>
436 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
437 * @version  CVS: \$Id: configure.php,v 1.8 2008/12/26 18:50:51 farell Exp $
438 * @link     http://pear.php.net/package/PHP_CompatInfo
439 * @since    version 1.1.1 (2006-07-27)
440 */
441
442". $requires .
443"
444/**
445 * Predefined Constants
446 *
447 * @link http://www.php.net/manual/en/reserved.constants.php
448 * @global array \$GLOBALS['_PHP_COMPATINFO_CONST']
449 */
450
451\$GLOBALS['_PHP_COMPATINFO_CONST'] = array_merge(
452". $globals .
453"    );
454?>");
455
456
457$class_glob_list = array_unique($class_glob_list);
458natcasesort($class_glob_list);
459
460$requires = '';
461$globals  = '';
462foreach ($class_glob_list as $clsExt) {
463    $requires .= "require_once 'PHP/CompatInfo/" . $clsExt . "_class_array.php';"
464              . PHP_EOL;
465    $globals  .= "    \$GLOBALS['_PHP_COMPATINFO_CLASS_" . strtoupper($clsExt)
466              . "'], " . PHP_EOL;
467}
468$globals  = rtrim($globals, ", ".PHP_EOL);
469$globals .= PHP_EOL;
470
471file_put_contents($target_directory . 'class_array.php',
472
473"<?php
474/**
475 * Class dictionary for PHP_CompatInfo 1.9.0a1 or better
476 *
477 * PHP versions 4 and 5
478 *
479 * @category PHP
480 * @package  PHP_CompatInfo
481 * @author   Davey Shafik <davey@php.net>
482 * @author   Laurent Laville <pear@laurent-laville.org>
483 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
484 * @version  CVS: \$Id: configure.php,v 1.8 2008/12/26 18:50:51 farell Exp $
485 * @link     http://pear.php.net/package/PHP_CompatInfo
486 * @since    version 1.9.0a1 (2008-11-23)
487 */
488
489". $requires .
490"
491/**
492 * Predefined Classes
493 *
494 * > Standard Defined Classes
495 *   These classes are defined in the standard set of functions included in
496 *   the PHP build.
497 * - Directory
498 * - stdClass
499 * -  __PHP_Incomplete_Class
500 *
501 * > Predefined classes as of PHP 5
502 *   These additional predefined classes were introduced in PHP 5.0.0
503 * - Exception
504 * - php_user_filter
505 *
506 * > Miscellaneous extensions
507 *   define other classes which are described in their reference.
508 *
509 * @link http://www.php.net/manual/en/function.get-declared-classes.php
510 * @link http://www.php.net/manual/en/reserved.classes.php
511 * @global array \$GLOBALS['_PHP_COMPATINFO_CLASS']
512 */
513
514\$GLOBALS['_PHP_COMPATINFO_CLASS'] = array_merge(
515". $globals .
516"    );
517?>");
518
519
520$func_glob_list = array_unique($func_glob_list);
521natcasesort($func_glob_list);
522
523$requires = '';
524$globals  = '';
525foreach ($func_glob_list as $funcExt) {
526    $requires .= "require_once 'PHP/CompatInfo/" . $funcExt . "_func_array.php';"
527              . PHP_EOL;
528    $globals  .= "    \$GLOBALS['_PHP_COMPATINFO_FUNC_" . strtoupper($funcExt)
529              . "'], " . PHP_EOL;
530}
531$globals  = rtrim($globals, ", ".PHP_EOL);
532$globals .= PHP_EOL;
533
534file_put_contents($target_directory . 'func_array.php',
535
536"<?php
537/**
538 * Function dictionary for PHP_CompatInfo 1.9.0a1 or better
539 *
540 * PHP versions 4 and 5
541 *
542 * @category PHP
543 * @package  PHP_CompatInfo
544 * @author   Davey Shafik <davey@php.net>
545 * @author   Laurent Laville <pear@laurent-laville.org>
546 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD
547 * @version  CVS: \$Id: configure.php,v 1.8 2008/12/26 18:50:51 farell Exp $
548 * @link     http://pear.php.net/package/PHP_CompatInfo
549 * @since    version 1.9.0a1 (2008-11-23)
550 */
551
552". $requires .
553"
554/**
555 * Predefined Functions
556 *
557 * @global array \$GLOBALS['_PHP_COMPATINFO_FUNCS']
558 */
559
560\$GLOBALS['_PHP_COMPATINFO_FUNCS'] = array_merge(
561". $globals .
562"    );
563?>");
564?>