95 return get_called_class();
167 $fields = array_filter( $this->
getFieldInfo(),
static function ( $info ) {
168 return $info[
'type'] !==
'null';
174 foreach ( $fields as $field => $info ) {
179 if ( $info[
'type'] ===
'checkbox' || $info[
'type'] ===
'button' ) {
180 $this->$field = isset( $data[$field] ) && $data[$field] !==
false
181 || isset( $data[
"{$field}_x"] ) && $data[
"{$field}_x"] !==
false;
182 if ( !$this->$field && empty( $info[
'optional'] ) ) {
189 if ( !isset( $data[$field] ) && $info[
'type'] ===
'multiselect' ) {
193 if ( !isset( $data[$field] ) ) {
196 if ( $data[$field] ===
'' || $data[$field] === [] ) {
197 if ( empty( $info[
'optional'] ) ) {
201 switch ( $info[
'type'] ) {
203 if ( !isset( $info[
'options'][$data[$field]] ) ) {
209 $data[$field] = (array)$data[$field];
211 $allowed = array_keys( $info[
'options'] );
212 if ( array_diff( $data[$field], $allowed ) !== [] ) {
219 $this->$field = $data[$field];
245 'provider' => new \RawMessage(
'$1', [ get_called_class() ] ),
246 'account' => new \RawMessage(
'$1', [ $this->
getUniqueId() ] ),
259 foreach ( $reqs as $req ) {
260 if ( $req->loadFromSubmission( $data ) ) {
281 $requests = array_filter( $reqs,
static function ( $req ) use ( $class, $allowSubclasses ) {
282 if ( $allowSubclasses ) {
283 return is_a( $req, $class,
false );
285 return get_class( $req ) === $class;
289 return count( $requests ) === 1 ? reset( $requests ) :
null;
304 foreach ( $reqs as $req ) {
305 $info = $req->getFieldInfo();
306 if ( $info && array_key_exists(
'username', $info ) && $req->username !==
null ) {
309 $otherClass = get_class( $req );
310 } elseif (
$username !== $req->username ) {
311 $requestClass = get_class( $req );
312 throw new \UnexpectedValueException(
"Conflicting username fields: \"{$req->username}\" from "
314 .
"$requestClass::\$username vs. \"$username\" from $otherClass::\$username" );
331 $sharedRequiredPrimaryFields =
null;
332 foreach ( $reqs as $req ) {
333 if ( $req->required !== self::PRIMARY_REQUIRED ) {
337 foreach ( $req->getFieldInfo() as $fieldName => $options ) {
338 if ( empty( $options[
'optional'] ) ) {
342 if ( $sharedRequiredPrimaryFields ===
null ) {
343 $sharedRequiredPrimaryFields =
$required;
345 $sharedRequiredPrimaryFields = array_intersect( $sharedRequiredPrimaryFields,
$required );
349 foreach ( $reqs as $req ) {
350 $info = $req->getFieldInfo();
355 foreach ( $info as $name => $options ) {
358 $req->required === self::OPTIONAL
361 || $req->required === self::PRIMARY_REQUIRED
363 && !in_array( $name, $sharedRequiredPrimaryFields,
true )
365 $options[
'optional'] =
true;
367 $options[
'optional'] = !empty( $options[
'optional'] );
370 $options[
'sensitive'] = !empty( $options[
'sensitive'] );
371 $type = $options[
'type'];
373 if ( !array_key_exists( $name, $merged ) ) {
374 $merged[$name] = $options;
375 } elseif ( $merged[$name][
'type'] !==
$type ) {
376 throw new \UnexpectedValueException(
"Field type conflict for \"$name\", " .
377 "\"{$merged[$name]['type']}\" vs \"$type\""
380 if ( isset( $options[
'options'] ) ) {
381 if ( isset( $merged[$name][
'options'] ) ) {
382 $merged[$name][
'options'] += $options[
'options'];
385 $merged[$name][
'options'] = $options[
'options'];
390 $merged[$name][
'optional'] = $merged[$name][
'optional'] && $options[
'optional'];
391 $merged[$name][
'sensitive'] = $merged[$name][
'sensitive'] || $options[
'sensitive'];
410 foreach ( $data as $k => $v ) {
The Message class deals with fetching and processing of interface message into a variety of formats.