scenario-logic-base.php
2 years ago
scenario-logic-repository.php
2 years ago
scenario-view-base.php
2 years ago
scenarios-manager-abstract.php
2 years ago
scenarios-view-repository.php
2 years ago
scenarios-manager-abstract.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace JFB_Modules\Gateways\Scenarios_Abstract; |
| 5 | |
| 6 | use Jet_Form_Builder\Exceptions\Gateway_Exception; |
| 7 | use Jet_Form_Builder\Exceptions\Repository_Exception; |
| 8 | use JFB_Modules\Gateways\Base_Gateway; |
| 9 | |
| 10 | // If this file is called directly, abort. |
| 11 | if ( ! defined( 'WPINC' ) ) { |
| 12 | die; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Class Actions_Manager |
| 17 | * |
| 18 | * @package JFB_Modules\Gateways\Paypal |
| 19 | */ |
| 20 | abstract class Scenarios_Manager_Abstract { |
| 21 | |
| 22 | const QUERY_VAR = 'jet_gateway_scenario'; |
| 23 | |
| 24 | private $queried_scenario; |
| 25 | // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
| 26 | private $_logic_manager; |
| 27 | private $_view_manager; |
| 28 | // phpcs:enable PSR2.Classes.PropertyDeclaration.Underscore |
| 29 | |
| 30 | protected function __construct() { |
| 31 | $this->logic()->rep_install(); |
| 32 | $this->view()->rep_install(); |
| 33 | } |
| 34 | |
| 35 | public function logic(): Scenario_Logic_Repository { |
| 36 | return $this->_logic_manager; |
| 37 | } |
| 38 | |
| 39 | public function view(): Scenarios_View_Repository { |
| 40 | return $this->_view_manager; |
| 41 | } |
| 42 | |
| 43 | protected function set_logic_manager( Scenario_Logic_Repository $manager ) { |
| 44 | $this->_logic_manager = $manager; |
| 45 | |
| 46 | return $this; |
| 47 | } |
| 48 | |
| 49 | protected function set_view_manager( Scenarios_View_Repository $manager ) { |
| 50 | $this->_view_manager = $manager; |
| 51 | |
| 52 | return $this; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param Base_Gateway $controller |
| 57 | * |
| 58 | * @return Scenario_Logic_Base |
| 59 | * @throws Repository_Exception |
| 60 | */ |
| 61 | public function get_logic( Base_Gateway $controller ): Scenario_Logic_Base { |
| 62 | return $this->logic()->rep_get_item( $controller->get_current_scenario_id() ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @param $slug |
| 67 | * |
| 68 | * @return Scenario_View_Base |
| 69 | * @throws Repository_Exception |
| 70 | */ |
| 71 | public function get_view( $slug ): Scenario_View_Base { |
| 72 | return $this->view()->get_view( $slug ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * @return Scenario_Logic_Base |
| 77 | * @throws Gateway_Exception |
| 78 | */ |
| 79 | public function query_logic(): Scenario_Logic_Base { |
| 80 | try { |
| 81 | if ( ! $this->queried_scenario ) { |
| 82 | $scenario = sanitize_text_field( |
| 83 | wp_unslash( |
| 84 | // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 85 | $_GET[ self::QUERY_VAR ] ?? '' |
| 86 | ) |
| 87 | ); |
| 88 | |
| 89 | $this->queried_scenario = $this->logic()->rep_get_item( $scenario ); |
| 90 | } |
| 91 | } catch ( Repository_Exception $exception ) { |
| 92 | throw new Gateway_Exception( esc_html( $exception->getMessage() ) ); |
| 93 | } |
| 94 | |
| 95 | return $this->queried_scenario; |
| 96 | } |
| 97 | |
| 98 | |
| 99 | } |
| 100 |