| 1 |
<?php |
| 2 |
|
| 3 |
namespace FilterEverything\Filter; |
| 4 |
|
| 5 |
if ( ! defined('ABSPATH') ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class TabRenderer |
| 10 |
{ |
| 11 |
|
| 12 |
private $tabs = []; |
| 13 |
|
| 14 |
public function register(TabInterface $tab) |
| 15 |
{ |
| 16 |
$this->tabs[$tab->getName()] = $tab; |
| 17 |
} |
| 18 |
|
| 19 |
public function init() |
| 20 |
{ |
| 21 |
foreach ($this->tabs as $tab) { |
| 22 |
$tab->init(); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
public function render() |
| 27 |
{ |
| 28 |
$tab = $this->get($this->current()) ?: reset($this->tabs); |
| 29 |
|
| 30 |
if ($tab && $tab->valid()) { |
| 31 |
flrt_include_admin_view( 'options', array('tabs' => $this->tabs, 'current' => $tab) ); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
public function get($name) |
| 36 |
{ |
| 37 |
return $this->has($name) ? $this->tabs[$name] : null; |
| 38 |
} |
| 39 |
|
| 40 |
public function has($name) |
| 41 |
{ |
| 42 |
return isset($this->tabs[$name]); |
| 43 |
} |
| 44 |
|
| 45 |
public function current() |
| 46 |
{ |
| 47 |
/** |
| 48 |
* string |
| 49 |
*/ |
| 50 |
$get = Container::instance()->getTheGet(); |
| 51 |
return isset($get['tab']) ? sanitize_key($get['tab']) : null; |
| 52 |
} |
| 53 |
} |
| 54 |
|