| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace MGModule\DNSManager2\mgLibs\custom;
- use MGModule\DNSManager2\mgLibs\custom\cache\CacheFactory;
- class SubmoduleCap {
- private $submodule;
- /** @var \MGModule\DNSManager2\mgLibs\custom\cache\CacheInterface */
- private $cache = false;
-
- public function __construct($submodule) {
- $this->submodule = $submodule;
- }
-
- public function __set($name, $value) {
- $this->submodule->$name = $value;
- }
-
- public function __get($name) {
- return $this->submodule->$name;
- }
-
- public function __call($name, $args) {
- if($this->cache !== false && in_array($name, array(
- 'addRecord', 'editRecord', 'deleteRecord', 'terminateZone', 'activateZone'
- ))) {
- $this->cache->remove();
- }
- return call_user_func_array(array($this->submodule,$name), $args);//$this->submodule->$name($args[0]);
- }
-
- public function enableCache($serverid, $domain) {
- $this->cache = CacheFactory::get("{$serverid}_{$domain}.cache");
- }
-
- public function getRecords($recordType = false) {
- if($recordType === false && $this->cache !== false && $this->cache->exist()) {
- return $this->cache->get();
- }
-
- $records = $this->submodule->getRecords($recordType);
-
- if($this->cache !== false) {
- $this->cache->save($records);
- }
- return $records;
- }
-
- public function moduleHasMethod($methodName)
- {
- return method_exists($this->submodule, $methodName);
- }
-
- public function moduleConvertInputFormData(&$input)
- {
- if($this->moduleHasMethod('convertInputFormData'))
- {
- $this->submodule->convertInputFormData($input);
- }
- }
- public function removeDefaultServerRecords($defaultModuleRecords)
- {
- if($this->submodule->isRemoveableDefaultServerRecordsSet())
- {
- $this->submodule->removeDefaultServerRecordsSet($defaultModuleRecords);
- }
- }
-
- public function customEditRecords($input)
- {
- if($this->submodule->hasCustomEditRecords())
- {
- return $this->submodule->customEditRecords($input);
- }
-
- return false;
- }
- public function getSubmodule()
- {
- return $this->submodule;
- }
- }
|