| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
namespace Yoast\WP\SEO\Dashboard\Domain\Taxonomies; |
| 5 |
|
| 6 |
/** |
| 7 |
* This class describes a Taxonomy. |
| 8 |
*/ |
| 9 |
class Taxonomy { |
| 10 |
|
| 11 |
/** |
| 12 |
* The name of the taxonomy. |
| 13 |
* |
| 14 |
* @var string |
| 15 |
*/ |
| 16 |
private $name; |
| 17 |
|
| 18 |
/** |
| 19 |
* The label of the taxonomy. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
private $label; |
| 24 |
|
| 25 |
/** |
| 26 |
* The REST URL of the taxonomy. |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
private $rest_url; |
| 31 |
|
| 32 |
/** |
| 33 |
* The constructor. |
| 34 |
* |
| 35 |
* @param string $name The name of the taxonomy. |
| 36 |
* @param string $label The label of the taxonomy. |
| 37 |
* @param string $rest_url The REST URL of the taxonomy. |
| 38 |
*/ |
| 39 |
public function __construct( |
| 40 |
string $name, |
| 41 |
string $label, |
| 42 |
string $rest_url |
| 43 |
) { |
| 44 |
$this->name = $name; |
| 45 |
$this->label = $label; |
| 46 |
$this->rest_url = $rest_url; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns the name of the taxonomy. |
| 51 |
* |
| 52 |
* @return string The name of the taxonomy. |
| 53 |
*/ |
| 54 |
public function get_name(): string { |
| 55 |
return $this->name; |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Parses the taxonomy to the expected key value representation. |
| 60 |
* |
| 61 |
* @return array<string, array<string, string>> The taxonomy presented as the expected key value representation. |
| 62 |
*/ |
| 63 |
public function to_array(): array { |
| 64 |
return [ |
| 65 |
'name' => $this->name, |
| 66 |
'label' => $this->label, |
| 67 |
'links' => [ |
| 68 |
'search' => $this->rest_url, |
| 69 |
], |
| 70 |
]; |
| 71 |
} |
| 72 |
} |
| 73 |
|