SubmoduleCap.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom;
  3. use MGModule\DNSManager2\mgLibs\custom\cache\CacheFactory;
  4. class SubmoduleCap {
  5. private $submodule;
  6. /** @var \MGModule\DNSManager2\mgLibs\custom\cache\CacheInterface */
  7. private $cache = false;
  8. public function __construct($submodule) {
  9. $this->submodule = $submodule;
  10. }
  11. public function __set($name, $value) {
  12. $this->submodule->$name = $value;
  13. }
  14. public function __get($name) {
  15. return $this->submodule->$name;
  16. }
  17. public function __call($name, $args) {
  18. if($this->cache !== false && in_array($name, array(
  19. 'addRecord', 'editRecord', 'deleteRecord', 'terminateZone', 'activateZone'
  20. ))) {
  21. $this->cache->remove();
  22. }
  23. return call_user_func_array(array($this->submodule,$name), $args);//$this->submodule->$name($args[0]);
  24. }
  25. public function enableCache($serverid, $domain) {
  26. $this->cache = CacheFactory::get("{$serverid}_{$domain}.cache");
  27. }
  28. public function getRecords($recordType = false) {
  29. if($recordType === false && $this->cache !== false && $this->cache->exist()) {
  30. return $this->cache->get();
  31. }
  32. $records = $this->submodule->getRecords($recordType);
  33. if($this->cache !== false) {
  34. $this->cache->save($records);
  35. }
  36. return $records;
  37. }
  38. public function moduleHasMethod($methodName)
  39. {
  40. return method_exists($this->submodule, $methodName);
  41. }
  42. public function moduleConvertInputFormData(&$input)
  43. {
  44. if($this->moduleHasMethod('convertInputFormData'))
  45. {
  46. $this->submodule->convertInputFormData($input);
  47. }
  48. }
  49. public function removeDefaultServerRecords($defaultModuleRecords)
  50. {
  51. if($this->submodule->isRemoveableDefaultServerRecordsSet())
  52. {
  53. $this->submodule->removeDefaultServerRecordsSet($defaultModuleRecords);
  54. }
  55. }
  56. public function customEditRecords($input)
  57. {
  58. if($this->submodule->hasCustomEditRecords())
  59. {
  60. return $this->submodule->customEditRecords($input);
  61. }
  62. return false;
  63. }
  64. public function getSubmodule()
  65. {
  66. return $this->submodule;
  67. }
  68. }