api.usconfig.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Basic Ubilling UserStats configs abstraction class
  4. */
  5. class UserStatsConfig {
  6. /**
  7. * Stores UserStats main config "userstats.ini"
  8. *
  9. * @var array
  10. */
  11. protected $ustasCfg = array();
  12. /**
  13. * Stores OPENPAYZ config "opayz.ini"
  14. *
  15. * @var array
  16. */
  17. protected $opayzCfg = array();
  18. /**
  19. * Stores TARIFF_MATRIX config "tariffmatrix.ini"
  20. *
  21. * @var array
  22. */
  23. protected $tariffmatrixCfg = array();
  24. const US_CONFIG_PATH = 'config/userstats.ini';
  25. const OPAYZ_CONFIG_PATH = 'config/opayz.ini';
  26. const TARIFF_MATRIX_CONFIG_PATH = 'config/tariffmatrix.ini';
  27. public function __construct() {
  28. $this->loadUstas();
  29. $this->loadOpayzCfg();
  30. }
  31. /**
  32. * Loads UserStats main config "userstats.ini" to private ustasCfg prop
  33. *
  34. * @return void
  35. */
  36. protected function loadUstas() {
  37. $this->ustasCfg = parse_ini_file(self::US_CONFIG_PATH);
  38. }
  39. /**
  40. * Getter for private ustatsCfg prop
  41. *
  42. * @return array
  43. */
  44. public function getUstas() {
  45. return ($this->ustasCfg);
  46. }
  47. /**
  48. * Parameter getter for ustasCfg
  49. * Returns $parameter from "userstats.ini" or FALSE if parameter not defined
  50. * May return $retValIfParamEmptyOrNotExists value, instead of searched $parameter,
  51. * if searched $parameter is FALSE (but NOT NULL) or not defined
  52. *
  53. * @param mixed $param
  54. * @param mixed $retValIfParamEmptyOrNotExists
  55. *
  56. * @return mixed
  57. */
  58. public function getUstasParam($param = false, $retValIfParamEmptyOrNotExists = null) {
  59. $alterParam = ($param and isset($this->ustasCfg[$param])) ? $this->ustasCfg[$param] : false;
  60. if ($alterParam === false and !is_null($retValIfParamEmptyOrNotExists)) {
  61. $alterParam = $retValIfParamEmptyOrNotExists;
  62. }
  63. return ($alterParam);
  64. }
  65. /**
  66. * Loads UserStats OPENPAYZ config "opayz.ini" to private opayzCfg prop
  67. *
  68. * @return void
  69. */
  70. protected function loadOpayzCfg() {
  71. $this->opayzCfg = parse_ini_file(self::OPAYZ_CONFIG_PATH);
  72. }
  73. /**
  74. * Getter for private opayzCfg prop
  75. *
  76. * @return array
  77. */
  78. public function getOpayzCfg() {
  79. return ($this->opayzCfg);
  80. }
  81. /**
  82. * Loads UserStats TARIFF_MATRIX config "tariffmatrix.ini" to private tariffmatrixCfg prop
  83. *
  84. * @return void
  85. */
  86. protected function loadTariffMatrixCfg() {
  87. $this->tariffmatrixCfg = parse_ini_file(self::TARIFF_MATRIX_CONFIG_PATH);
  88. }
  89. /**
  90. * Getter for private tariffmatrixCfg prop
  91. *
  92. * @return array
  93. */
  94. public function getTariffMatrixCfg() {
  95. return ($this->tariffmatrixCfg);
  96. }
  97. }