protected function parseLongOption($option, $argument, array $options, &$argumentIndex)
{
$index = null;
$exact = false;
$ambiguous = false;
$optionName = substr($option, 2);
for ($length = 0; isset($option[$length + 2]) && $option[$length + 2] !== '='; $length++) {
}
foreach ($options as $i => $optionData) {
if (!strncmp($optionData['name'], $optionName, $length)) {
if (strlen($optionName) === strlen($optionData['name'])) {
$index = $i;
$exact = true;
break;
} elseif ($index === null) {
$index = $i;
} elseif ($options[$index]['code'] !== $optionData['code'] || $options[$index]['has_arg'] !== $optionData['has_arg']) {
$ambiguous = true;
}
}
}
if ($ambiguous && !$exact) {
$this->error = sprintf('Option "%s" is ambigiuous', $option);
return false;
} elseif ($index === null) {
$this->error = sprintf('Unrecognized option "%s"', $option);
return false;
}
$argumentIndex++;
if (isset($option[$length + 2])) {
if ($options[$index]['has_arg'] === false) {
$this->error = sprintf('Option "%s" doesn\'t allow an argument', $option);
return false;
} elseif ($options[$index]['has_arg'] === true && !isset($option[$length + 3])) {
$this->error = sprintf('Option "%s" requires an argument', $option);
return false;
}
$this->options[] = array('code' => $options[$index]['code'], 'argument' => substr($option, $length + 3));
return true;
}
if ($options[$index]['has_arg'] === true) {
if (!$argument || !isset($argument[0])) {
$this->error = sprintf('Option "%s" requires an argument', $option);
return false;
}
$argumentIndex++;
$this->options[] = array('code' => $options[$index]['code'], 'argument' => $argument);
return true;
}
$this->options[] = array('code' => $options[$index]['code'], 'argument' => null);
return true;
}