| 1 |
<?php |
| 2 |
|
| 3 |
namespace BitCode\BitForm\Core\Form; |
| 4 |
|
| 5 |
use BitCode\BitForm\Admin\Form\AdminFormHandler; |
| 6 |
use BitCode\BitForm\Core\Capability\Request; |
| 7 |
use BitCode\BitForm\Frontend\Form\FrontendFormHandler; |
| 8 |
|
| 9 |
final class FormHandler |
| 10 |
{ |
| 11 |
private $_container = []; |
| 12 |
private static $_instance = null; |
| 13 |
|
| 14 |
/** |
| 15 |
* Undocumented function |
| 16 |
*/ |
| 17 |
public static function getInstance() |
| 18 |
{ |
| 19 |
if (null === self::$_instance) { |
| 20 |
self::$_instance = new FormHandler(); |
| 21 |
} |
| 22 |
return self::$_instance; |
| 23 |
} |
| 24 |
|
| 25 |
public function __construct() |
| 26 |
{ |
| 27 |
if (Request::Check('frontend')) { |
| 28 |
$this->load_public_form_handler(); |
| 29 |
} |
| 30 |
if (Request::Check('admin')) { |
| 31 |
$this->load_admin_form_handler(); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Magic getter function |
| 37 |
* |
| 38 |
* @param $object |
| 39 |
* |
| 40 |
* @return mixed |
| 41 |
*/ |
| 42 |
public function __get($object) |
| 43 |
{ |
| 44 |
if (array_key_exists($object, $this->_container)) { |
| 45 |
return $this->_container[$object]; |
| 46 |
} |
| 47 |
|
| 48 |
return $this->{$object}; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Magic isset function |
| 53 |
* |
| 54 |
* @param $object |
| 55 |
* |
| 56 |
* @return mixed |
| 57 |
*/ |
| 58 |
public function __isset($object) |
| 59 |
{ |
| 60 |
return isset($this->{$object}) || isset($this->container[$object]); |
| 61 |
} |
| 62 |
|
| 63 |
public function load_admin_form_handler() |
| 64 |
{ |
| 65 |
$this->_container['admin'] = new AdminFormHandler(); |
| 66 |
} |
| 67 |
|
| 68 |
protected function load_public_form_handler() |
| 69 |
{ |
| 70 |
$this->_container['frontend'] = new FrontendFormHandler(); |
| 71 |
} |
| 72 |
} |
| 73 |
|