64 $this->allowEmptyWhenRequired = !empty( $options[ self::OPT_ALLOW_EMPTY ] );
67 public function validate( $name, $value, array $settings, array $options ) {
74 $this->
failure(
'missingparam', $name, $value, $settings, $options );
79 $len = strlen( $value );
80 if ( isset( $settings[self::PARAM_MAX_BYTES] ) && $len > $settings[self::PARAM_MAX_BYTES] ) {
83 'maxbytes' => $settings[self::PARAM_MAX_BYTES] ??
null,
84 'maxchars' => $settings[self::PARAM_MAX_CHARS] ??
null,
85 ] )->numParams( $settings[self::PARAM_MAX_BYTES], $len ),
86 $name, $value, $settings, $options
89 $len = mb_strlen( $value,
'UTF-8' );
90 if ( isset( $settings[self::PARAM_MAX_CHARS] ) && $len > $settings[self::PARAM_MAX_CHARS] ) {
93 'maxbytes' => $settings[self::PARAM_MAX_BYTES] ??
null,
94 'maxchars' => $settings[self::PARAM_MAX_CHARS] ??
null,
95 ] )->numParams( $settings[self::PARAM_MAX_CHARS], $len ),
96 $name, $value, $settings, $options
103 public function checkSettings(
string $name, $settings, array $options, array $ret ): array {
104 $ret = parent::
checkSettings( $name, $settings, $options, $ret );
106 $ret[
'allowedKeys'] = array_merge( $ret[
'allowedKeys'], [
107 self::PARAM_MAX_BYTES, self::PARAM_MAX_CHARS,
111 if ( !is_int( $maxb ) ) {
114 } elseif ( $maxb < 0 ) {
119 if ( !is_int( $maxc ) ) {
122 } elseif ( $maxc < 0 ) {
128 $ret[
'issues'][] =
'PARAM_REQUIRED is set, allowEmptyWhenRequired is not set, and '
129 .
'PARAM_MAX_BYTES is 0. That\'s impossible to satisfy.';
132 $ret[
'issues'][] =
'PARAM_REQUIRED is set, allowEmptyWhenRequired is not set, and '
133 .
'PARAM_MAX_CHARS is 0. That\'s impossible to satisfy.';
140 public function getParamInfo( $name, array $settings, array $options ) {
141 $info = parent::getParamInfo( $name, $settings, $options );
143 $info[
'maxbytes'] = $settings[self::PARAM_MAX_BYTES] ??
null;
144 $info[
'maxchars'] = $settings[self::PARAM_MAX_CHARS] ??
null;
149 public function getHelpInfo( $name, array $settings, array $options ) {
150 $info = parent::getHelpInfo( $name, $settings, $options );
152 if ( isset( $settings[self::PARAM_MAX_BYTES] ) ) {
153 $info[self::PARAM_MAX_BYTES] = MessageValue::new(
'paramvalidator-help-type-string-maxbytes' )
154 ->numParams( $settings[self::PARAM_MAX_BYTES] );
156 if ( isset( $settings[self::PARAM_MAX_CHARS] ) ) {
157 $info[self::PARAM_MAX_CHARS] = MessageValue::new(
'paramvalidator-help-type-string-maxchars' )
158 ->numParams( $settings[self::PARAM_MAX_CHARS] );