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