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