PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.4.1
Fluent Support – Helpdesk & Customer Support Ticket System v1.4.1
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / vendor / wpfluent / framework / src / WPFluent / Foundation / RequestGuard.php

RequestGuard.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.4.1, at vendor/wpfluent/framework/src/WPFluent/Foundation/RequestGuard.php

61 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\Framework\Foundation;
4
5 use FluentSupport\Framework\Foundation\App;
6 use FluentSupport\Framework\Validator\Validator;
7 use FluentSupport\Framework\Validator\ValidationException;
8
9 abstract class RequestGuard
10 {
11 public function rules()
12 {
13 return [];
14 }
15
16 public function messages()
17 {
18 return [];
19 }
20
21 public function validate(Validator $validator)
22 {
23 try {
24 $rules = (array) $this->rules();
25
26 if (!$rules) return;
27
28 $validator = $validator->make($this->all(), $rules, (array) $this->messages());
29
30 if ($validator->validate()->fails()) {
31 throw new ValidationException('Unprocessable Entity!', 422, null, $validator->errors());
32 }
33 } catch (ValidationException $e) {
34
35 if (defined('REST_REQUEST') && REST_REQUEST) {
36 throw $e;
37 } else {
38 App::getInstance()->doCustomAction('handle_exception', $e);
39 }
40 }
41 }
42
43 /**
44 * Get an input element from the request.
45 *
46 * @param string $key
47 * @return mixed
48 */
49 public function __get($key)
50 {
51 return $this->get($key);
52 }
53
54 public function __call($method, $params)
55 {
56 return call_user_func_array(
57 [App::getInstance('request'), $method], $params
58 );
59 }
60 }
61