PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.2
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.2
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / API / V2 / Writers / Null_Writer.php

Null_Writer.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.2, at includes/API/V2/Writers/Null_Writer.php

74 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Pass-through collection writer.
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 WP_REST_Request;
14
15 /** Provides the unmodified lifecycle used by ordinary wc/v3 collections. */
16 class Null_Writer implements Collection_Writer_Interface {
17 /** Prepare an unchanged create. */
18 public function prepare_create( array $meta, array $payload, callable $validate_tax_ids ) {
19 return array(
20 'method' => 'POST',
21 'route' => $meta['route'],
22 'payload' => $payload,
23 'context' => array(),
24 );
25 }
26
27 /** Prepare an unchanged update. */
28 public function prepare_update( array $meta, int $id, array $payload, callable $validate_tax_ids ) {
29 return array(
30 'method' => 'PUT',
31 'route' => $meta['route'] . '/' . $id,
32 'payload' => $payload,
33 'context' => array(),
34 );
35 }
36
37 /** Accept an existing target unchanged. */
38 public function validate_existing_create( int $id, array $payload, array $prepared ) {
39 return null;
40 }
41
42 /** Forward without collection hooks. */
43 public function forward( array $prepared, callable $forward ) {
44 return $forward( $prepared['method'], $prepared['route'], $prepared['payload'] );
45 }
46
47 /** No-op for pass-through persistence. */
48 public function persist( string $phase, int $id, array $payload, array $current = array(), array $response_data = array(), array $context = array() ): void {
49 }
50
51 /** Permanently delete a generic collection record. */
52 public function delete( array $meta, int $id, array $mutation, callable $dispatch, callable $can_delete ) {
53 return $dispatch( $this->delete_request( $meta['route'] . '/' . $id, $id, true ) );
54 }
55
56 /** Use the shared generic document reader. */
57 public function document( array $meta, int $id, callable $default_document ) {
58 return $default_document( $meta, $id, array() );
59 }
60
61 /** Use the shared generic response builder. */
62 public function build_response_document( array $bare, string $record_id, array $meta, int $id, callable $default_builder ): array {
63 return $default_builder( $bare, $record_id, $meta, $id );
64 }
65
66 /** Build a delete request with authoritative route parameters. */
67 protected function delete_request( string $route, int $id, bool $force ): WP_REST_Request {
68 $request = new WP_REST_Request( 'DELETE', $route );
69 $request->set_param( 'id', $id );
70 $request->set_param( 'force', $force );
71 return $request;
72 }
73 }
74