variables = NULL; $this->variables_count = 0; if ($file_url==""){ $this->config_file_name= NULL; $this->config_file_handle = NULL; } else{ $this->openConfigFile($file_url); $this->config_file_name=$file_url; } } /** * Opens configuration file. * $file_url must by supplied if it wasn't supplied before (in constructor or in earlier call if this method) * @param string $file_url - url of configuration file. * @return - true/false */ function openConfigFile($file_url=""){ if($file_url==""){ $file_url = $this->config_file_name; } if($file_url){ $F = fopen($file_url, "r") or die("configParserClass (file '".__FILE__."'; line ".__LINE__."):: Nepavyko atidaryti failo '$file_url'"); $this->config_file_handle = $F; $this->config_file_name=$file_url; return true; } else{ die("configParserClass (file '".__FILE__."'; line ".__LINE__."):: Nezinomas failo vardas"); } return false; } /* * Returns all variables from configuration file. * @return - Array with variables: [var_name]=var_value */ function getAllVariables(){ if($this->variables == NULL) $this->readVariables(); return $this->variables; } /* * Closes configuration file. * @return - true on success. */ function closeConfigFile(){ if($this->config_file_handle){ fclose($this->config_file_handle) or die("configParserClass (file '".__FILE__."'; line ".__LINE__."):: Nepavyko u´┐Żdaryti failo"); $this->config_file_handle = NULL; return true; } } /* * Reads variables from configuration file. * @return - frue/false */ function readVariables(){ if(!$this->config_file_handle) $this->openConfigFile(); $this->variables = Array(); while (!feof ($this->config_file_handle)) { $buffer = fgets($this->config_file_handle, 1024); if(preg_match("/\s*[$]{1}([_a-zA-Z][_a-zA-Z0-9]*)\s=\s\"?([^\"]+)\"?\s*;(.*)/", $buffer, $vars)){ $this->variables[$vars[1]] = $vars[2]; $this->variables_coment[$vars[1]] =$vars[3]; } } $this->variables_count = count($this->variables); return true; } /* * Makes constants from variables * @return - true/false */ function parseConfig(){ if(!$this->variables_count) $this->readVariables(); foreach ($this->variables AS $name=>$value){ eval("define('".$name."','".addslashes($value)."');"); } $this->closeConfigFile(); return true; } /** * parses file and returns array * @param $file - full path to config file * @return array **/ function makeArray( $file ){ $this->openConfigFile($file); $this->readVariables(); return $this->getAllVariables(); } /** * class ends **/ } ?> unable to find init config file or config parser class