conditions
3 years ago
events
3 years ago
methods
3 years ago
types
3 years ago
action-handler.php
3 years ago
action-localize.php
3 years ago
events-list.php
3 years ago
events-manager.php
3 years ago
manager.php
3 years ago
events-list.php
53 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 | class Events_List extends Collection { |
| 12 | |
| 13 | public static function create( array $events ): Events_List { |
| 14 | $collection = new Events_List(); |
| 15 | foreach ( $events as $event ) { |
| 16 | $collection->push( $event ); |
| 17 | } |
| 18 | |
| 19 | return $collection; |
| 20 | } |
| 21 | |
| 22 | public function push( $event ): Events_List { |
| 23 | if ( $event instanceof Base_Event ) { |
| 24 | return $this->add( $event ); |
| 25 | } |
| 26 | |
| 27 | try { |
| 28 | $item = Events_Manager::instance()->rep_get_item( $event ); |
| 29 | } catch ( Repository_Exception $exception ) { |
| 30 | return $this; |
| 31 | } |
| 32 | |
| 33 | return $this->add( $item ); |
| 34 | } |
| 35 | |
| 36 | public function in_array( $state ): bool { |
| 37 | if ( ! ( $state instanceof Base_Executor ) ) { |
| 38 | return parent::in_array( $state ); |
| 39 | } |
| 40 | $executor_name = get_class( $state ); |
| 41 | |
| 42 | /** @var Base_Event $event */ |
| 43 | foreach ( $this as $event ) { |
| 44 | if ( ! in_array( $executor_name, $event->ignored_executors(), true ) ) { |
| 45 | return parent::in_array( $state->get_event() ); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | return 0 !== count( $this ); |
| 50 | } |
| 51 | |
| 52 | } |
| 53 |