Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conduit/parametertype/ConduitListParameterType.php
<?php | <?php | ||||
abstract class ConduitListParameterType | abstract class ConduitListParameterType | ||||
extends ConduitParameterType { | extends ConduitParameterType { | ||||
private $allowEmptyList = true; | private $allowEmptyList = true; | ||||
public function setAllowEmptyList($allow_empty_list) { | public function setAllowEmptyList($allow_empty_list) { | ||||
$this->allowEmptyList = $allow_empty_list; | $this->allowEmptyList = $allow_empty_list; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getAllowEmptyList() { | public function getAllowEmptyList() { | ||||
return $this->allowEmptyList; | return $this->allowEmptyList; | ||||
} | } | ||||
protected function getParameterValue(array $request, $key) { | protected function getParameterValue(array $request, $key, $strict) { | ||||
$value = parent::getParameterValue($request, $key); | $value = parent::getParameterValue($request, $key, $strict); | ||||
if (!is_array($value)) { | if (!is_array($value)) { | ||||
$this->raiseValidationException( | $this->raiseValidationException( | ||||
$request, | $request, | ||||
$key, | $key, | ||||
pht('Expected a list, but value is not a list.')); | pht('Expected a list, but value is not a list.')); | ||||
} | } | ||||
Show All 16 Lines | if (!$value && !$this->getAllowEmptyList()) { | ||||
$request, | $request, | ||||
$key, | $key, | ||||
pht('Expected a nonempty list, but value is an empty list.')); | pht('Expected a nonempty list, but value is an empty list.')); | ||||
} | } | ||||
return $value; | return $value; | ||||
} | } | ||||
protected function validateStringList(array $request, $key, array $list) { | protected function parseStringList( | ||||
array $request, | |||||
$key, | |||||
array $list, | |||||
$strict) { | |||||
foreach ($list as $idx => $item) { | foreach ($list as $idx => $item) { | ||||
if (!is_string($item)) { | $list[$idx] = $this->parseStringValue( | ||||
$this->raiseValidationException( | |||||
$request, | $request, | ||||
$key, | $key.'['.$idx.']', | ||||
pht( | $item, | ||||
'Expected a list of strings, but item with index "%s" is '. | $strict); | ||||
'not a string.', | |||||
$idx)); | |||||
} | |||||
} | } | ||||
return $list; | return $list; | ||||
} | } | ||||
protected function getParameterDefault() { | protected function getParameterDefault() { | ||||
return array(); | return array(); | ||||
} | } | ||||
} | } |