PHP configuration file processing class code

WBOY
Release: 2016-07-25 08:54:20
Original
1114 people have browsed it
  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. }
复制代码


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template