PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / src / dooraccess / device / capability.php

capability.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/src/dooraccess/device/capability.php

135 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2025 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Door Access device capability. Such objects are
16 * serialized and stored onto the database as blobs.
17 *
18 * @since 1.18.4 (J) - 1.8.4 (WP)
19 */
20 final class VBODooraccessDeviceCapability
21 {
22 /**
23 * @var ?string
24 */
25 protected ?string $id = null;
26
27 /**
28 * @var ?string
29 */
30 protected ?string $title = null;
31
32 /**
33 * @var ?string
34 */
35 protected ?string $description = null;
36
37 /**
38 * @var ?string
39 */
40 protected ?string $icon = null;
41
42 /**
43 * @var ?array
44 */
45 protected ?array $params = null;
46
47 /**
48 * @var ?string
49 */
50 protected ?string $callback = null;
51
52 /**
53 * Class constructor.
54 */
55 public function __construct()
56 {}
57
58 /**
59 * Magic method to get or set protected properties.
60 *
61 * @param string $name The method name called.
62 * @param array $arguments The arguments of the method called.
63 *
64 * @return mixed
65 *
66 * @throws Exception
67 */
68 public function __call(string $name, array $arguments)
69 {
70 if (preg_match('/^get([a-z]+)/i', $name, $matches)) {
71 // getter method invoked
72 $property = strtolower($matches[1]);
73
74 // access the requested property, if set
75 return $this->{$property} ?? null;
76 }
77
78 if (preg_match('/^set([a-z]+)/i', $name, $matches) && $arguments) {
79 // setter method invoked
80 $property = strtolower($matches[1]);
81
82 if (property_exists($this, $property)) {
83 // set the value for the requested property
84 $this->{$property} = $arguments[0];
85 }
86
87 // return self for chain-ability
88 return $this;
89 }
90
91 throw new Exception(sprintf('Could not call device capability method %s.', $name), 500);
92 }
93
94 /**
95 * Tells if the device capability provides parameters for its execution.
96 *
97 * @return bool
98 */
99 public function providesParams()
100 {
101 return !empty($this->params);
102 }
103
104 /**
105 * Tells if the device capability meets the minimum requirements.
106 *
107 * @return bool
108 */
109 public function isValid()
110 {
111 return !empty($this->id) && !empty($this->title) && !empty($this->callback);
112 }
113
114 /**
115 * Executes the capability through the callback instructions, if set.
116 *
117 * @param VBODooraccessIntegrationAware $integration The provider integration object.
118 * @param VBODooraccessIntegrationDevice $device The device executing the capability.
119 * @param ?array $options Optional settings obtained from the params.
120 *
121 * @return ?string Optional execution result string to display.
122 *
123 * @throws Exception
124 */
125 public function execute(VBODooraccessIntegrationAware $integration, VBODooraccessIntegrationDevice $device, ?array $options = null)
126 {
127 if (!is_string($this->callback) || !is_callable([$integration, $this->callback])) {
128 throw new Exception('Could not execute device capability.', 500);
129 }
130
131 // execute the capability on the provider integration object
132 return call_user_func_array([$integration, $this->callback], [$device, $options]);
133 }
134 }
135