89 return get_called_class();
156 $fields = array_filter( $this->
getFieldInfo(),
function ( $info ) {
157 return $info[
'type'] !==
'null';
163 foreach ( $fields as $field => $info ) {
168 if ( $info[
'type'] ===
'checkbox' || $info[
'type'] ===
'button' ) {
169 $this->$field = isset( $data[$field] ) && $data[$field] !==
false
170 || isset( $data[
"{$field}_x"] ) && $data[
"{$field}_x"] !==
false;
171 if ( !$this->$field && empty( $info[
'optional'] ) ) {
178 if ( !isset( $data[$field] ) && $info[
'type'] ===
'multiselect' ) {
182 if ( !isset( $data[$field] ) ) {
185 if ( $data[$field] ===
'' || $data[$field] === [] ) {
186 if ( empty( $info[
'optional'] ) ) {
190 switch ( $info[
'type'] ) {
192 if ( !isset( $info[
'options'][$data[$field]] ) ) {
198 $data[$field] = (array)$data[$field];
199 $allowed = array_keys( $info[
'options'] );
200 if ( array_diff( $data[$field], $allowed ) !== [] ) {
207 $this->$field = $data[$field];
231 'provider' => new \RawMessage(
'$1', [ get_called_class() ] ),
232 'account' => new \RawMessage(
'$1', [ $this->
getUniqueId() ] ),
243 return array_values( array_filter( $reqs,
function ( $req ) use ( $data ) {
244 return $req->loadFromSubmission( $data );
264 $requests = array_filter( $reqs,
function ( $req ) use ( $class, $allowSubclasses ) {
265 if ( $allowSubclasses ) {
266 return is_a( $req, $class,
false );
268 return get_class( $req ) === $class;
271 return count( $requests ) === 1 ? reset( $requests ) :
null;
286 foreach ( $reqs as $req ) {
287 $info = $req->getFieldInfo();
288 if ( $info && array_key_exists(
'username', $info ) && $req->username !==
null ) {
291 $otherClass = get_class( $req );
292 } elseif (
$username !== $req->username ) {
293 $requestClass = get_class( $req );
294 throw new \UnexpectedValueException(
"Conflicting username fields: \"{$req->username}\" from "
295 .
"$requestClass::\$username vs. \"$username\" from $otherClass::\$username" );
313 $primaryRequests = array_filter( $reqs,
function ( $req ) {
316 $sharedRequiredPrimaryFields = array_reduce( $primaryRequests,
function ( $shared, $req ) {
317 $required = array_keys( array_filter( $req->getFieldInfo(),
function ( $options ) {
318 return empty( $options[
'optional'] );
320 if ( $shared ===
null ) {
323 return array_intersect( $shared,
$required );
327 foreach ( $reqs as $req ) {
328 $info = $req->getFieldInfo();
333 foreach ( $info as $name => $options ) {
336 $req->required === self::OPTIONAL
339 || $req->required === self::PRIMARY_REQUIRED
340 && !in_array( $name, $sharedRequiredPrimaryFields,
true )
342 $options[
'optional'] =
true;
344 $options[
'optional'] = !empty( $options[
'optional'] );
347 $options[
'sensitive'] = !empty( $options[
'sensitive'] );
348 $type = $options[
'type'];
350 if ( !array_key_exists( $name, $merged ) ) {
351 $merged[$name] = $options;
352 } elseif ( $merged[$name][
'type'] !==
$type ) {
353 throw new \UnexpectedValueException(
"Field type conflict for \"$name\", " .
354 "\"{$merged[$name]['type']}\" vs \"$type\""
357 if ( isset( $options[
'options'] ) ) {
358 if ( isset( $merged[$name][
'options'] ) ) {
359 $merged[$name][
'options'] += $options[
'options'];
362 $merged[$name][
'options'] = $options[
'options'];
367 $merged[$name][
'optional'] = $merged[$name][
'optional'] && $options[
'optional'];
368 $merged[$name][
'sensitive'] = $merged[$name][
'sensitive'] || $options[
'sensitive'];
387 foreach ( $data as $k => $v ) {