public static function parseShortParam($str, $other = [])
{
// Is the parameter optional?
if (self::strEnds($str, '?')) {
$required = false;
$str = substr($str, 0, -1);
} else {
$required = true;
}
// Check for a type.
$parts = explode(':', $str);
if (count($parts) === 1) {
if (isset($other['type'])) {
$type = $other['type'];
} else {
$type = 'string';
}
$name = $parts[0];
} else {
$name = $parts[1];
if (isset(self::$types[$parts[0]])) {
$type = self::$types[$parts[0]];
} else {
throw new \InvalidArgumentException("Invalid type {$parts[1]} for field {$name}.", 500);
}
}
$result = ['name' => $name, 'type' => $type, 'required' => $required];
return $result;
}