Guest User

Untitled

a guest
Aug 27th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. /*
  2.     Trida pro nacteni dat z konfiguracniho souboru
  3. */
  4.     class webConfigData {
  5.         /*
  6.         MySQL Data
  7.         */
  8.             public static $localhost = "";
  9.             public static $username = "kapa";
  10.             public static $password = "";  
  11.        
  12.             /**
  13.              * Funkce nacitajici konfiguracni soubor
  14.              * param $configfile
  15.              * return void
  16.             **/
  17.            
  18.             public function __construct()   {
  19.                    
  20.                     $this->loadConfigData();   
  21.             }
  22.            
  23.             public function loadConfigData($configfile = "configs/config.ini")  {
  24.                    
  25.                 $configContent = file_get_contents($configfile);
  26.                    
  27.                 $leArray = array(
  28.                   "localhost"   =>   $this->varEndPosition("localhost", $configContent),
  29.                   "username"    =>   $this->varEndPosition("username", $configContent),
  30.                   "password"    =>   $this->varEndPosition("password", $configContent),                                            
  31.                                 );
  32.  
  33.                 for ($i = 0; ($configContent[$i] != NULL); $i++)    {
  34.                    
  35.                     // Ignoruj komentar, tj radek s #
  36.                     if($configContent[$i] == '#')
  37.                         while($configContent[$i] != "\n")  
  38.                             $i++;
  39.                     if(in_array($i, $leArray))  {
  40.                         $temp = $i;
  41.                         // Ceka na znak "="
  42.                         while($configContent[$i - 1] != '=') $i++;
  43.                         // Ceka na libovolny znak
  44.                         while(!ctype_graph($configContent[$i]) &&
  45.                               $configContent[$i] != "\n")
  46.                             $i++;
  47.                         // Uklada znaky jako hodnotu do pole
  48.                         while($configContent[$i] != "\n")   {
  49.                             $outArray[$temp] .= $configContent[$i];
  50.                             $i++;
  51.                         }
  52.                     }
  53.                 }
  54.                    
  55.                 self::$localhost    = $outArray[$leArray["localhost"]];
  56.                 self::$username     = $outArray[$leArray["username"]];
  57.                 self::$password     = $outArray[$leArray["password"]];
  58.             }
  59.            
  60.             private function varEndPosition($posVar, $configContent)    {
  61.                 return strpos($configContent, $posVar) +
  62.                 strlen(strpos($configContent, $posVar));   
  63.             }
  64.     }
Add Comment
Please, Sign In to add comment