PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.10.3
Fluent Support – Helpdesk & Customer Support Ticket System v1.10.3
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.10.3, at vendor/wpfluent/framework/src/WPFluent/Foundation/RequestGuard.php

115 lines 2.5 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 /**
12 * Retrive the validation rules
13 * @return array
14 */
15 public function rules()
16 {
17 return [];
18 }
19
20 /**
21 * Retrive the validation messages set by the developer
22 * @return array
23 */
24 public function messages()
25 {
26 return [];
27 }
28
29 /**
30 * Allow the developer tinker with data before the validation.
31 * @return array
32 */
33 public function beforeValidation()
34 {
35 return [];
36 }
37
38 /**
39 * Allow the developer tinker with data after the validation.
40 * @return array
41 */
42 public function afterValidation()
43 {
44 return [];
45 }
46
47 /**
48 * Validate the request.
49 *
50 * @param array $rules Optional
51 * @param array $messages Optional
52 * @return array Request Data
53 * @throws FluentSupport\Framework\Validator\ValidationException
54 */
55 public function validate($rules = [], $messages = [])
56 {
57 try {
58 return App::make('request')->validate(
59 $rules ?: (array) $this->rules(),
60 $messages ?: (array) $this->messages()
61 );
62 } catch (ValidationException $e) {
63
64 if (defined('REST_REQUEST') && REST_REQUEST) {
65 throw $e;
66 } else {
67 App::getInstance()->doCustomAction('handle_exception', $e);
68 }
69 }
70 }
71
72 /**
73 * Handles validation including before and after calls
74 *
75 * @throws FluentSupport\Framework\Validator\ValidationException
76 * @return null
77 */
78 public static function applyValidation()
79 {
80 $instance = new static;
81
82 $request = App::getInstance('request');
83
84 $request->merge($instance->beforeValidation());
85
86 $instance->validate();
87
88 $request->merge($instance->afterValidation());
89 }
90
91 /**
92 * Get an input element from the request.
93 *
94 * @param string $key
95 * @return mixed
96 */
97 public function __get($key)
98 {
99 return $this->get($key);
100 }
101
102 /**
103 * Handle the dynamic method calls
104 * @param string $method
105 * @param array $params
106 * @return mixed
107 */
108 public function __call($method, $params)
109 {
110 return call_user_func_array(
111 [App::make('request'), $method], $params
112 );
113 }
114 }
115