91 return get_called_class();
160 $fields = array_filter( $this->
getFieldInfo(),
static function ( $info ) {
161 return $info[
'type'] !==
'null';
167 foreach ( $fields as $field => $info ) {
172 if ( $info[
'type'] ===
'checkbox' || $info[
'type'] ===
'button' ) {
173 $this->$field = isset( $data[$field] ) && $data[$field] !==
false
174 || isset( $data[
"{$field}_x"] ) && $data[
"{$field}_x"] !==
false;
175 if ( !$this->$field && empty( $info[
'optional'] ) ) {
182 if ( !isset( $data[$field] ) && $info[
'type'] ===
'multiselect' ) {
186 if ( !isset( $data[$field] ) ) {
189 if ( $data[$field] ===
'' || $data[$field] === [] ) {
190 if ( empty( $info[
'optional'] ) ) {
194 switch ( $info[
'type'] ) {
196 if ( !isset( $info[
'options'][$data[$field]] ) ) {
202 $data[$field] = (array)$data[$field];
203 $allowed = array_keys( $info[
'options'] );
204 if ( array_diff( $data[$field], $allowed ) !== [] ) {
211 $this->$field = $data[$field];
237 'provider' => new \RawMessage(
'$1', [ get_called_class() ] ),
238 'account' => new \RawMessage(
'$1', [ $this->
getUniqueId() ] ),
251 foreach ( $reqs as $req ) {
252 if ( $req->loadFromSubmission( $data ) ) {
273 $requests = array_filter( $reqs,
static function ( $req ) use ( $class, $allowSubclasses ) {
274 if ( $allowSubclasses ) {
275 return is_a( $req, $class,
false );
277 return get_class( $req ) === $class;
280 return count( $requests ) === 1 ? reset( $requests ) :
null;
295 foreach ( $reqs as $req ) {
296 $info = $req->getFieldInfo();
297 if ( $info && array_key_exists(
'username', $info ) && $req->username !==
null ) {
300 $otherClass = get_class( $req );
301 } elseif (
$username !== $req->username ) {
302 $requestClass = get_class( $req );
303 throw new \UnexpectedValueException(
"Conflicting username fields: \"{$req->username}\" from "
304 .
"$requestClass::\$username vs. \"$username\" from $otherClass::\$username" );
321 $sharedRequiredPrimaryFields =
null;
322 foreach ( $reqs as $req ) {
323 if ( $req->required !== self::PRIMARY_REQUIRED ) {
327 foreach ( $req->getFieldInfo() as $fieldName => $options ) {
328 if ( empty( $options[
'optional'] ) ) {
332 if ( $sharedRequiredPrimaryFields ===
null ) {
333 $sharedRequiredPrimaryFields =
$required;
335 $sharedRequiredPrimaryFields = array_intersect( $sharedRequiredPrimaryFields,
$required );
339 foreach ( $reqs as $req ) {
340 $info = $req->getFieldInfo();
345 foreach ( $info as $name => $options ) {
348 $req->required === self::OPTIONAL
351 || $req->required === self::PRIMARY_REQUIRED
352 && !in_array( $name, $sharedRequiredPrimaryFields,
true )
354 $options[
'optional'] =
true;
356 $options[
'optional'] = !empty( $options[
'optional'] );
359 $options[
'sensitive'] = !empty( $options[
'sensitive'] );
360 $type = $options[
'type'];
362 if ( !array_key_exists( $name, $merged ) ) {
363 $merged[$name] = $options;
364 } elseif ( $merged[$name][
'type'] !==
$type ) {
365 throw new \UnexpectedValueException(
"Field type conflict for \"$name\", " .
366 "\"{$merged[$name]['type']}\" vs \"$type\""
369 if ( isset( $options[
'options'] ) ) {
370 if ( isset( $merged[$name][
'options'] ) ) {
371 $merged[$name][
'options'] += $options[
'options'];
374 $merged[$name][
'options'] = $options[
'options'];
379 $merged[$name][
'optional'] = $merged[$name][
'optional'] && $options[
'optional'];
380 $merged[$name][
'sensitive'] = $merged[$name][
'sensitive'] || $options[
'sensitive'];
399 foreach ( $data as $k => $v ) {
The Message class deals with fetching and processing of interface message into a variety of formats.