PageRenderTime 64ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/dmCorePlugin/lib/project/dmProject.php

http://github.com/diem-project/diem
PHP | 153 lines | 114 code | 27 blank | 12 comment | 9 complexity | 71bd7b2a00479df5e2456657c08c6984 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT, ISC
  1. <?php
  2. class dmProject
  3. {
  4. protected static
  5. $key,
  6. $hash,
  7. $models,
  8. $allModels,
  9. $dmModels;
  10. /**
  11. * Returns project key based on his dir_name
  12. */
  13. public static function getKey()
  14. {
  15. if (null === self::$key)
  16. {
  17. self::$key = basename(sfConfig::get('sf_root_dir'));
  18. }
  19. return self::$key;
  20. }
  21. /**
  22. * Returns project key based on his root dir
  23. */
  24. public static function getHash()
  25. {
  26. if (null === self::$hash)
  27. {
  28. self::$hash = substr(md5(sfConfig::get('sf_root_dir')), -8);
  29. }
  30. return self::$hash;
  31. }
  32. public static function getModels()
  33. {
  34. if (null === self::$models)
  35. {
  36. $libDir = dmOs::normalize(sfConfig::get('sf_lib_dir'));
  37. $baseFiles = array_merge(
  38. glob($libDir.'/model/doctrine/base/Base*.class.php'),
  39. glob($libDir.'/model/doctrine/*Plugin/base/Base*.class.php')
  40. );
  41. $dmCoreDir = dmOs::join($libDir, 'model/doctrine/dmCorePlugin/base/');
  42. $dmUserDir = dmOs::join($libDir, 'model/doctrine/dmUserPlugin/base/');
  43. foreach($baseFiles as $index => $file)
  44. {
  45. if(0 === strpos($file, $dmCoreDir) || 0 === strpos($file, $dmUserDir))
  46. {
  47. unset($baseFiles[$index]);
  48. }
  49. }
  50. self::$models = self::getModelsFromBaseFiles($baseFiles);
  51. }
  52. return self::$models;
  53. }
  54. public static function getAllModels()
  55. {
  56. if (null === self::$allModels)
  57. {
  58. $baseFiles = array_merge(
  59. glob(sfConfig::get('sf_lib_dir').'/model/doctrine/base/Base*.class.php'),
  60. glob(sfConfig::get('sf_lib_dir').'/model/doctrine/*Plugin/base/Base*.class.php')
  61. );
  62. self::$allModels = self::getModelsFromBaseFiles($baseFiles);
  63. }
  64. return self::$allModels;
  65. }
  66. public static function getDmModels()
  67. {
  68. if (null === self::$dmModels)
  69. {
  70. $baseFiles = glob(dmOs::join(sfConfig::get('sf_lib_dir'), 'model/doctrine/dmCorePlugin/base/Base*.class.php'));
  71. self::$dmModels = self::getModelsFromBaseFiles($baseFiles);
  72. }
  73. return self::$dmModels;
  74. }
  75. protected static function getModelsFromBaseFiles(array $files)
  76. {
  77. $models = array();
  78. foreach($files as $file)
  79. {
  80. $models[] = preg_replace('|^Base(\w+).class.php$|', '$1', basename($file));
  81. }
  82. return $models;
  83. }
  84. public static function getRootDir()
  85. {
  86. return dmOs::normalize(sfConfig::get('sf_root_dir'));
  87. }
  88. public static function getNormalizedRootDir()
  89. {
  90. return dmOs::normalize(self::getRootDir());
  91. }
  92. /**
  93. * remove sfConfig::get('sf_root_dir') from path
  94. */
  95. public static function unRootify($path)
  96. {
  97. if (self::isInProject($path))
  98. {
  99. $path = substr($path, strlen(self::getRootDir()));
  100. }
  101. return trim($path, '/');
  102. }
  103. /**
  104. * add sfConfig::get('sf_root_dir') to path
  105. */
  106. public static function rootify($path)
  107. {
  108. if (!self::isInProject($path))
  109. {
  110. $path = dmOs::join(self::getRootDir(), $path);
  111. }
  112. else
  113. {
  114. $path = dmOs::join($path);
  115. }
  116. return $path;
  117. }
  118. public static function isInProject($path)
  119. {
  120. return strpos(dmOs::normalize($path), self::getRootDir()) === 0;
  121. }
  122. public static function appExists($application)
  123. {
  124. return file_exists(self::rootify('apps/'.$application.'/config/'.$application.'Configuration.class.php'));
  125. }
  126. }