base-v2.php
2 months ago
base.php
2 years ago
get-from-db.php
2 months ago
get-from-rest-api.php
2 months ago
get-from-users.php
2 months ago
get-related-posts.php
2 months ago
legacy-parser.php
2 months ago
num-range-manual.php
2 months ago
num-range.php
2 months ago
registry.php
2 months ago
base.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Jet_Form_Builder\Generators; |
| 4 | |
| 5 | // If this file is called directly, abort. |
| 6 | if ( ! defined( 'WPINC' ) ) { |
| 7 | die; |
| 8 | } |
| 9 | |
| 10 | abstract class Base { |
| 11 | |
| 12 | /** |
| 13 | * @var \Jet_Form_Builder\Blocks\Types\Base |
| 14 | */ |
| 15 | protected $block; |
| 16 | |
| 17 | /** |
| 18 | * Returns generator ID |
| 19 | * |
| 20 | * @return [type] [description] |
| 21 | */ |
| 22 | abstract public function get_id(); |
| 23 | |
| 24 | /** |
| 25 | * Returns generator name |
| 26 | * |
| 27 | * @return [type] [description] |
| 28 | */ |
| 29 | abstract public function get_name(); |
| 30 | |
| 31 | /** |
| 32 | * Returns generated options list |
| 33 | * |
| 34 | * @param $args |
| 35 | * |
| 36 | * @return array |
| 37 | */ |
| 38 | abstract public function generate( $args ); |
| 39 | |
| 40 | public function can_generate() { |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | public function incoming_args() { |
| 45 | return array( |
| 46 | 'generator_field' => function ( $value ) { |
| 47 | return $value; |
| 48 | }, |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | public function get_values( $args ) { |
| 53 | $fields = array(); |
| 54 | |
| 55 | foreach ( $this->incoming_args() as $name => $parse_callable ) { |
| 56 | $fields[ $name ] = isset( $args[ $name ] ) ? call_user_func( $parse_callable, $args[ $name ] ) : false; |
| 57 | } |
| 58 | |
| 59 | return $this->generate( $fields ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @param \Jet_Form_Builder\Blocks\Types\Base $block |
| 64 | */ |
| 65 | public function set_block( \Jet_Form_Builder\Blocks\Types\Base $block ) { |
| 66 | $this->block = $block; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @return \Jet_Form_Builder\Blocks\Types\Base |
| 71 | */ |
| 72 | public function get_block(): \Jet_Form_Builder\Blocks\Types\Base { |
| 73 | return $this->block; |
| 74 | } |
| 75 | |
| 76 | public function clear_block() { |
| 77 | $this->block = null; |
| 78 | } |
| 79 | |
| 80 | } |
| 81 |