PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/dmCorePlugin/lib/project/dmProject.php

https://github.com/jaimesuez/diem
PHP | 152 lines | 113 code | 27 blank | 12 comment | 9 complexity | c78199c6de488b0099e08e6f959da321 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. $baseFiles = array_merge(
  37. glob(sfConfig::get('sf_lib_dir').'/model/doctrine/base/Base*.class.php'),
  38. glob(sfConfig::get('sf_lib_dir').'/model/doctrine/*Plugin/base/Base*.class.php')
  39. );
  40. $dmCoreDir = dmOs::join(sfConfig::get('sf_lib_dir'), 'model/doctrine/dmCorePlugin/base/');
  41. $dmUserDir = dmOs::join(sfConfig::get('sf_lib_dir'), 'model/doctrine/dmUserPlugin/base/');
  42. foreach($baseFiles as $index => $file)
  43. {
  44. if(0 === strpos($file, $dmCoreDir) || 0 === strpos($file, $dmUserDir))
  45. {
  46. unset($baseFiles[$index]);
  47. }
  48. }
  49. self::$models = self::getModelsFromBaseFiles($baseFiles);
  50. }
  51. return self::$models;
  52. }
  53. public static function getAllModels()
  54. {
  55. if (null === self::$allModels)
  56. {
  57. $baseFiles = array_merge(
  58. glob(sfConfig::get('sf_lib_dir').'/model/doctrine/base/Base*.class.php'),
  59. glob(sfConfig::get('sf_lib_dir').'/model/doctrine/*Plugin/base/Base*.class.php')
  60. );
  61. self::$allModels = self::getModelsFromBaseFiles($baseFiles);
  62. }
  63. return self::$allModels;
  64. }
  65. public static function getDmModels()
  66. {
  67. if (null === self::$dmModels)
  68. {
  69. $baseFiles = glob(dmOs::join(sfConfig::get('sf_lib_dir'), 'model/doctrine/dmCorePlugin/base/Base*.class.php'));
  70. self::$dmModels = self::getModelsFromBaseFiles($baseFiles);
  71. }
  72. return self::$dmModels;
  73. }
  74. protected static function getModelsFromBaseFiles(array $files)
  75. {
  76. $models = array();
  77. foreach($files as $file)
  78. {
  79. $models[] = preg_replace('|^Base(\w+).class.php$|', '$1', basename($file));
  80. }
  81. return $models;
  82. }
  83. public static function getRootDir()
  84. {
  85. return dmOs::normalize(sfConfig::get('sf_root_dir'));
  86. }
  87. public static function getNormalizedRootDir()
  88. {
  89. return dmOs::normalize(self::getRootDir());
  90. }
  91. /**
  92. * remove sfConfig::get('sf_root_dir') from path
  93. */
  94. public static function unRootify($path)
  95. {
  96. if (self::isInProject($path))
  97. {
  98. $path = substr($path, strlen(self::getRootDir()));
  99. }
  100. return trim($path, '/');
  101. }
  102. /**
  103. * add sfConfig::get('sf_root_dir') to path
  104. */
  105. public static function rootify($path)
  106. {
  107. if (!self::isInProject($path))
  108. {
  109. $path = dmOs::join(self::getRootDir(), $path);
  110. }
  111. else
  112. {
  113. $path = dmOs::join($path);
  114. }
  115. return $path;
  116. }
  117. public static function isInProject($path)
  118. {
  119. return strpos(dmOs::normalize($path), self::getRootDir()) === 0;
  120. }
  121. public static function appExists($application)
  122. {
  123. return file_exists(self::rootify('apps/'.$application.'/config/'.$application.'Configuration.class.php'));
  124. }
  125. }