From: Bryan Tong Minh Date: Fri, 29 Aug 2008 21:09:18 +0000 (+0000) Subject: Add a function to require one and only one parameter of a list. X-Git-Tag: 1.31.0-rc.0~45554 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/?a=commitdiff_plain;h=145775132b543be423933a79a98ab96e27cc63f9;p=lhc%2Fweb%2Fwiklou.git Add a function to require one and only one parameter of a list. --- diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index f926a2d575..42538226cc 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -365,6 +365,21 @@ abstract class ApiBase { $paramSettings = $params[$paramName]; return $this->getParameterFromSettings($paramName, $paramSettings, $parseMaxLimit); } + + /** + * Die if none or more than one of a certain set of parameters is set + */ + public function requireOnlyOneParameter($params) { + $required = func_get_args(); + array_shift($required); + + $intersection = array_intersect(array_keys($params), $required); + if (count($intersection) > 1) { + $this->dieUsage('The parameters '.implode(', ', $intersection).' can not be used together', 'invalidparammix'); + } elseif (count($intersection) == 0) { + $this->dieUsage('One of the parameters '.implode(', ', $required).' is required', 'missingparam'); + } + } /** * Returns an array of the namespaces (by integer id) that exist on the