ArrayColumn.php
1 year ago
ArrayFlatten.php
1 year ago
ArrayKeys.php
1 year ago
ArraySearch.php
1 year ago
ArrayValues.php
1 year ago
Count.php
1 year ago
DotNotation.php
1 year ago
PrepareUrl.php
1 year ago
TransformerInterface.php
1 year ago
TransformerService.php
1 year ago
ArrayFlatten.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers; |
| 4 | |
| 5 | use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface; |
| 6 | use stdClass; |
| 7 | |
| 8 | /** |
| 9 | * Flatten nested array. |
| 10 | * |
| 11 | * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers |
| 12 | */ |
| 13 | class ArrayFlatten implements TransformerInterface { |
| 14 | /** |
| 15 | * Search a given value in the array. |
| 16 | * |
| 17 | * @param mixed $value a value to transform. |
| 18 | * @param stdClass|null $arguments arguments. |
| 19 | * @param string|null $default_value default value. |
| 20 | * |
| 21 | * @return mixed|null |
| 22 | */ |
| 23 | public function transform( $value, ?stdClass $arguments = null, $default_value = array() ) { |
| 24 | if ( ! is_array( $value ) ) { |
| 25 | return $default_value; |
| 26 | } |
| 27 | |
| 28 | $return = array(); |
| 29 | array_walk_recursive( |
| 30 | $value, |
| 31 | function ( $item ) use ( &$return ) { |
| 32 | $return[] = $item; |
| 33 | } |
| 34 | ); |
| 35 | |
| 36 | return $return; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Validate Transformer arguments. |
| 41 | * |
| 42 | * @param stdClass|null $arguments arguments to validate. |
| 43 | * |
| 44 | * @return mixed |
| 45 | */ |
| 46 | public function validate( ?stdClass $arguments = null ) { |
| 47 | return true; |
| 48 | } |
| 49 | } |
| 50 |