28 use UnexpectedValueException;
93 return get_called_class();
162 $fields = array_filter( $this->
getFieldInfo(),
static function ( $info ) {
163 return $info[
'type'] !==
'null';
169 foreach ( $fields as $field => $info ) {
174 if ( $info[
'type'] ===
'checkbox' || $info[
'type'] ===
'button' ) {
175 $this->$field = isset( $data[$field] ) && $data[$field] !==
false
176 || isset( $data[
"{$field}_x"] ) && $data[
"{$field}_x"] !==
false;
177 if ( !$this->$field && empty( $info[
'optional'] ) ) {
184 if ( !isset( $data[$field] ) && $info[
'type'] ===
'multiselect' ) {
188 if ( !isset( $data[$field] ) ) {
191 if ( $data[$field] ===
'' || $data[$field] === [] ) {
192 if ( empty( $info[
'optional'] ) ) {
196 switch ( $info[
'type'] ) {
198 if ( !isset( $info[
'options'][$data[$field]] ) ) {
204 $data[$field] = (array)$data[$field];
206 $allowed = array_keys( $info[
'options'] );
207 if ( array_diff( $data[$field], $allowed ) !== [] ) {
214 $this->$field = $data[$field];
240 'provider' =>
new RawMessage(
'$1', [ get_called_class() ] ),
254 foreach ( $reqs as $req ) {
255 if ( $req->loadFromSubmission( $data ) ) {
276 $requests = array_filter( $reqs,
static function ( $req ) use ( $class, $allowSubclasses ) {
277 if ( $allowSubclasses ) {
278 return is_a( $req, $class,
false );
280 return get_class( $req ) === $class;
284 return count( $requests ) === 1 ? reset( $requests ) :
null;
299 foreach ( $reqs as $req ) {
300 $info = $req->getFieldInfo();
301 if ( $info && array_key_exists(
'username', $info ) && $req->username !==
null ) {
304 $otherClass = get_class( $req );
305 } elseif (
$username !== $req->username ) {
306 $requestClass = get_class( $req );
307 throw new UnexpectedValueException(
"Conflicting username fields: \"{$req->username}\" from "
309 .
"$requestClass::\$username vs. \"$username\" from $otherClass::\$username" );
326 $sharedRequiredPrimaryFields =
null;
327 foreach ( $reqs as $req ) {
328 if ( $req->required !== self::PRIMARY_REQUIRED ) {
332 foreach ( $req->getFieldInfo() as $fieldName => $options ) {
333 if ( empty( $options[
'optional'] ) ) {
337 if ( $sharedRequiredPrimaryFields ===
null ) {
338 $sharedRequiredPrimaryFields =
$required;
340 $sharedRequiredPrimaryFields = array_intersect( $sharedRequiredPrimaryFields,
$required );
344 foreach ( $reqs as $req ) {
345 $info = $req->getFieldInfo();
350 foreach ( $info as $name => $options ) {
353 $req->required === self::OPTIONAL
356 || $req->required === self::PRIMARY_REQUIRED
358 && !in_array( $name, $sharedRequiredPrimaryFields,
true )
360 $options[
'optional'] =
true;
362 $options[
'optional'] = !empty( $options[
'optional'] );
365 $options[
'sensitive'] = !empty( $options[
'sensitive'] );
366 $type = $options[
'type'];
368 if ( !array_key_exists( $name, $merged ) ) {
369 $merged[$name] = $options;
370 } elseif ( $merged[$name][
'type'] !==
$type ) {
371 throw new UnexpectedValueException(
"Field type conflict for \"$name\", " .
372 "\"{$merged[$name]['type']}\" vs \"$type\""
375 if ( isset( $options[
'options'] ) ) {
376 if ( isset( $merged[$name][
'options'] ) ) {
377 $merged[$name][
'options'] += $options[
'options'];
380 $merged[$name][
'options'] = $options[
'options'];
385 $merged[$name][
'optional'] = $merged[$name][
'optional'] && $options[
'optional'];
386 $merged[$name][
'sensitive'] = $merged[$name][
'sensitive'] || $options[
'sensitive'];
405 foreach ( $data as $k => $v ) {
The Message class deals with fetching and processing of interface message into a variety of formats.