| 1 |
<?php |
| 2 |
|
| 3 |
namespace FilterEverything\Filter; |
| 4 |
|
| 5 |
if ( ! defined('ABSPATH') ) { |
| 6 |
exit; |
| 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() ); |
| 80 |
} |
| 81 |
|
| 82 |
return $this->getService('filterservice'); |
| 83 |
} |
| 84 |
|
| 85 |
public function getUrlManager() |
| 86 |
{ |
| 87 |
if ( ! isset( $this->services['urlmanager'] ) ) { |
| 88 |
$this->addService('urlmanager', new UrlManager() ); |
| 89 |
} |
| 90 |
return $this->getService('urlmanager'); |
| 91 |
} |
| 92 |
|
| 93 |
public function getTemplateManager() |
| 94 |
{ |
| 95 |
if (!isset($this->services['templatemanager'])) { |
| 96 |
$this->addService('templatemanager', new TemplateManager(FLRT_PLUGIN_DIR_PATH)); |
| 97 |
} |
| 98 |
|
| 99 |
return $this->getService('templatemanager'); |
| 100 |
} |
| 101 |
|
| 102 |
public function getFilterSetService() |
| 103 |
{ |
| 104 |
if (!isset($this->services['filterset'])) { |
| 105 |
$this->addService('filterset', new FilterSet()); |
| 106 |
} |
| 107 |
|
| 108 |
return $this->getService('filterset'); |
| 109 |
} |
| 110 |
|
| 111 |
public function getFilterFieldsService() |
| 112 |
{ |
| 113 |
if (!isset($this->services['filterfields'])) { |
| 114 |
$this->addService('filterfields', new FilterFields()); |
| 115 |
} |
| 116 |
|
| 117 |
return $this->getService('filterfields'); |
| 118 |
} |
| 119 |
|
| 120 |
public function getWpManager() |
| 121 |
{ |
| 122 |
if (!isset($this->services['wpmanager'])) { |
| 123 |
$this->addService('wpmanager', new WpManager()); |
| 124 |
} |
| 125 |
|
| 126 |
return $this->getService('wpmanager'); |
| 127 |
} |
| 128 |
|
| 129 |
public function getSeoFrontendService() |
| 130 |
{ |
| 131 |
if( class_exists('FilterEverything\Filter\Pro\SeoFrontend') ) { |
| 132 |
if (!isset($this->services['seofrontend'])) { |
| 133 |
$this->addService('seofrontend', new SeoFrontend()); |
| 134 |
} |
| 135 |
|
| 136 |
return $this->getService('seofrontend'); |
| 137 |
} |
| 138 |
|
| 139 |
return new \stdClass(); |
| 140 |
} |
| 141 |
|
| 142 |
public function getTabRenderer() |
| 143 |
{ |
| 144 |
if (!isset($this->services['tabrenderer'])) { |
| 145 |
$this->addService('tabrenderer', new TabRenderer()); |
| 146 |
} |
| 147 |
|
| 148 |
return $this->getService('tabrenderer'); |
| 149 |
} |
| 150 |
|
| 151 |
public function getSwatches() |
| 152 |
{ |
| 153 |
if ( !isset( $this->services['swatches'] ) ) { |
| 154 |
$this->addService('swatches', new Swatches() ); |
| 155 |
} |
| 156 |
|
| 157 |
return $this->getService('swatches' ); |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* Sanitizes $_GET variables and stores them in the Container |
| 162 |
* @return false|mixed |
| 163 |
*/ |
| 164 |
public function getTheGet() |
| 165 |
{ |
| 166 |
if ( ! $this->getParam('get') ) { |
| 167 |
$clean_get = []; |
| 168 |
|
| 169 |
if ( is_array( $_GET ) ) { |
| 170 |
foreach ( $_GET as $param => $value ) { |
| 171 |
$clean_get[ $param ] = flrt_string_polyfill( $value ); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
$this->storeParam( 'get', $clean_get ); |
| 176 |
} |
| 177 |
|
| 178 |
return $this->getParam('get'); |
| 179 |
} |
| 180 |
|
| 181 |
public function getThePost() |
| 182 |
{ |
| 183 |
if( ! $this->getParam('post') ){ |
| 184 |
$this->storeParam( 'post', $_POST ); |
| 185 |
} |
| 186 |
|
| 187 |
return $this->getParam('post'); |
| 188 |
} |
| 189 |
|
| 190 |
} |