Skip to content

Commit edef6e1

Browse files
author
Blake Williams
committed
fixed null argv bug in handler
fixed child pattern argument handling
1 parent 03decdc commit edef6e1

2 files changed

Lines changed: 552 additions & 429 deletions

File tree

src/docopt.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Return true if all cased characters in the string are uppercase and there is
1616
* at least one cased character, false otherwise.
17-
* Python method with no known equivalent in PHP.
17+
* Python method with no knowrn equivalent in PHP.
1818
*/
1919
function is_upper($string)
2020
{
@@ -385,7 +385,7 @@ public function __construct($children=null)
385385
if (!$children)
386386
$children = array();
387387
elseif ($children instanceof Pattern)
388-
$children = array($children);
388+
$children = func_get_args();
389389

390390
foreach ($children as $c) {
391391
$this->children[] = $c;
@@ -638,7 +638,7 @@ public function match($left, $collected=null)
638638
{
639639
if (!$collected)
640640
$collected = array();
641-
641+
642642
$outcomes = array();
643643
foreach ($this->children as $p) {
644644
list ($matched, $dump1, $dump2) = $outcome = $p->match($left, $collected);
@@ -713,12 +713,11 @@ function parse_long($tokens, \ArrayIterator $options)
713713
throw new \UnexpectedValueExeption();
714714

715715
if (!$value) $value = null;
716-
717716

718717
$similar = array_filter($options, function($o) use ($long) { return $o->long && $o->long == $long; }, true);
719718
if ('ExitException' == $tokens->error && !$similar)
720719
$similar = array_filter($options, function($o) use ($long) { return $o->long && strpos($o->long, $long)===0; }, true);
721-
720+
722721
if (count($similar) > 1) {
723722
// might be simply specified ambiguously 2+ times?
724723
$tokens->raiseException("$long is not a unique prefix: ".implode(', ', array_map(function($o) { return $o->long; }, $similar)));
@@ -750,7 +749,6 @@ function parse_long($tokens, \ArrayIterator $options)
750749
$o->value = $value !== null ? $value : true;
751750
}
752751
}
753-
754752
return array($o);
755753
}
756754

@@ -1048,7 +1046,7 @@ public function __construct($options=array())
10481046
function handle($doc, $argv=null)
10491047
{
10501048
try {
1051-
if (!$argv && isset($_SERVER['argv']))
1049+
if ($argv === null && isset($_SERVER['argv']))
10521050
$argv = array_slice($_SERVER['argv'], 1);
10531051

10541052
ExitException::$usage = printable_usage($doc);

0 commit comments

Comments
 (0)