65 $this->allowEmptyWhenRequired = !empty( $options[ self::OPT_ALLOW_EMPTY ] );
69 public function validate( $name, $value, array $settings, array $options ) {
76 $this->
failure(
'missingparam', $name, $value, $settings, $options );
81 $len = strlen( $value );
82 if ( isset( $settings[self::PARAM_MAX_BYTES] ) && $len > $settings[self::PARAM_MAX_BYTES] ) {
85 'maxbytes' => $settings[self::PARAM_MAX_BYTES] ??
null,
86 'maxchars' => $settings[self::PARAM_MAX_CHARS] ??
null,
87 ] )->numParams( $settings[self::PARAM_MAX_BYTES], $len ),
88 $name, $value, $settings, $options
91 $len = mb_strlen( $value,
'UTF-8' );
92 if ( isset( $settings[self::PARAM_MAX_CHARS] ) && $len > $settings[self::PARAM_MAX_CHARS] ) {
95 'maxbytes' => $settings[self::PARAM_MAX_BYTES] ??
null,
96 'maxchars' => $settings[self::PARAM_MAX_CHARS] ??
null,
97 ] )->numParams( $settings[self::PARAM_MAX_CHARS], $len ),
98 $name, $value, $settings, $options
106 public function checkSettings(
string $name, $settings, array $options, array $ret ): array {
107 $ret = parent::
checkSettings( $name, $settings, $options, $ret );
113 if ( !is_int( $maxb ) ) {
116 } elseif ( $maxb < 0 ) {
121 if ( !is_int( $maxc ) ) {
124 } elseif ( $maxc < 0 ) {
130 $ret[
'issues'][] =
'PARAM_REQUIRED is set, allowEmptyWhenRequired is not set, and '
131 .
'PARAM_MAX_BYTES is 0. That\'s impossible to satisfy.';
134 $ret[
'issues'][] =
'PARAM_REQUIRED is set, allowEmptyWhenRequired is not set, and '
135 .
'PARAM_MAX_CHARS is 0. That\'s impossible to satisfy.';
143 public function getParamInfo( $name, array $settings, array $options ) {
144 $info = parent::getParamInfo( $name, $settings, $options );
146 $info[
'maxbytes'] = $settings[self::PARAM_MAX_BYTES] ??
null;
147 $info[
'maxchars'] = $settings[self::PARAM_MAX_CHARS] ??
null;
153 public function getHelpInfo( $name, array $settings, array $options ) {
154 $info = parent::getHelpInfo( $name, $settings, $options );
156 if ( isset( $settings[self::PARAM_MAX_BYTES] ) ) {
157 $info[self::PARAM_MAX_BYTES] = MessageValue::new(
'paramvalidator-help-type-string-maxbytes' )
158 ->numParams( $settings[self::PARAM_MAX_BYTES] );
160 if ( isset( $settings[self::PARAM_MAX_CHARS] ) ) {
161 $info[self::PARAM_MAX_CHARS] = MessageValue::new(
'paramvalidator-help-type-string-maxchars' )
162 ->numParams( $settings[self::PARAM_MAX_CHARS] );