/libraries/rokcommon/RokCommon/Service.php

https://bitbucket.org/pastor399/newcastleunifc · PHP · 143 lines · 67 code · 15 blank · 61 comment · 6 complexity · 0d992ea493d81a4a016e5f44d50ba3d9 MD5 · raw file

  1. <?php
  2. /**
  3. * @version $Id: Service.php 57540 2012-10-14 18:27:59Z btowles $
  4. * @author RocketTheme http://www.rockettheme.com
  5. * @copyright Copyright (C) 2007 - ${copyright_year} RocketTheme, LLC
  6. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  7. */
  8. defined('ROKCOMMON') or die;
  9. /**
  10. *
  11. */
  12. class RokCommon_Service extends RokCommon_Service_Container_Builder
  13. {
  14. /**
  15. * @var bool
  16. */
  17. protected static $developmentMode = false;
  18. /**
  19. * @var RokCommon_Service_Container[]
  20. */
  21. protected static $instance = array();
  22. /**
  23. * @var
  24. */
  25. protected static $containerInstance;
  26. /**
  27. * @var string
  28. */
  29. protected static $last_checksum = null;
  30. /**
  31. * @var string[]
  32. */
  33. protected static $config_files = array();
  34. /**
  35. * @var array
  36. */
  37. protected static $addedFiles = array();
  38. /**
  39. * @var array
  40. */
  41. protected static $addingFiles = array();
  42. /**
  43. * @var
  44. */
  45. protected static $tmp_file_dir;
  46. /**
  47. * @static
  48. * @return RokCommon_Service_Container
  49. */
  50. public static function &getContainer()
  51. {
  52. if (!isset(self::$containerInstance)) {
  53. self::$containerInstance = new self;
  54. $loader = new RokCommon_Service_Container_Loader_File_Xml(self::$containerInstance);
  55. // get and load the platform specific base container file
  56. $platform = RokCommon_PlatformFactory::getCurrent();
  57. foreach ($platform->getLoaderChecks() as $platform_check) {
  58. $platform_file = ROKCOMMON_LIB_PATH . '/config/' . $platform_check . '.xml';
  59. if (file_exists($platform_file)) {
  60. $loader->load($platform_file);
  61. /** @var $platforminfo RokCommon_IPlatformInfo */
  62. $platforminfo = self::$containerInstance->platforminfo;
  63. $platforminfo->setPlatformParameters(self::$containerInstance);
  64. break;
  65. }
  66. }
  67. }
  68. return self::$containerInstance;
  69. }
  70. /**
  71. * @static
  72. *
  73. * @param string $path
  74. */
  75. public static function addConfigFile($path)
  76. {
  77. self::getContainer();
  78. if (!in_array($path, self::$config_files)) {
  79. // set up the loader
  80. $loader = new RokCommon_Service_Container_Loader_File_Xml(self::$containerInstance);
  81. $loader->load($path);
  82. self::$config_files[] = $path;
  83. }
  84. }
  85. /**
  86. * @static
  87. * @return string[]
  88. */
  89. protected static function getConfigFiles()
  90. {
  91. $ret = array();
  92. ksort(self::$config_files, SORT_NUMERIC);
  93. $iterator = new RecursiveArrayIterator(self::$config_files);
  94. foreach ($iterator as $path) {
  95. if (is_file($path)) {
  96. $ret[] = $path;
  97. }
  98. }
  99. return $ret;
  100. }
  101. /**
  102. * @param boolean $developmentMode
  103. */
  104. public static function setDevelopmentMode($developmentMode)
  105. {
  106. self::$developmentMode = $developmentMode;
  107. }
  108. /**
  109. * @return boolean
  110. */
  111. public static function getDevelopmentMode()
  112. {
  113. return self::$developmentMode;
  114. }
  115. /**
  116. * @static
  117. *
  118. * @param $path
  119. */
  120. public static function setTempFileDir($path)
  121. {
  122. if (@is_dir($path) && @is_writable($path)) {
  123. self::$tmp_file_dir = $path;
  124. }
  125. }
  126. }
  127. RokCommon_Service::setTempFileDir(sys_get_temp_dir());