diff --git a/src/applications/conduit/parametertype/ConduitListParameterType.php b/src/applications/conduit/parametertype/ConduitListParameterType.php index 10c81e8c5d..6ec3898ac2 100644 --- a/src/applications/conduit/parametertype/ConduitListParameterType.php +++ b/src/applications/conduit/parametertype/ConduitListParameterType.php @@ -1,53 +1,71 @@ allowEmptyList = $allow_empty_list; + return $this; + } + + public function getAllowEmptyList() { + return $this->allowEmptyList; + } + protected function getParameterValue(array $request, $key) { $value = parent::getParameterValue($request, $key); if (!is_array($value)) { $this->raiseValidationException( $request, $key, pht('Expected a list, but value is not a list.')); } $actual_keys = array_keys($value); if ($value) { $natural_keys = range(0, count($value) - 1); } else { $natural_keys = array(); } if ($actual_keys !== $natural_keys) { $this->raiseValidationException( $request, $key, pht('Expected a list, but value is an object.')); } + if (!$value && !$this->getAllowEmptyList()) { + $this->raiseValidationException( + $request, + $key, + pht('Expected a nonempty list, but value is an empty list.')); + } + return $value; } protected function validateStringList(array $request, $key, array $list) { foreach ($list as $idx => $item) { if (!is_string($item)) { $this->raiseValidationException( $request, $key, pht( 'Expected a list of strings, but item with index "%s" is '. 'not a string.', $idx)); } } return $list; } protected function getParameterDefault() { return array(); } } diff --git a/src/applications/conduit/parametertype/ConduitParameterType.php b/src/applications/conduit/parametertype/ConduitParameterType.php index 8f02057c0f..6468b099a0 100644 --- a/src/applications/conduit/parametertype/ConduitParameterType.php +++ b/src/applications/conduit/parametertype/ConduitParameterType.php @@ -1,97 +1,101 @@ viewer = $viewer; return $this; } final public function getViewer() { if (!$this->viewer) { throw new PhutilInvalidStateException('setViewer'); } return $this->viewer; } final public function getExists(array $request, $key) { return $this->getParameterExists($request, $key); } final public function getValue(array $request, $key) { if (!$this->getExists($request, $key)) { return $this->getParameterDefault(); } return $this->getParameterValue($request, $key); } final public function getDefaultValue() { return $this->getParameterDefault(); } final public function getTypeName() { return $this->getParameterTypeName(); } final public function getFormatDescriptions() { return $this->getParameterFormatDescriptions(); } final public function getExamples() { return $this->getParameterExamples(); } protected function raiseValidationException(array $request, $key, $message) { // TODO: Specialize this so we can give users more tailored messages from // Conduit. - throw new Exception($message); + throw new Exception( + pht( + 'Error while reading "%s": %s', + $key, + $message)); } final public static function getAllTypes() { return id(new PhutilClassMapQuery()) ->setAncestorClass(__CLASS__) ->setUniqueMethod('getTypeName') ->setSortMethod('getTypeName') ->execute(); } protected function getParameterExists(array $request, $key) { return array_key_exists($key, $request); } protected function getParameterValue(array $request, $key) { return $request[$key]; } abstract protected function getParameterTypeName(); abstract protected function getParameterFormatDescriptions(); abstract protected function getParameterExamples(); protected function getParameterDefault() { return null; } } diff --git a/src/applications/search/field/PhabricatorIDsSearchField.php b/src/applications/search/field/PhabricatorIDsSearchField.php index 909cce9c4a..cb8c27ef75 100644 --- a/src/applications/search/field/PhabricatorIDsSearchField.php +++ b/src/applications/search/field/PhabricatorIDsSearchField.php @@ -1,30 +1,31 @@ getStrList($key); } protected function newControl() { if (strlen($this->getValueForControl())) { return new AphrontFormTextControl(); } else { return null; } } protected function getValueForControl() { return implode(', ', parent::getValueForControl()); } protected function newConduitParameterType() { - return new ConduitIntListParameterType(); + return id(new ConduitIntListParameterType()) + ->setAllowEmptyList(false); } } diff --git a/src/applications/search/field/PhabricatorPHIDsSearchField.php b/src/applications/search/field/PhabricatorPHIDsSearchField.php index 459233c472..c88ef7670a 100644 --- a/src/applications/search/field/PhabricatorPHIDsSearchField.php +++ b/src/applications/search/field/PhabricatorPHIDsSearchField.php @@ -1,30 +1,31 @@ getStrList($key); } protected function newControl() { if (strlen($this->getValueForControl())) { return new AphrontFormTextControl(); } else { return null; } } protected function getValueForControl() { return implode(', ', parent::getValueForControl()); } protected function newConduitParameterType() { - return new ConduitPHIDListParameterType(); + return id(new ConduitPHIDListParameterType()) + ->setAllowEmptyList(false); } } diff --git a/src/applications/search/field/PhabricatorSearchDatasourceField.php b/src/applications/search/field/PhabricatorSearchDatasourceField.php index 6ba322936f..d8c1242ef4 100644 --- a/src/applications/search/field/PhabricatorSearchDatasourceField.php +++ b/src/applications/search/field/PhabricatorSearchDatasourceField.php @@ -1,31 +1,32 @@ datasource); } public function setDatasource(PhabricatorTypeaheadDatasource $datasource) { $this->datasource = $datasource; return $this; } public function setConduitParameterType(ConduitParameterType $type) { $this->conduitParameterType = $type; return $this; } protected function newConduitParameterType() { if (!$this->conduitParameterType) { - return new ConduitStringListParameterType(); + return id(new ConduitStringListParameterType()) + ->setAllowEmptyList(false); } return $this->conduitParameterType; } }