Home >Backend Development >PHP Tutorial >PHP configuration file processing class code

PHP configuration file processing class code

WBOY
WBOYOriginal
2016-07-25 08:54:201146browse
  1. /*
  2. * 来源: http://www.xuehuwang.com/
  3. * 作者: 雪狐博客
  4. * 应用: 用于处理配置数据
  5. * 搜集整理:bbs.it-home.org
  6. **/
  7. final class Config {
  8. private $data = array();
  9. public function get($key) {
  10. return (isset($this->data[$key]) ? $this->data[$key] : NULL);
  11. }
  12. public function set($key, $value) {
  13. $this->data[$key] = $value;
  14. }
  15. public function has($key) {
  16. return isset($this->data[$key]);
  17. }
  18. public function load($filename) {
  19. $file = DIR_CONFIG . $filename . '.php';
  20. if (file_exists($file)) {
  21. $cfg = array();
  22. require($file);
  23. $this->data = array_merge($this->data, $cfg);
  24. } else {
  25. exit('Error: Could not load config ' . $filename . '!');
  26. }
  27. }
  28. }
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn