51 public function validate( $name, $value, array $settings, array $options ) {
54 if ( in_array( $value, $values,
true ) ) {
56 if ( empty( $options[
'is-default'] ) &&
57 isset( $settings[self::PARAM_DEPRECATED_VALUES][$value] )
61 $message = DataMessageValue::new(
70 $this->
failure( $message, $name, $value, $settings, $options,
false );
76 $isMulti = isset( $options[
'values-list'] );
78 $this->
failureMessage(
'badvalue', [], $isMulti ?
'enummulti' :
'enumnotmulti' )
79 ->textListParams( array_map(
static function ( $v ) {
82 ->numParams( count( $values ) ),
83 $name, $value, $settings, $options
87 public function checkSettings(
string $name, $settings, array $options, array $ret ): array {
88 $ret = parent::
checkSettings( $name, $settings, $options, $ret );
93 if ( !is_array( $dv ) ) {
97 $values = array_map(
function ( $v ) use ( $name, $settings, $options ) {
100 foreach ( $dv as $k => $v ) {
102 if ( !in_array( $k, $values,
true ) ) {
103 $ret[
'issues'][] =
"PARAM_DEPRECATED_VALUES contains \"$k\", which is not "
104 .
'one of the enumerated values';
105 } elseif ( $v instanceof MessageValue ) {
106 $ret[
'messages'][] = $v;
107 } elseif ( $v !==
null && $v !==
true ) {
108 $type = $v ===
false ?
'false' : ( is_object( $v ) ? get_class( $v ) : gettype( $v ) );
109 $ret[
'issues'][] =
'Values in PARAM_DEPRECATED_VALUES must be null, true, or MessageValue, '
110 .
"but value for \"$k\" is $type";
122 public function stringifyValue( $name, $value, array $settings, array $options ) {
123 if ( !is_array( $value ) ) {
124 return parent::stringifyValue( $name, $value, $settings, $options );
130 public function getParamInfo( $name, array $settings, array $options ) {
131 $info = parent::getParamInfo( $name, $settings, $options );
133 $info[
'type'] = $this->sortEnumValues(
140 if ( !empty( $settings[self::PARAM_DEPRECATED_VALUES] ) ) {
141 $deprecatedValues = array_intersect(
142 array_keys( $settings[self::PARAM_DEPRECATED_VALUES] ),
145 if ( $deprecatedValues ) {
146 $deprecatedValues = $this->sortEnumValues( $name, $deprecatedValues, $settings, $options );
147 $info[
'deprecatedvalues'] = array_values( $deprecatedValues );
154 public function getHelpInfo( $name, array $settings, array $options ) {
155 $info = parent::getHelpInfo( $name, $settings, $options );
159 $values = $this->getEnumValuesForHelp( $name, $settings, $options );
160 $count = count( $values );
162 $i = array_search(
'', $values,
true );
163 if ( $i ===
false ) {
166 unset( $values[$i] );
167 $valuesParam = MessageValue::new(
'paramvalidator-help-type-enum-can-be-empty' )
168 ->commaListParams( $values )
169 ->numParams( count( $values ) );
173 ->params( $isMulti ? 2 : 1 )
174 ->params( $valuesParam )
175 ->numParams( $count );
193 string $name, array $values, array $settings, array $options
197 foreach ( $values as $k => $value ) {
199 if ( isset( $settings[self::PARAM_DEPRECATED_VALUES][$value] ) ) {
204 array_multisort( $flags, $values, SORT_NATURAL );
218 $values = $this->getEnumValues( $name, $settings, $options );
219 $values = $this->sortEnumValues( $name, $values, $settings, $options );