PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 weeks ago Booking 2 weeks ago Calendar 2 weeks ago Entities 2 weeks ago Google 3 months ago Import 3 months ago Mobile 2 weeks ago Notification 2 weeks ago Payment 2 months ago QrCode 3 months ago Settings 2 weeks ago Square 6 months ago Stash 6 months ago Stats 6 months ago Test 6 months ago User 2 days ago WhatsNew 3 months ago Command.php 4 weeks ago CommandHandler.php 7 years ago CommandResult.php 4 months ago SortParamsTrait.php 3 months ago
Command.php
246 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 AmeliaVendor\Psr\Http\Message\ServerRequestInterface as 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 $token = null;
120
121 /** @var SettingsService $settingsService */
122 $settingsService = new SettingsService(new SettingsStorage());
123
124 $authorization = $request->getHeaderLine('Authorization');
125
126 if (
127 $authorization !== '' &&
128 ($values = explode(' ', $authorization)) &&
129 sizeof($values) === 2 &&
130 $settingsService->getSetting('roles', 'enabledHttpAuthorization')
131 ) {
132 $token = $values[1];
133 } else {
134 $cookies = $request->getCookieParams();
135 if (!empty($cookies['ameliaToken'])) {
136 $token = $cookies['ameliaToken'];
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 FetchAccessTokenWithAuthCodeOutlookCommand) &&
191 !($this instanceof UpdateSMSNotificationHistoryCommand)
192 ) {
193 $queryParams = $request->getQueryParams();
194
195 return wp_verify_nonce(
196 !empty($queryParams['wpAmeliaNonce']) ? $queryParams['wpAmeliaNonce'] : $queryParams['ameliaNonce'],
197 'ajax-nonce'
198 );
199 }
200
201 return true;
202 }
203
204 /**
205 * Return cabinet type
206 *
207 * @return string|null
208 */
209 public function getCabinetType()
210 {
211 return $this->cabinetType;
212 }
213
214 /**
215 * @return PermissionsService
216 */
217 public function getPermissionService()
218 {
219 return $this->permissionService;
220 }
221
222 /**
223 * @param PermissionsService $permissionService
224 */
225 public function setPermissionService($permissionService)
226 {
227 $this->permissionService = $permissionService;
228 }
229
230 /**
231 * @return UserApplicationService
232 */
233 public function getUserApplicationService()
234 {
235 return $this->userApplicationService;
236 }
237
238 /**
239 * @param UserApplicationService $userApplicationService
240 */
241 public function setUserApplicationService($userApplicationService)
242 {
243 $this->userApplicationService = $userApplicationService;
244 }
245 }
246