PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / Command.php
ameliabooking / src / Application / Commands Last commit date
Bookable 6 months ago Booking 5 months ago Calendar 6 months ago Entities 6 months ago Import 6 months ago Notification 6 months ago Payment 6 months ago QrCode 6 months ago Settings 6 months ago Square 6 months ago Stash 6 months ago Stats 6 months ago Test 6 months ago User 5 months ago WhatsNew 6 months ago Command.php 6 months ago CommandHandler.php 7 years ago CommandResult.php 1 year ago
Command.php
245 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands;
4
5 use AmeliaBooking\Application\Commands\Booking\Appointment\AddBookingCommand;
6 use AmeliaBooking\Application\Commands\Booking\Appointment\DeleteBookingRemotelyCommand;
7 use AmeliaBooking\Application\Commands\Booking\Appointment\SuccessfulBookingCommand;
8 use AmeliaBooking\Application\Commands\Notification\UpdateSMSNotificationHistoryCommand;
9 use AmeliaBooking\Application\Commands\Payment\CalculatePaymentAmountCommand;
10 use AmeliaBooking\Application\Commands\Square\DisconnectFromSquareAccountCommand;
11 use AmeliaBooking\Application\Commands\Square\SquareRefundWebhookCommand;
12 use AmeliaBooking\Application\Services\User\UserApplicationService;
13 use AmeliaBooking\Domain\Services\Permissions\PermissionsService;
14 use AmeliaBooking\Domain\Services\Settings\SettingsService;
15 use AmeliaBooking\Infrastructure\WP\SettingsService\SettingsStorage;
16 use Slim\Http\Request;
17
18 /**
19 * Class Command
20 *
21 * @package AmeliaBooking\Application\Commands
22 */
23 abstract class Command
24 {
25 protected $args;
26
27 protected $container;
28
29 private $fields = [];
30
31 public $token;
32
33 private $page;
34
35 private $cabinetType;
36
37 private $permissionService;
38
39 private $userApplicationService;
40
41 /**
42 * Command constructor.
43 *
44 * @param $args
45 */
46 public function __construct($args)
47 {
48 $this->args = $args;
49 if (isset($args['type'])) {
50 $this->setField('type', $args['type']);
51 }
52 }
53
54 /**
55 * @return mixed
56 */
57 public function getArgs()
58 {
59 return $this->args;
60 }
61
62 /**
63 * @param mixed $arg Argument to be fetched
64 *
65 * @return null|mixed
66 */
67 public function getArg($arg)
68 {
69 return isset($this->args[$arg]) ? $this->args[$arg] : null;
70 }
71
72 /**
73 * @param $fieldName
74 * @param $fieldValue
75 */
76 public function setField($fieldName, $fieldValue)
77 {
78 $this->fields[$fieldName] = $fieldValue;
79 }
80
81 /**
82 * @param $fieldName
83 */
84 public function removeField($fieldName)
85 {
86 unset($this->fields[$fieldName]);
87 }
88
89 /**
90 * Return a single field
91 *
92 * @param $fieldName
93 *
94 * @return mixed|null
95 */
96 public function getField($fieldName)
97 {
98 return isset($this->fields[$fieldName]) ? $this->fields[$fieldName] : null;
99 }
100
101 /**
102 * Return all fields
103 *
104 * @return array
105 */
106 public function getFields()
107 {
108 return $this->fields;
109 }
110
111 /**
112 * Set Token
113 *
114 * @param Request $request
115 */
116 public function setToken($request)
117 {
118 $headers = $request->getHeaders();
119
120 $token = null;
121
122 /** @var SettingsService $settingsService */
123 $settingsService = new SettingsService(new SettingsStorage());
124
125 if (
126 isset($headers['HTTP_AUTHORIZATION'][0]) &&
127 ($values = explode(' ', $request->getHeaders()['HTTP_AUTHORIZATION'][0])) &&
128 sizeof($values) === 2 &&
129 $settingsService->getSetting('roles', 'enabledHttpAuthorization')
130 ) {
131 $token = $values[1];
132 } elseif (isset($headers['HTTP_COOKIE'][0])) {
133 foreach (explode('; ', $headers['HTTP_COOKIE'][0]) as $cookie) {
134 if (($ameliaTokenCookie = explode('=', $cookie)) && $ameliaTokenCookie[0] === 'ameliaToken') {
135 $token = $ameliaTokenCookie[1];
136 }
137 }
138 }
139
140 $this->token = $token;
141 }
142
143 /**
144 * Return Token
145 *
146 * @return string|null
147 */
148 public function getToken()
149 {
150 return $this->token;
151 }
152
153 /**
154 * Set page
155 *
156 * @param string $page
157 */
158 public function setPage($page)
159 {
160 $this->page = explode('-', $page)[0];
161
162 $this->cabinetType = !empty(explode('-', $page)[1]) ? explode('-', $page)[1] : null;
163 }
164
165 /**
166 * Return page
167 *
168 * @return string|null
169 */
170 public function getPage()
171 {
172 return $this->page;
173 }
174
175 /**
176 * @param $request
177 * @return int|boolean
178 */
179 public function validateNonce($request)
180 {
181 if (
182 $request->getMethod() === 'POST' &&
183 !self::getToken() &&
184 !($this instanceof CalculatePaymentAmountCommand) &&
185 !($this instanceof AddBookingCommand) &&
186 !($this instanceof DeleteBookingRemotelyCommand) &&
187 !($this instanceof SquareRefundWebhookCommand) &&
188 !($this instanceof DisconnectFromSquareAccountCommand) &&
189 !($this instanceof SuccessfulBookingCommand) &&
190 !($this instanceof UpdateSMSNotificationHistoryCommand)
191 ) {
192 $queryParams = $request->getQueryParams();
193
194 return wp_verify_nonce(
195 !empty($queryParams['wpAmeliaNonce']) ? $queryParams['wpAmeliaNonce'] : $queryParams['ameliaNonce'],
196 'ajax-nonce'
197 );
198 }
199
200 return true;
201 }
202
203 /**
204 * Return cabinet type
205 *
206 * @return string|null
207 */
208 public function getCabinetType()
209 {
210 return $this->cabinetType;
211 }
212
213 /**
214 * @return PermissionsService
215 */
216 public function getPermissionService()
217 {
218 return $this->permissionService;
219 }
220
221 /**
222 * @param PermissionsService $permissionService
223 */
224 public function setPermissionService($permissionService)
225 {
226 $this->permissionService = $permissionService;
227 }
228
229 /**
230 * @return UserApplicationService
231 */
232 public function getUserApplicationService()
233 {
234 return $this->userApplicationService;
235 }
236
237 /**
238 * @param UserApplicationService $userApplicationService
239 */
240 public function setUserApplicationService($userApplicationService)
241 {
242 $this->userApplicationService = $userApplicationService;
243 }
244 }
245