PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.3
JetFormBuilder — Dynamic Blocks Form Builder v3.0.3
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / request / parser-context.php
jetformbuilder / includes / request Last commit date
exceptions 3 years ago fields 3 years ago field-data-parser.php 3 years ago file-uploader.php 3 years ago form-request-router.php 3 years ago parser-context.php 3 years ago parser-manager.php 3 years ago request-handler.php 3 years ago request-router.php 3 years ago request-tools.php 3 years ago
parser-context.php
164 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Request;
5
6 use Jet_Form_Builder\Blocks\Block_Helper;
7 use Jet_Form_Builder\Blocks\Types\Base;
8 use Jet_Form_Builder\Exceptions\Parse_Exception;
9 use Jet_Form_Builder\Exceptions\Repository_Exception;
10
11 class Parser_Context {
12
13 protected $block;
14 protected $settings;
15 protected $name = '';
16 protected $field_type;
17
18 protected $request;
19 protected $files;
20
21 protected $inside_conditional = false;
22
23 protected $context = array();
24
25 /**
26 * @return mixed
27 */
28 public function get_file() {
29 return $this->files[ $this->name ] ?? false;
30 }
31
32 public function get_value() {
33 return $this->request[ $this->name ] ?? '';
34 }
35
36 public function isset_parser(): bool {
37 return Parser_Manager::instance()->isset_parser( $this->field_type );
38 }
39
40 /**
41 * @return Field_Data_Parser
42 * @throws Repository_Exception
43 */
44 public function get_parser(): Field_Data_Parser {
45 return Parser_Manager::instance()->get_parser( $this->field_type );
46 }
47
48 public function save_to_request() {
49 Parser_Manager::instance()->save_to_request( $this->name, $this->field_type, $this->settings );
50 }
51
52 /**
53 * @param array $field
54 *
55 * @return $this
56 * @throws Parse_Exception
57 */
58 public function set_field( array $field ): Parser_Context {
59 $this->validate_field( $field );
60
61 return $this->set_raw_field( $field );
62 }
63
64 public function set_raw_field( array $field ): Parser_Context {
65 $this->block = $field;
66 $this->settings = $field['attrs'];
67 $this->name = $field['attrs']['name'] ?? 'field_name';
68 $this->field_type = Block_Helper::delete_namespace( $field['blockName'] );
69
70 return $this;
71 }
72
73 /**
74 * @param array $field
75 *
76 * @throws Parse_Exception
77 */
78 protected function validate_field( array $field ) {
79 if ( empty( $field['blockName'] ) ) {
80 throw new Parse_Exception( Parser_Manager::EMPTY_BLOCK_ERROR );
81 }
82
83 if ( empty( $field['innerBlocks'] ) ) {
84 return;
85 }
86
87 if ( strpos( $field['blockName'], 'conditional-block' ) ) {
88 throw new Parse_Exception( Parser_Manager::IS_CONDITIONAL, $field['innerBlocks'] );
89 }
90 if ( ! Parser_Manager::instance()->isset_parser( $field['blockName'] ) ) {
91 throw new Parse_Exception( Parser_Manager::NOT_FIELD_HAS_INNER, $field['innerBlocks'] );
92 }
93 }
94
95 public function get_default_value() {
96 /** @var Base $block */
97 $block = jet_form_builder()->blocks->get_field_by_name( $this->field_type );
98
99 // the exception will never be thrown
100 $block->set_block_data( $this->settings );
101 $block->set_context( $this->context );
102 $block->set_preset();
103
104 return $block->block_attrs['default'];
105 }
106
107 public function set_request_context( array $request ): Parser_Context {
108 $this->request = $request;
109
110 return $this;
111 }
112
113
114 public function set_files_context( $files ): Parser_Context {
115 $this->files = $files;
116
117 return $this;
118 }
119
120 public function get_request(): array {
121 return $this->request;
122 }
123
124 /**
125 * @return mixed
126 */
127 public function get_files() {
128 return $this->files;
129 }
130
131 /**
132 * @return mixed
133 */
134 public function get_block() {
135 return $this->block;
136 }
137
138 /**
139 * @return mixed
140 */
141 public function get_settings() {
142 return $this->settings;
143 }
144
145 /**
146 * @return string
147 */
148 public function get_name(): string {
149 return $this->name;
150 }
151
152 public function is_inside_conditional(): bool {
153 return $this->inside_conditional;
154 }
155
156 public function set_inside_conditional( bool $inside_conditional ): Parser_Context {
157 $this->inside_conditional = $inside_conditional;
158
159 return $this;
160 }
161
162
163 }
164