From 145775132b543be423933a79a98ab96e27cc63f9 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Fri, 29 Aug 2008 21:09:18 +0000 Subject: [PATCH] Add a function to require one and only one parameter of a list. --- includes/api/ApiBase.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 -- 2.20.1