Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Trida pro nacteni dat z konfiguracniho souboru
- */
- class webConfigData {
- /*
- MySQL Data
- */
- public static $localhost = "";
- public static $username = "kapa";
- public static $password = "";
- /**
- * Funkce nacitajici konfiguracni soubor
- * param $configfile
- * return void
- **/
- public function __construct() {
- $this->loadConfigData();
- }
- public function loadConfigData($configfile = "configs/config.ini") {
- $configContent = file_get_contents($configfile);
- $leArray = array(
- "localhost" => $this->varEndPosition("localhost", $configContent),
- "username" => $this->varEndPosition("username", $configContent),
- "password" => $this->varEndPosition("password", $configContent),
- );
- for ($i = 0; ($configContent[$i] != NULL); $i++) {
- // Ignoruj komentar, tj radek s #
- if($configContent[$i] == '#')
- while($configContent[$i] != "\n")
- $i++;
- if(in_array($i, $leArray)) {
- $temp = $i;
- // Ceka na znak "="
- while($configContent[$i - 1] != '=') $i++;
- // Ceka na libovolny znak
- while(!ctype_graph($configContent[$i]) &&
- $configContent[$i] != "\n")
- $i++;
- // Uklada znaky jako hodnotu do pole
- while($configContent[$i] != "\n") {
- $outArray[$temp] .= $configContent[$i];
- $i++;
- }
- }
- }
- self::$localhost = $outArray[$leArray["localhost"]];
- self::$username = $outArray[$leArray["username"]];
- self::$password = $outArray[$leArray["password"]];
- }
- private function varEndPosition($posVar, $configContent) {
- return strpos($configContent, $posVar) +
- strlen(strpos($configContent, $posVar));
- }
- }
Add Comment
Please, Sign In to add comment