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