PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.18
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.18
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 1.9.13 All 162 releases
woocommerce-pos / includes / API / V2 / Proxy / Scoped_Proxy_Behavior.php

Scoped_Proxy_Behavior.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.18, at includes/API/V2/Proxy/Scoped_Proxy_Behavior.php

91 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Scoped catalog proxy behavior base.
4 *
5 * @package WCPOS\WooCommercePOS\API\V2\Proxy
6 */
7
8 namespace WCPOS\WooCommercePOS\API\V2\Proxy;
9
10 use WCPOS\WooCommercePOS\Services\Permission_Rules;
11 use WP_REST_Request;
12
13 /**
14 * Gives every resource the same install/run/finally/unwind discipline.
15 */
16 abstract class Scoped_Proxy_Behavior implements Proxy_Behavior {
17 /** Permission collection, when this resource has a POS-tier read grant.
18 *
19 * @var string|null
20 */
21 protected $permission_collection;
22
23 /**
24 * Forward every param untouched.
25 *
26 * @param array $params Query parameters to forward.
27 * @param WP_REST_Request $request Original proxy request.
28 *
29 * @return array
30 */
31 public function forwarded_params( array $params, WP_REST_Request $request ): array {
32 return $params;
33 }
34
35 /**
36 * Install this resource's hooks, run the forward, and always unwind.
37 *
38 * @param callable $forward Forward operation.
39 *
40 * @return mixed
41 */
42 public function around( callable $forward ) {
43 $bindings = $this->install();
44 if ( $this->permission_collection ) {
45 Permission_Rules::install_wc_filter( $this->permission_collection );
46 }
47
48 try {
49 return $this->run( $forward );
50 } finally {
51 if ( $this->permission_collection ) {
52 Permission_Rules::uninstall_wc_filter();
53 }
54 foreach ( array_reverse( $bindings ) as $binding ) {
55 remove_filter( $binding[0], $binding[1], $binding[2] );
56 }
57 }
58 }
59
60 /**
61 * Return the response data unshaped.
62 *
63 * @param mixed $data Response data.
64 *
65 * @return mixed
66 */
67 public function post_process( $data ) {
68 return $data;
69 }
70
71 /**
72 * Install hooks and return their exact removal tuples.
73 *
74 * @return array<int, array{0: string, 1: callable, 2: int}>
75 */
76 protected function install(): array {
77 return array();
78 }
79
80 /**
81 * Run the forward, optionally through a resource plan.
82 *
83 * @param callable $forward Forward operation.
84 *
85 * @return mixed
86 */
87 protected function run( callable $forward ) {
88 return $forward();
89 }
90 }
91