model-dependencies-interface.php
2 years ago
model-dependencies.php
2 years ago
with-view.php
2 years ago
with-view.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Db_Queries\Traits; |
| 5 | |
| 6 | use Jet_Form_Builder\Db_Queries\Views\View_Base; |
| 7 | use Jet_Form_Builder\Exceptions\Query_Builder_Exception; |
| 8 | |
| 9 | // If this file is called directly, abort. |
| 10 | if ( ! defined( 'WPINC' ) ) { |
| 11 | die; |
| 12 | } |
| 13 | |
| 14 | trait With_View { |
| 15 | |
| 16 | private $view; |
| 17 | |
| 18 | public function before_set_view( View_Base $view ) { |
| 19 | } |
| 20 | |
| 21 | public function after_set_view() { |
| 22 | } |
| 23 | |
| 24 | public function set_view( View_Base $view ) { |
| 25 | $this->before_set_view( $view ); |
| 26 | $this->view = $view; |
| 27 | $this->after_set_view(); |
| 28 | |
| 29 | return $this; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @return View_Base |
| 34 | * @throws Query_Builder_Exception |
| 35 | */ |
| 36 | public function view(): View_Base { |
| 37 | if ( ! $this->view ) { |
| 38 | throw new Query_Builder_Exception( 'Undefined view' ); |
| 39 | } |
| 40 | |
| 41 | return $this->view; |
| 42 | } |
| 43 | |
| 44 | } |
| 45 |