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; | |||||
public function setAllowEmptyList($allow_empty_list) { | |||||
$this->allowEmptyList = $allow_empty_list; | |||||
return $this; | |||||
} | |||||
public function getAllowEmptyList() { | |||||
return $this->allowEmptyList; | |||||
} | |||||
protected function getParameterValue(array $request, $key) { | protected function getParameterValue(array $request, $key) { | ||||
$value = parent::getParameterValue($request, $key); | $value = parent::getParameterValue($request, $key); | ||||
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.')); | ||||
} | } | ||||
$actual_keys = array_keys($value); | $actual_keys = array_keys($value); | ||||
if ($value) { | if ($value) { | ||||
$natural_keys = range(0, count($value) - 1); | $natural_keys = range(0, count($value) - 1); | ||||
} else { | } else { | ||||
$natural_keys = array(); | $natural_keys = array(); | ||||
} | } | ||||
if ($actual_keys !== $natural_keys) { | if ($actual_keys !== $natural_keys) { | ||||
$this->raiseValidationException( | $this->raiseValidationException( | ||||
$request, | $request, | ||||
$key, | $key, | ||||
pht('Expected a list, but value is an object.')); | 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; | return $value; | ||||
} | } | ||||
protected function validateStringList(array $request, $key, array $list) { | protected function validateStringList(array $request, $key, array $list) { | ||||
foreach ($list as $idx => $item) { | foreach ($list as $idx => $item) { | ||||
if (!is_string($item)) { | if (!is_string($item)) { | ||||
$this->raiseValidationException( | $this->raiseValidationException( | ||||
$request, | $request, | ||||
Show All 16 Lines |