array-tools.php
27 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Classes\Arrayable; |
| 5 | |
| 6 | class Array_Tools { |
| 7 | |
| 8 | public static function to_array( array $payload ): array { |
| 9 | foreach ( $payload as $index => $object ) { |
| 10 | if ( is_array( $object ) ) { |
| 11 | continue; |
| 12 | } |
| 13 | |
| 14 | /** @var Arrayable $object */ |
| 15 | if ( is_object( $object ) && ! ( $object instanceof Arrayable ) ) { |
| 16 | wp_die( 'Must implements Arrayable.', 'Illegal item of array' ); |
| 17 | } |
| 18 | |
| 19 | $payload[] = $object->to_array(); |
| 20 | unset( $payload[ $index ] ); |
| 21 | } |
| 22 | |
| 23 | return $payload; |
| 24 | } |
| 25 | |
| 26 | } |
| 27 |