0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 16:31:53 +00:00

- Rewrite command line parsing code to support --opt val

- Add $php settings variable

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1555 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-02-16 23:23:45 +00:00
parent 8c439aa62c
commit 9f851b2139
3 changed files with 40 additions and 14 deletions

View File

@ -28,6 +28,7 @@ $GLOBALS['HTMLPurifierTest']['PH5P'] = class_exists('DOMDocument');
$simpletest_location = 'simpletest/'; // reasonable guess
$csstidy_location = false;
$versions_to_test = array();
$php = 'php';
$phpv = 'phpv';
// load configuration
@ -72,12 +73,8 @@ require_once 'tally_errors.func.php'; // compat
* Arguments parser, is cli and web agnostic.
* @warning
* There are some quirks about the argument format:
* - Short flags cannot be chained together
* - Any number of hyphens are allowed to lead flags
* - Flag values cannot have spaces in them
* - You must specify an equal sign, --foo=value; --foo value doesn't work
* - Only strings and booleans are accepted
* - This --flag=off will be interpreted as true, use --flag=0 instead
* - Short boolean flags cannot be chained together
* - Only strings, integers and booleans are accepted
* @param $AC
* Arguments array to populate. This takes a simple format of 'argument'
* => default value. Depending on the type of the default value,
@ -90,15 +87,43 @@ require_once 'tally_errors.func.php'; // compat
function htmlpurifier_parse_args(&$AC, $aliases) {
if (empty($_GET)) {
array_shift($_SERVER['argv']);
$o = false;
$bool = false;
$val_is_bool = false;
foreach ($_SERVER['argv'] as $opt) {
if (strpos($opt, "=") !== false) {
list($o, $v) = explode("=", $opt, 2);
if ($o !== false) {
$v = $opt;
} else {
$o = $opt;
$v = true;
if ($opt === '') continue;
if (strlen($opt) > 2 && strncmp($opt, '--', 2) === 0) {
$o = substr($opt, 2);
} elseif ($opt[0] == '-') {
$o = substr($opt, 1);
} else {
$lopt = strtolower($opt);
if ($bool !== false && ($opt === '0' || $lopt === 'off' || $lopt === 'no')) {
$o = $bool;
$v = false;
$val_is_bool = true;
} elseif (isset($aliases[''])) {
$o = $aliases[''];
}
$o = ltrim($o, '-');
}
$bool = false;
if (!isset($AC[$o]) || !is_bool($AC[$o])) {
if (strpos($o, '=') === false) {
continue;
}
list($o, $v) = explode('=', $o);
} elseif (!$val_is_bool) {
$v = true;
$bool = $o;
}
$val_is_bool = false;
}
if ($o === false) continue;
htmlpurifier_args($AC, $aliases, $o, $v);
$o = false;
}
} else {
foreach ($_GET as $o => $v) {
@ -119,7 +144,8 @@ function htmlpurifier_args(&$AC, $aliases, $o, $v) {
if (isset($aliases[$o])) $o = $aliases[$o];
if (!isset($AC[$o])) return;
if (is_string($AC[$o])) $AC[$o] = $v;
if (is_bool($AC[$o])) $AC[$o] = true;
if (is_bool($AC[$o])) $AC[$o] = (bool) $v;
if (is_int($AC[$o])) $AC[$o] = (int) $v;
}
/**

View File

@ -39,7 +39,7 @@ htmlpurifier_parse_args($AC, $aliases);
if (!SimpleReporter::inCli()) {
// Undo any dangerous parameters
$AC['php'] = 'php';
$AC['php'] = $php;
}
if ($AC['disable-phpt'] && $AC['only-phpt']) {

View File

@ -98,7 +98,7 @@ foreach ($versions_to_test as $version) {
//if (!$AC['disable-phpt']) {
$test->addTestCase(
new CliTestCase(
$AC['php'] . " index.php --xml --php=\"$phpv $version\" --only-phpt",
$AC['php'] . " index.php --xml --php \"$phpv $version\" --only-phpt",
$AC['quiet'], $size
)
);