| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Introductions\Domain; |
| 4 |
|
| 5 |
/** |
| 6 |
* A collection domain object. |
| 7 |
*/ |
| 8 |
class Introductions_Bucket { |
| 9 |
|
| 10 |
/** |
| 11 |
* Holds the introductions. |
| 12 |
* |
| 13 |
* @var Introduction_Item[] |
| 14 |
*/ |
| 15 |
private $introductions; |
| 16 |
|
| 17 |
/** |
| 18 |
* The constructor. |
| 19 |
*/ |
| 20 |
public function __construct() { |
| 21 |
$this->introductions = []; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Adds an introduction to this bucket. |
| 26 |
* |
| 27 |
* @param Introduction_Item $introduction The introduction. |
| 28 |
* |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
public function add_introduction( Introduction_Item $introduction ) { |
| 32 |
$this->introductions[] = $introduction; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Returns the array representation of the introductions. |
| 37 |
* |
| 38 |
* @return array |
| 39 |
*/ |
| 40 |
public function to_array() { |
| 41 |
// No sorting here because that is done in JS. |
| 42 |
return \array_map( |
| 43 |
static function ( $item ) { |
| 44 |
return $item->to_array(); |
| 45 |
}, |
| 46 |
$this->introductions, |
| 47 |
); |
| 48 |
} |
| 49 |
} |
| 50 |
|