91 return get_called_class();
160 $fields = array_filter( $this->
getFieldInfo(),
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 ) ) {
275 $requests = array_filter( $reqs,
function ( $req ) use ( $class, $allowSubclasses ) {
276 if ( $allowSubclasses ) {
277 return is_a( $req, $class,
false );
279 return get_class( $req ) === $class;
282 return count( $requests ) === 1 ? reset( $requests ) :
null;
297 foreach ( $reqs as $req ) {
298 $info = $req->getFieldInfo();
299 if ( $info && array_key_exists(
'username', $info ) && $req->username !==
null ) {
302 $otherClass = get_class( $req );
303 } elseif (
$username !== $req->username ) {
304 $requestClass = get_class( $req );
305 throw new \UnexpectedValueException(
"Conflicting username fields: \"{$req->username}\" from "
306 .
"$requestClass::\$username vs. \"$username\" from $otherClass::\$username" );
323 $sharedRequiredPrimaryFields =
null;
324 foreach ( $reqs as $req ) {
325 if ( $req->required !== self::PRIMARY_REQUIRED ) {
329 foreach ( $req->getFieldInfo() as $fieldName => $options ) {
330 if ( empty( $options[
'optional'] ) ) {
334 if ( $sharedRequiredPrimaryFields ===
null ) {
335 $sharedRequiredPrimaryFields =
$required;
337 $sharedRequiredPrimaryFields = array_intersect( $sharedRequiredPrimaryFields,
$required );
341 foreach ( $reqs as $req ) {
342 $info = $req->getFieldInfo();
347 foreach ( $info as $name => $options ) {
350 $req->required === self::OPTIONAL
353 || $req->required === self::PRIMARY_REQUIRED
354 && !in_array( $name, $sharedRequiredPrimaryFields,
true )
356 $options[
'optional'] =
true;
358 $options[
'optional'] = !empty( $options[
'optional'] );
361 $options[
'sensitive'] = !empty( $options[
'sensitive'] );
362 $type = $options[
'type'];
364 if ( !array_key_exists( $name, $merged ) ) {
365 $merged[$name] = $options;
366 } elseif ( $merged[$name][
'type'] !==
$type ) {
367 throw new \UnexpectedValueException(
"Field type conflict for \"$name\", " .
368 "\"{$merged[$name]['type']}\" vs \"$type\""
371 if ( isset( $options[
'options'] ) ) {
372 if ( isset( $merged[$name][
'options'] ) ) {
373 $merged[$name][
'options'] += $options[
'options'];
376 $merged[$name][
'options'] = $options[
'options'];
381 $merged[$name][
'optional'] = $merged[$name][
'optional'] && $options[
'optional'];
382 $merged[$name][
'sensitive'] = $merged[$name][
'sensitive'] || $options[
'sensitive'];
401 foreach ( $data as $k => $v ) {
The Message class deals with fetching and processing of interface message into a variety of formats.