bad-request
3 years ago
default-process
3 years ago
default-required
3 years ago
gateway-failed
3 years ago
gateway-success
3 years ago
base-action-event.php
3 years ago
base-event.php
3 years ago
base-executor.php
3 years ago
base-gateway-event.php
3 years ago
gateway-base-executor.php
3 years ago
base-event.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Actions\Events; |
| 5 | |
| 6 | use Jet_Form_Builder\Actions\Types\Base; |
| 7 | use Jet_Form_Builder\Classes\Arrayable\Arrayable; |
| 8 | use Jet_Form_Builder\Classes\Arrayable\Collection_Item_Interface; |
| 9 | use Jet_Form_Builder\Classes\Repository\Repository_Item_Instance_Trait; |
| 10 | use Jet_Form_Builder\Exceptions\Action_Exception; |
| 11 | |
| 12 | abstract class Base_Event implements |
| 13 | Repository_Item_Instance_Trait, |
| 14 | Collection_Item_Interface, |
| 15 | Arrayable { |
| 16 | |
| 17 | /** |
| 18 | * @return Base_Executor[] |
| 19 | */ |
| 20 | abstract public function executors(): array; |
| 21 | |
| 22 | public function ignored_executors(): array { |
| 23 | return array(); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @throws Action_Exception |
| 28 | */ |
| 29 | final public function execute() { |
| 30 | $this->get_executor()->execute(); |
| 31 | } |
| 32 | |
| 33 | |
| 34 | /** |
| 35 | * @return Base_Executor |
| 36 | */ |
| 37 | final public function get_executor(): Base_Executor { |
| 38 | foreach ( $this->executors() as $executor ) { |
| 39 | if ( $executor->is_supported() ) { |
| 40 | return $executor->set_event( $this ); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped |
| 45 | wp_die( |
| 46 | /* translators: %s - Event class name */ |
| 47 | sprintf( __( 'Not founded supported executor for %s', 'jet-form-builder' ), static::class ) |
| 48 | ); |
| 49 | // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped |
| 50 | } |
| 51 | |
| 52 | public function is_valid_action( Base $action ): bool { |
| 53 | $unsupported = $action->unsupported_events(); |
| 54 | |
| 55 | if ( ! empty( $unsupported ) && in_array( static::class, $unsupported, true ) ) { |
| 56 | return false; |
| 57 | } |
| 58 | $supported = $action->supported_events(); |
| 59 | |
| 60 | if ( ! empty( $supported ) && ! in_array( static::class, $supported, true ) ) { |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | return $action->get_events()->in_array( $this ); |
| 65 | } |
| 66 | |
| 67 | public function get_label(): string { |
| 68 | return $this->get_id(); |
| 69 | } |
| 70 | |
| 71 | public function rep_item_id() { |
| 72 | return $this->get_id(); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | public function to_array(): array { |
| 77 | return array( |
| 78 | 'value' => $this->get_id(), |
| 79 | 'label' => $this->get_label(), |
| 80 | 'self' => static::class, |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | } |
| 85 |