| 1 |
<?php |
| 2 |
/** |
| 3 |
* Public Booking Resource data-transfer object. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
* @since 11.6.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Carry public Resource data between repositories and frontend presenters. |
| 15 |
* |
| 16 |
* The object intentionally excludes admin actions, capabilities, owner data, |
| 17 |
* inspector schemas, and storage details. This keeps frontend renderers from |
| 18 |
* becoming coupled to the Booking Resources administration table. |
| 19 |
*/ |
| 20 |
final class WPBC_Booking_Resource_DTO { |
| 21 |
|
| 22 |
/** |
| 23 |
* Normalized public Resource values. |
| 24 |
* |
| 25 |
* @var array<string,mixed> |
| 26 |
*/ |
| 27 |
private $values; |
| 28 |
|
| 29 |
/** |
| 30 |
* Initialize one immutable public Resource snapshot. |
| 31 |
* |
| 32 |
* @param array<string,mixed> $values Normalized public Resource values. |
| 33 |
*/ |
| 34 |
public function __construct( $values ) { |
| 35 |
$defaults = array( |
| 36 |
'resource_id' => 0, |
| 37 |
'title' => '', |
| 38 |
'description' => '', |
| 39 |
'image_url' => '', |
| 40 |
'attachment_id' => 0, |
| 41 |
'parent_id' => 0, |
| 42 |
'parent_title' => '', |
| 43 |
'resource_type' => 'single', |
| 44 |
'child_ids' => array(), |
| 45 |
'child_count' => 0, |
| 46 |
'capacity' => 1, |
| 47 |
'count' => 0, |
| 48 |
'availability_summary' => array(), |
| 49 |
'price_summary' => array(), |
| 50 |
); |
| 51 |
|
| 52 |
$values = is_array( $values ) ? array_intersect_key( $values, $defaults ) : array(); |
| 53 |
$this->values = wp_parse_args( $values, $defaults ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Return the stable public representation used by frontend consumers. |
| 58 |
* |
| 59 |
* @return array<string,mixed> Public Resource values. |
| 60 |
*/ |
| 61 |
public function to_array() { |
| 62 |
return $this->values; |
| 63 |
} |
| 64 |
} |
| 65 |
|