ModuleConstants.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core;
  3. class ModuleConstants
  4. {
  5. protected static $mgDevConfig = null;
  6. protected static $mgHelperLangs = null;
  7. protected static $mgCoreConfig = null;
  8. protected static $mgModuleRootDir = null;
  9. protected static $mgTemplateDir = null;
  10. protected static $mgIsPhp7 = false;
  11. protected static $mgModuleNamespace = "ModulesGarden\ProxmoxAddon";
  12. protected static $prefixDataBase = "";
  13. public static function initialize()
  14. {
  15. self::$mgModuleRootDir = dirname(__DIR__);
  16. self::$mgDevConfig = self::getFullPath("app", "Config");
  17. self::$mgHelperLangs = self::getFullPath("langs");
  18. self::$mgCoreConfig = self::getFullPath("core", "Config");
  19. self::$mgTemplateDir = self::getFullPath("templates");
  20. self::$mgIsPhp7 = self::checkIfPhp7();
  21. self::$prefixDataBase = self::loadDataBasePrefix();
  22. }
  23. public static function loadDataBasePrefix()
  24. {
  25. $namespaceParts = explode("\\", self::$mgModuleNamespace);
  26. return end($namespaceParts);
  27. }
  28. public static function checkIfPhp7()
  29. {
  30. return (version_compare(PHP_VERSION, '7.0.0') >= 0);
  31. }
  32. public static function getDevConfigDir()
  33. {
  34. return self::$mgDevConfig;
  35. }
  36. public static function getCoreConfigDir()
  37. {
  38. return self::$mgCoreConfig;
  39. }
  40. public static function getLangsDir()
  41. {
  42. return self::$mgHelperLangs;
  43. }
  44. public static function getModuleRootDir()
  45. {
  46. return self::$mgModuleRootDir;
  47. }
  48. public static function getFullPath()
  49. {
  50. $fullPath = self::getModuleRootDir();
  51. foreach (func_get_args() as $dir)
  52. {
  53. $fullPath .= (DS . $dir);
  54. }
  55. return $fullPath;
  56. }
  57. public static function getFullNamespace()
  58. {
  59. $fullNamespace = self::getRootNamespace();
  60. foreach (func_get_args() as $dir)
  61. {
  62. $fullNamespace .= ("\\" . $dir);
  63. }
  64. return $fullNamespace;
  65. }
  66. public static function getFullPathWhmcs()
  67. {
  68. $fullPath = ROOTDIR;
  69. foreach (func_get_args() as $dir)
  70. {
  71. $fullPath .= (DS . $dir);
  72. }
  73. return $fullPath;
  74. }
  75. public static function requireFile($file, $ones = true)
  76. {
  77. if ($ones)
  78. {
  79. require_once $file;
  80. }
  81. else
  82. {
  83. require $file;
  84. }
  85. }
  86. public static function getTemplateDir()
  87. {
  88. return self::$mgTemplateDir;
  89. }
  90. public static function isPhp7orHigher()
  91. {
  92. return self::$mgIsPhp7;
  93. }
  94. public static function getPrefixDataBase()
  95. {
  96. return self::$prefixDataBase . "_";
  97. }
  98. public static function getRootNamespace()
  99. {
  100. return self::$mgModuleNamespace;
  101. }
  102. }