Advertisement
Guest User

Boduch™

a guest
Aug 31st, 2012
2,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. /**
  2.  * Wyjatek generowany w przypadku niemoznosci odnalezenia pliku konfiguracyjnego
  3.  */
  4. class ConfigFileNotFoundException extends Exception
  5. {
  6.     function __construct($message, $code = 0)
  7.     {
  8.         parent::__construct($message, $code);
  9.  
  10.         echo "<p><b>Config file not found</b></p>";
  11.     }
  12. }
  13.  
  14. // ...
  15.  
  16.     /**
  17.      * Metoda realizuje pobranie konfiguracji projektu z pliku XML
  18.      * @param string $cfg Nazwa pliku konfiguracyjnego (bez sciezki)
  19.      */
  20.     function load($cfg)
  21.     {
  22.         try
  23.         {
  24.             if (!file_exists($cfg))
  25.             {
  26.                 throw new ConfigFileNotFoundException("Could not find {$cfg} file");
  27.             }
  28.             $config = $this->toArray(simplexml_load_file($cfg));           
  29.         }
  30.         catch (ConfigFileNotFoundException $e)
  31.         {
  32.             echo $e->getMessage() . "<br />\n";
  33.             echo "Should be on: {$cfg} \n";
  34.             exit;
  35.         }
  36.         return $config;
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement