| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Dashboard\Domain\Data_Provider; |
| 5 |
|
| 6 |
/** |
| 7 |
* The data container. |
| 8 |
*/ |
| 9 |
class Data_Container { |
| 10 |
|
| 11 |
/** |
| 12 |
* All the data points. |
| 13 |
* |
| 14 |
* @var array<Data_Interface> |
| 15 |
*/ |
| 16 |
private $data_container; |
| 17 |
|
| 18 |
/** |
| 19 |
* The constructor |
| 20 |
*/ |
| 21 |
public function __construct() { |
| 22 |
$this->data_container = []; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Method to add data. |
| 27 |
* |
| 28 |
* @param Data_Interface $data The data. |
| 29 |
* |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
public function add_data( Data_Interface $data ) { |
| 33 |
$this->data_container[] = $data; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Method to get all the data points. |
| 38 |
* |
| 39 |
* @return Data_Interface[] All the data points. |
| 40 |
*/ |
| 41 |
public function get_data(): array { |
| 42 |
return $this->data_container; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Converts the data points into an array. |
| 47 |
* |
| 48 |
* @return array<string, string> The array of the data points. |
| 49 |
*/ |
| 50 |
public function to_array(): array { |
| 51 |
$result = []; |
| 52 |
foreach ( $this->data_container as $data ) { |
| 53 |
$result[] = $data->to_array(); |
| 54 |
} |
| 55 |
|
| 56 |
return $result; |
| 57 |
} |
| 58 |
} |
| 59 |
|