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