| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 4 |
|
| 5 |
namespace Yoast\WP\SEO\AI\Generator\Domain; |
| 6 |
|
| 7 |
use WP_User; |
| 8 |
|
| 9 |
/** |
| 10 |
* Parameters for a usage request. |
| 11 |
*/ |
| 12 |
class Usage_Parameters { |
| 13 |
|
| 14 |
/** |
| 15 |
* The user the request is on behalf of. |
| 16 |
* |
| 17 |
* @var WP_User |
| 18 |
*/ |
| 19 |
private $user; |
| 20 |
|
| 21 |
/** |
| 22 |
* Whether usage should be read from the time-unbound free-usage bucket rather than a period. |
| 23 |
* |
| 24 |
* @var bool |
| 25 |
*/ |
| 26 |
private $is_free; |
| 27 |
|
| 28 |
/** |
| 29 |
* The usage period (e.g. `2026-06`) the request applies to when it is not a free-usage request. |
| 30 |
* |
| 31 |
* @var string |
| 32 |
*/ |
| 33 |
private $period; |
| 34 |
|
| 35 |
/** |
| 36 |
* The constructor. |
| 37 |
* |
| 38 |
* @param WP_User $user The user. |
| 39 |
* @param bool $is_free Whether to read the free-usage bucket instead of a period. |
| 40 |
* @param string $period The usage period (e.g. `2026-06`); ignored for free-usage requests. |
| 41 |
*/ |
| 42 |
public function __construct( WP_User $user, bool $is_free, string $period ) { |
| 43 |
$this->user = $user; |
| 44 |
$this->is_free = $is_free; |
| 45 |
$this->period = $period; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Returns the user. |
| 50 |
* |
| 51 |
* @return WP_User The user. |
| 52 |
*/ |
| 53 |
public function get_user(): WP_User { |
| 54 |
return $this->user; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Returns whether usage should be read from the free-usage bucket. |
| 59 |
* |
| 60 |
* @return bool True when the request targets the free-usage bucket. |
| 61 |
*/ |
| 62 |
public function is_free(): bool { |
| 63 |
return $this->is_free; |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Returns the usage period the request applies to. |
| 68 |
* |
| 69 |
* @return string The usage period (e.g. `2026-06`). |
| 70 |
*/ |
| 71 |
public function get_period(): string { |
| 72 |
return $this->period; |
| 73 |
} |
| 74 |
} |
| 75 |
|