XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
IniHandler.class.php
1<?php
12
14 /*** string[] ***/
15 protected $_mConfig = [];
16 /*** string ***/
17 protected $_mFilePath;
18 /*** bool ***/
19 protected $_mSectionFlag = false;
20
29 public function __construct( /*** string ***/ $filePath, /*** bool ***/ $section = false ) {
30 $this->_mSectionFlag = $section;
31 $this->_mFilePath = $filePath;
32 $this->_loadIni();
33 }
34
42 protected function _loadIni() {
43 if ( file_exists( $this->_mFilePath ) ) {
44 $key = null;
45 foreach ( explode( "\n", file_get_contents( $this->_mFilePath ) ) as $line ) {
46 //case: comment line
47 if ( preg_match( '/^\s*([;#]|\/\/)/', $line ) ) {
48 continue;
49 }
50 //remove CR
51 $line = preg_replace( '/\r/', '', $line );
52 //case: section line
53 if ( preg_match( '/\[(.*)\]/', $line, $str ) ) {
54 if ( true === $this->_mSectionFlag ) {
55 $key = $str[1];
56 $this->_mConfig[ $key ] = [];
57 }
58 } //case: key/value line
59 elseif ( preg_match( '/^(.*)=(.*)$/', $line, $str ) ) {
60 $name =& $str[1];
61 $val =& $str[2];
62 if ( preg_match( '/^"(.*)"$/', $val, $body ) || preg_match( '/^\'(.*)\'$/', $val, $body ) ) {
63 $val =& $body[1];
64 }
65
66 if ( true === $this->_mSectionFlag ) {
67 $this->_mConfig[ $key ][ $name ] = $val;
68 } else {
69 $this->_mConfig[ $name ] = $val;
70 }
71 }
72 }
73 }
74 }
75
84 public function getConfig( /*** string ***/ $key, /*** string ***/ $section = '' ) {
85 if ( true === $this->_mSectionFlag ) {
86 return $this->_mConfig[ $section ][ $key ];
87 }
88
89 return $this->_mConfig[ $key ];
90 }
91
99 public function getSectionConfig( /*** string ***/ $section ) {
100 return ( true === $this->_mSectionFlag ) ? $this->_mConfig[ $section ] : null;
101 }
102
110 public function getAllConfig() {
111 return $this->_mConfig;
112 }
113}
__construct($filePath, $section=false)
getConfig($key, $section='')