| 1 |
<?php |
| 2 |
/** |
| 3 |
* Collection writer lifecycle contract. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS\Interfaces |
| 6 |
*/ |
| 7 |
|
| 8 |
// phpcs:disable Squiz.Commenting, Generic.Commenting -- Lifecycle docblocks are intentionally concise. |
| 9 |
|
| 10 |
namespace WCPOS\WooCommercePOS\Interfaces; |
| 11 |
|
| 12 |
/** |
| 13 |
* Adapts collection behavior around the controller-owned mutation protocol. |
| 14 |
* |
| 15 |
* @internal Not a public extension point. Unlike the other contracts in this |
| 16 |
* namespace, this shape is provisional: six of its methods still take a |
| 17 |
* `callable` for the controller's default implementation, and the intended |
| 18 |
* follow-up is to push those defaults into Null_Writer and let the other |
| 19 |
* writers extend it. Third-party code must not implement this interface — |
| 20 |
* narrowing it later would otherwise be a breaking change on a released line. |
| 21 |
*/ |
| 22 |
interface Collection_Writer_Interface { |
| 23 |
/** |
| 24 |
* Prepare a create payload and route. |
| 25 |
* |
| 26 |
* @return array|object Prepared write with method, route, payload, context, and optional context_factory keys; or validation error. |
| 27 |
*/ |
| 28 |
public function prepare_create( array $meta, array $payload, callable $validate_tax_ids ); |
| 29 |
|
| 30 |
/** |
| 31 |
* Prepare an update payload and route. |
| 32 |
* |
| 33 |
* @return array|object Prepared write with method, route, payload, context, and optional context_factory keys; or validation error. |
| 34 |
*/ |
| 35 |
public function prepare_update( array $meta, int $id, array $payload, callable $validate_tax_ids ); |
| 36 |
|
| 37 |
/** Validate and repair an already-existing create target. */ |
| 38 |
public function validate_existing_create( int $id, array $payload, array $prepared ); |
| 39 |
|
| 40 |
/** Forward a prepared write within collection hooks. */ |
| 41 |
public function forward( array $prepared, callable $forward ); |
| 42 |
|
| 43 |
/** Persist collection data at a named create/update lifecycle phase. */ |
| 44 |
public function persist( string $phase, int $id, array $payload, array $current = array(), array $response_data = array(), array $context = array() ): void; |
| 45 |
|
| 46 |
/** Execute the collection-specific delete forward. */ |
| 47 |
public function delete( array $meta, int $id, array $mutation, callable $dispatch, callable $can_delete ); |
| 48 |
|
| 49 |
/** Read the collection's authoritative response document. */ |
| 50 |
public function document( array $meta, int $id, callable $default_document ); |
| 51 |
|
| 52 |
/** Shape a bare document for the mutation response. */ |
| 53 |
public function build_response_document( array $bare, string $record_id, array $meta, int $id, callable $default_builder ): array; |
| 54 |
} |
| 55 |
|