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