65 $this->allowEmptyWhenRequired = !empty( $options[ self::OPT_ALLOW_EMPTY ] );
68 public function validate( $name, $value, array $settings, array $options ) {
75 $this->
failure(
'missingparam', $name, $value, $settings, $options );
80 $len = strlen( $value );
81 if ( isset( $settings[self::PARAM_MAX_BYTES] ) && $len > $settings[self::PARAM_MAX_BYTES] ) {
84 'maxbytes' => $settings[self::PARAM_MAX_BYTES] ??
null,
85 'maxchars' => $settings[self::PARAM_MAX_CHARS] ??
null,
86 ] )->numParams( $settings[self::PARAM_MAX_BYTES], $len ),
87 $name, $value, $settings, $options
90 $len = mb_strlen( $value,
'UTF-8' );
91 if ( isset( $settings[self::PARAM_MAX_CHARS] ) && $len > $settings[self::PARAM_MAX_CHARS] ) {
94 'maxbytes' => $settings[self::PARAM_MAX_BYTES] ??
null,
95 'maxchars' => $settings[self::PARAM_MAX_CHARS] ??
null,
96 ] )->numParams( $settings[self::PARAM_MAX_CHARS], $len ),
97 $name, $value, $settings, $options
104 public function checkSettings(
string $name, $settings, array $options, array $ret ): array {
105 $ret = parent::
checkSettings( $name, $settings, $options, $ret );
107 $ret[
'allowedKeys'] = array_merge( $ret[
'allowedKeys'], [
108 self::PARAM_MAX_BYTES, self::PARAM_MAX_CHARS,
112 if ( !is_int( $maxb ) ) {
115 } elseif ( $maxb < 0 ) {
120 if ( !is_int( $maxc ) ) {
123 } elseif ( $maxc < 0 ) {
129 $ret[
'issues'][] =
'PARAM_REQUIRED is set, allowEmptyWhenRequired is not set, and '
130 .
'PARAM_MAX_BYTES is 0. That\'s impossible to satisfy.';
133 $ret[
'issues'][] =
'PARAM_REQUIRED is set, allowEmptyWhenRequired is not set, and '
134 .
'PARAM_MAX_CHARS is 0. That\'s impossible to satisfy.';
141 public function getParamInfo( $name, array $settings, array $options ) {
142 $info = parent::getParamInfo( $name, $settings, $options );
144 $info[
'maxbytes'] = $settings[self::PARAM_MAX_BYTES] ??
null;
145 $info[
'maxchars'] = $settings[self::PARAM_MAX_CHARS] ??
null;
150 public function getHelpInfo( $name, array $settings, array $options ) {
151 $info = parent::getHelpInfo( $name, $settings, $options );
153 if ( isset( $settings[self::PARAM_MAX_BYTES] ) ) {
154 $info[self::PARAM_MAX_BYTES] = MessageValue::new(
'paramvalidator-help-type-string-maxbytes' )
155 ->numParams( $settings[self::PARAM_MAX_BYTES] );
157 if ( isset( $settings[self::PARAM_MAX_CHARS] ) ) {
158 $info[self::PARAM_MAX_CHARS] = MessageValue::new(
'paramvalidator-help-type-string-maxchars' )
159 ->numParams( $settings[self::PARAM_MAX_CHARS] );