conditions
2 years ago
events
2 years ago
methods
2 years ago
types
2 years ago
action-handler.php
2 years ago
action-localize.php
2 years ago
actions-tools.php
2 years ago
events-list.php
2 years ago
events-manager.php
2 years ago
legacy-request-data.php
2 years ago
manager.php
2 years ago
send-email-hooks.php
2 years ago
events-list.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Actions; |
| 5 | |
| 6 | use Jet_Form_Builder\Actions\Events\Base_Event; |
| 7 | use Jet_Form_Builder\Actions\Events\Base_Executor; |
| 8 | use Jet_Form_Builder\Classes\Arrayable\Collection; |
| 9 | use Jet_Form_Builder\Exceptions\Repository_Exception; |
| 10 | |
| 11 | // If this file is called directly, abort. |
| 12 | if ( ! defined( 'WPINC' ) ) { |
| 13 | die; |
| 14 | } |
| 15 | |
| 16 | class Events_List extends Collection { |
| 17 | |
| 18 | public static function create( array $events ): Events_List { |
| 19 | $collection = new Events_List(); |
| 20 | foreach ( $events as $event ) { |
| 21 | $collection->push( $event ); |
| 22 | } |
| 23 | |
| 24 | return $collection; |
| 25 | } |
| 26 | |
| 27 | public function push( $event ): Events_List { |
| 28 | if ( $event instanceof Base_Event ) { |
| 29 | return $this->add( $event ); |
| 30 | } |
| 31 | |
| 32 | try { |
| 33 | $item = Events_Manager::instance()->rep_clone_item( $event ); |
| 34 | } catch ( Repository_Exception $exception ) { |
| 35 | return $this->add( Events_Manager::instance()->get_never_event() ); |
| 36 | } |
| 37 | |
| 38 | return $this->add( $item ); |
| 39 | } |
| 40 | |
| 41 | public function in_array( $state ): bool { |
| 42 | if ( ! ( $state instanceof Base_Executor ) ) { |
| 43 | return parent::in_array( $state ); |
| 44 | } |
| 45 | $executor_name = get_class( $state ); |
| 46 | |
| 47 | /** @var Base_Event $event */ |
| 48 | foreach ( $this as $event ) { |
| 49 | if ( ! in_array( $executor_name, $event->ignored_executors(), true ) ) { |
| 50 | return parent::in_array( $state->get_event() ); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return 0 !== count( $this ); |
| 55 | } |
| 56 | |
| 57 | } |
| 58 |