| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Collects the data from the added collection objects. |
| 10 |
*/ |
| 11 |
class WPSEO_Collector { |
| 12 |
|
| 13 |
/** |
| 14 |
* Holds the collections. |
| 15 |
* |
| 16 |
* @var WPSEO_Collection[] |
| 17 |
*/ |
| 18 |
protected $collections = []; |
| 19 |
|
| 20 |
/** |
| 21 |
* Adds a collection object to the collections. |
| 22 |
* |
| 23 |
* @param WPSEO_Collection $collection The collection object to add. |
| 24 |
* |
| 25 |
* @return void |
| 26 |
*/ |
| 27 |
public function add_collection( WPSEO_Collection $collection ) { |
| 28 |
$this->collections[] = $collection; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Collects the data from the collection objects. |
| 33 |
* |
| 34 |
* @return array The collected data. |
| 35 |
*/ |
| 36 |
public function collect() { |
| 37 |
$data = []; |
| 38 |
|
| 39 |
foreach ( $this->collections as $collection ) { |
| 40 |
$data = array_merge( $data, $collection->get() ); |
| 41 |
} |
| 42 |
|
| 43 |
return $data; |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Returns the collected data as a JSON encoded string. |
| 48 |
* |
| 49 |
* @return string|false The encode string. |
| 50 |
*/ |
| 51 |
public function get_as_json() { |
| 52 |
return WPSEO_Utils::format_json_encode( $this->collect() ); |
| 53 |
} |
| 54 |
} |
| 55 |
|