Changeset View
Changeset View
Standalone View
Standalone View
src/config/option/ArcanistListConfigOption.php
- This file was copied to src/config/option/ArcanistMultiSourceConfigOption.php.
<?php | <?php | ||||
abstract class ArcanistListConfigOption | abstract class ArcanistListConfigOption | ||||
extends ArcanistConfigOption { | extends ArcanistSingleSourceConfigOption { | ||||
public function getValueFromStorageValueList(array $list) { | final public function getStorageValueFromStringValue($value) { | ||||
assert_instances_of($list, 'ArcanistConfigurationSourceValue'); | try { | ||||
$json_value = phutil_json_decode($value); | |||||
} catch (PhutilJSONParserException $ex) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Value "%s" is not valid, specify a JSON list: %s', | |||||
$value, | |||||
$ex->getMessage())); | |||||
} | |||||
if (!is_array($json_value) || !phutil_is_natural_list($json_value)) { | |||||
throw new PhutilArgumentUsageException( | |||||
pht( | |||||
'Value "%s" is not valid: expected a list, got "%s".', | |||||
$value, | |||||
phutil_describe_type($json_value))); | |||||
} | |||||
$result_list = array(); | foreach ($json_value as $idx => $item) { | ||||
foreach ($list as $source_value) { | $this->validateListItem($idx, $item); | ||||
$source = $source_value->getConfigurationSource(); | } | ||||
$storage_value = $this->getStorageValueFromSourceValue($source_value); | |||||
$items = $this->getValueFromStorageValue($storage_value); | return $json_value; | ||||
foreach ($items as $item) { | |||||
$result_list[] = new ArcanistConfigurationSourceValue( | |||||
$source, | |||||
$item); | |||||
} | } | ||||
final public function getValueFromStorageValue($value) { | |||||
if (!is_array($value)) { | |||||
throw new Exception(pht('Expected a list!')); | |||||
} | } | ||||
$result_list = $this->didReadStorageValueList($result_list); | if (!phutil_is_natural_list($value)) { | ||||
throw new Exception(pht('Expected a natural list!')); | |||||
} | |||||
return $result_list; | foreach ($value as $idx => $item) { | ||||
$this->validateListItem($idx, $item); | |||||
} | } | ||||
protected function didReadStorageValueList(array $list) { | return $value; | ||||
assert_instances_of($list, 'ArcanistConfigurationSourceValue'); | |||||
return mpull($list, 'getValue'); | |||||
} | } | ||||
public function getDisplayValueFromValue($value) { | |||||
return json_encode($value); | |||||
} | |||||
public function getStorageValueFromValue($value) { | |||||
return $value; | |||||
} | |||||
abstract protected function validateListItem($idx, $item); | |||||
} | } |