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