Core.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\dns;
  3. use MGModule\DNSManager2 as main;
  4. class Core
  5. {
  6. /**
  7. *
  8. * @return Strategy
  9. * @throws exceptions\DNSException
  10. */
  11. public static function getModule($module) {
  12. if(!class_exists($module)) {
  13. $path = __DIR__ . DIRECTORY_SEPARATOR . 'submodules' . DIRECTORY_SEPARATOR . $module . '.php';
  14. if(file_exists($path) )
  15. require_once $path;
  16. else
  17. throw new exceptions\DNSException("Module file ($path) not found");
  18. }
  19. $module = __NAMESPACE__ . '\\submodules\\' . $module;
  20. return new Strategy(new $module());
  21. }
  22. public static function getAvailableSubmodules() {
  23. if(!file_exists(__DIR__ . DS . 'submodules')) return array();
  24. $di = new \DirectoryIterator(__DIR__ . DS . 'submodules');
  25. $out = array();
  26. foreach (new \IteratorIterator($di) as $file) {
  27. if($file->isFile() && $file->getExtension() == 'php')
  28. $out[] = $file->getBasename('.php');
  29. }
  30. sort($out);
  31. return $out;
  32. }
  33. public static function getAvailableRecordTypes()
  34. {
  35. if(!file_exists(__DIR__.DS.'record'.DS.'type'))
  36. {
  37. return array();
  38. }
  39. $dir = new \DirectoryIterator(__DIR__.DS.'record'.DS.'type');
  40. $out = array();
  41. foreach(new \IteratorIterator($dir) as $file)
  42. {
  43. if($file->isFile() && $file->getExtension() == 'php')
  44. {
  45. $out[] = $file->getBasename('.php');
  46. }
  47. }
  48. $out = array_diff($out, array('OldDNS', 'RecordTypeAbstract', 'Def'));
  49. sort($out);
  50. return $out;
  51. }
  52. /*
  53. * return record types list only for active servers
  54. * @return array
  55. */
  56. public static function getAvailableRecordTypesByActiveServers()
  57. {
  58. $avalibleRecordTypes = array();
  59. $rep = main\models\custom\server\Repository::factory()->onlyActive();
  60. $activeServers = $rep->get();
  61. foreach($activeServers as $server)
  62. {
  63. $submodule = $server->getModule();
  64. $tmpTypes = $submodule->availableTypes;
  65. $avalibleRecordTypes = array_unique(array_merge($avalibleRecordTypes, $tmpTypes));
  66. }
  67. return $avalibleRecordTypes;
  68. }
  69. }