| 1 |
<?php |
| 2 |
/** |
| 3 |
* Collection writer resolver. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS\API\V2\Writers |
| 6 |
*/ |
| 7 |
|
| 8 |
// phpcs:disable Squiz.Commenting, Generic.Commenting -- Lifecycle docblocks are intentionally concise. |
| 9 |
|
| 10 |
namespace WCPOS\WooCommercePOS\API\V2\Writers; |
| 11 |
|
| 12 |
use WCPOS\WooCommercePOS\Interfaces\Collection_Writer_Interface; |
| 13 |
use WCPOS\WooCommercePOS\Sync\Mutation_Store; |
| 14 |
use WCPOS\WooCommercePOS\Sync\Order_Write_Payload; |
| 15 |
|
| 16 |
/** Resolves registry metadata to one collection writer. */ |
| 17 |
final class Collection_Writer_Resolver { |
| 18 |
/** @var object Mutation store for order audit persistence. */ |
| 19 |
private $store; |
| 20 |
|
| 21 |
/** Construct the resolver. */ |
| 22 |
public function __construct( ?object $store = null ) { |
| 23 |
$this->store = $store ?? new Mutation_Store(); |
| 24 |
} |
| 25 |
|
| 26 |
/** Resolve with the variation post-type override before the shared post id type. */ |
| 27 |
public function resolve( array $meta ): Collection_Writer_Interface { |
| 28 |
if ( 'product_variation' === ( $meta['post_type'] ?? '' ) ) { |
| 29 |
return new Variation_Writer(); |
| 30 |
} |
| 31 |
switch ( $meta['id_type'] ?? '' ) { |
| 32 |
case 'order': |
| 33 |
return new Order_Writer( $this->store, new Order_Write_Payload() ); |
| 34 |
case 'user': |
| 35 |
return new Customer_Writer(); |
| 36 |
default: |
| 37 |
return new Null_Writer(); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|