Config.class.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Config class
  4. *
  5. * Reads, manipulate configs
  6. *
  7. * @author vesta, http://vestacp.com/
  8. * @author Dmitry Malishev <dima.malishev@gmail.com>
  9. * @copyright vesta 2010-2011
  10. */
  11. class Config
  12. {
  13. protected $_config = array();
  14. static public $instance = null;
  15. /**
  16. * Config constructor
  17. *
  18. */
  19. public function __construct()
  20. {
  21. $this->_config = parse_ini_file(V_ROOT_DIR.'config'.DIRECTORY_SEPARATOR.'vesta_config.ini');
  22. }
  23. /**
  24. * get config parameter
  25. *
  26. * @param string $key
  27. * @return mixed
  28. */
  29. public function getParameter($key)
  30. {
  31. return isset($this->_config[$key]) ? $this->_config[$key] : false;
  32. }
  33. /**
  34. * Grab current instance or create it
  35. *
  36. * @return Config
  37. */
  38. static public function getInstance($request = null)
  39. {
  40. return null == self::$instance ? self::$instance = new self() : self::$instance;
  41. }
  42. /**
  43. * Shortcut method: get config parameter
  44. *
  45. * @param string $key
  46. * @return mixed
  47. */
  48. static public function get($key)
  49. {
  50. $ref = self::getInstance();
  51. return $ref->getParameter($key);
  52. }
  53. }