| 1 |
<?php |
| 2 |
|
| 3 |
namespace FilterEverything\Filter; |
| 4 |
|
| 5 |
if ( ! defined('WPINC') ) { |
| 6 |
wp_die(); |
| 7 |
} |
| 8 |
|
| 9 |
use FilterEverything\Filter\Pro\SeoFrontend; |
| 10 |
|
| 11 |
class Container |
| 12 |
{ |
| 13 |
private static $instance; |
| 14 |
|
| 15 |
private $services = []; |
| 16 |
|
| 17 |
private $params = []; |
| 18 |
|
| 19 |
private function __construct() |
| 20 |
{ |
| 21 |
} |
| 22 |
|
| 23 |
public function __clone() |
| 24 |
{ |
| 25 |
} |
| 26 |
|
| 27 |
public function __wakeup() |
| 28 |
{ |
| 29 |
throw new Exception("Cannot unserialize singleton"); |
| 30 |
} |
| 31 |
|
| 32 |
public static function instance() |
| 33 |
{ |
| 34 |
if (!isset(self::$instance)) { |
| 35 |
self::$instance = new self(); |
| 36 |
} |
| 37 |
return self::$instance; |
| 38 |
} |
| 39 |
|
| 40 |
public function storeParam($key, $value) |
| 41 |
{ |
| 42 |
if (!isset($this->params[$key])) { |
| 43 |
$this->params[$key] = $value; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
public function getParam($key) |
| 48 |
{ |
| 49 |
if (isset($this->params[$key])) { |
| 50 |
return $this->params[$key]; |
| 51 |
} |
| 52 |
return false; |
| 53 |
} |
| 54 |
|
| 55 |
public function getService($key) |
| 56 |
{ |
| 57 |
if (isset($this->services[$key])) { |
| 58 |
return $this->services[$key]; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
public function addService($key, $service) |
| 63 |
{ |
| 64 |
$this->services[$key] = $service; |
| 65 |
} |
| 66 |
|
| 67 |
public function getEntityManager() |
| 68 |
{ |
| 69 |
if (!isset($this->services['entitymanager'])) { |
| 70 |
$this->addService('entitymanager', new EntityManager()); |
| 71 |
} |
| 72 |
|
| 73 |
return $this->getService('entitymanager'); |
| 74 |
} |
| 75 |
|
| 76 |
public function getFilterService() |
| 77 |
{ |
| 78 |
if (!isset($this->services['filterservice'])) { |
| 79 |
$this->addService('filterservice', new Filter( array( 'or' => '-or-', 'and' => '-and-' ) )); |
| 80 |
} |
| 81 |
|
| 82 |
return $this->getService('filterservice'); |
| 83 |
} |
| 84 |
|
| 85 |
public function getTemplateManager() |
| 86 |
{ |
| 87 |
if (!isset($this->services['templatemanager'])) { |
| 88 |
$this->addService('templatemanager', new TemplateManager(FLRT_PLUGIN_DIR)); |
| 89 |
} |
| 90 |
|
| 91 |
return $this->getService('templatemanager'); |
| 92 |
} |
| 93 |
|
| 94 |
public function getFilterSetService() |
| 95 |
{ |
| 96 |
if (!isset($this->services['filterset'])) { |
| 97 |
$this->addService('filterset', new FilterSet()); |
| 98 |
} |
| 99 |
|
| 100 |
return $this->getService('filterset'); |
| 101 |
} |
| 102 |
|
| 103 |
public function getFilterFieldsService() |
| 104 |
{ |
| 105 |
if (!isset($this->services['filterfields'])) { |
| 106 |
$this->addService('filterfields', new FilterFields()); |
| 107 |
} |
| 108 |
|
| 109 |
return $this->getService('filterfields'); |
| 110 |
} |
| 111 |
|
| 112 |
public function getWpManager() |
| 113 |
{ |
| 114 |
if (!isset($this->services['wpmanager'])) { |
| 115 |
$this->addService('wpmanager', new WpManager()); |
| 116 |
} |
| 117 |
|
| 118 |
return $this->getService('wpmanager'); |
| 119 |
} |
| 120 |
|
| 121 |
public function getSeoFrontendService() |
| 122 |
{ |
| 123 |
if( class_exists('FilterEverything\Filter\Pro\SeoFrontend') ) { |
| 124 |
if (!isset($this->services['seofrontend'])) { |
| 125 |
$this->addService('seofrontend', new SeoFrontend()); |
| 126 |
} |
| 127 |
|
| 128 |
return $this->getService('seofrontend'); |
| 129 |
} |
| 130 |
|
| 131 |
return new \stdClass(); |
| 132 |
} |
| 133 |
|
| 134 |
public function getTabRenderer() |
| 135 |
{ |
| 136 |
if (!isset($this->services['tabrenderer'])) { |
| 137 |
$this->addService('tabrenderer', new TabRenderer()); |
| 138 |
} |
| 139 |
|
| 140 |
return $this->getService('tabrenderer'); |
| 141 |
} |
| 142 |
|
| 143 |
public function getTheGet() |
| 144 |
{ |
| 145 |
if( ! $this->getParam('get') ){ |
| 146 |
$this->storeParam( 'get', $_GET ); |
| 147 |
} |
| 148 |
|
| 149 |
return $this->getParam('get'); |
| 150 |
} |
| 151 |
|
| 152 |
public function getThePost() |
| 153 |
{ |
| 154 |
if( ! $this->getParam('post') ){ |
| 155 |
$this->storeParam( 'post', $_POST ); |
| 156 |
} |
| 157 |
|
| 158 |
return $this->getParam('post'); |
| 159 |
} |
| 160 |
|
| 161 |
} |