Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Settings
- {
- private static $instance;
- private $ini_settings = array();
- const database_host = 'localhost';
- const database_user = 'root';
- const database_pass = '';
- const database_name = 'savory';
- private function __construct() {
- try {
- $path_parts = pathinfo(__FILE__);
- $file = file_exists($path_parts['dirname'].'\settings.ini');
- if ($file === false) { throw new Exception('INI file not found'); }
- //parse the ini file
- $ini_array = parse_ini_file($path_parts['dirname'].'\settings.ini', true);
- //need to check for an empty array PHP < 5.2.7 and false PHP > 5.2.7
- if (empty($ini_array) OR $ini_array == false) {
- Throw new Exception('Error loading ini file');
- }
- $this->ini_settings = $ini_array;
- } catch(Exception $e) {
- echo 'Caught Exception: ', $e->getMessage();
- exit();
- }
- }
- // The singleton method
- public static function instance()
- {
- if (!(self::$instance instanceof self)) {
- self::$instance = new Settings();
- }
- return self::$instance;
- }
- public function database_settings()
- {
- $db = array(
- 'database_host' => self::database_host,
- 'database_user' => self::database_user,
- 'database_pass' => self::database_pass,
- 'database_name' => self::database_name
- );
- return $db;
- }
- public function settings() {
- return $this->ini_settings;
- }
- public function __clone()
- {
- throw new Exception('Clone is not allowed on singleton class');
- }
- }
- $ini_array = Settings::instance()->settings();
- ?>
- ; Savory configuration file
- ;
- ; Best to save this file outside the accessible folders
- ; database user / password stored in settings.php
- [savory]
- database = "mysql"
- session = "database"
- auth = "keys"
- [smarty]
- cache = "E:\xampplite\htdocs\modules\Smarty-2.6.26\cache"
- compile = "E:\xampplite\htdocs\modules\Smarty-2.6.26templates_c"
- config = "E:\xampplite\htdocs\modules\Smarty-2.6.26\configs"
- templates = "E:\xampplite\htdocs\modules\Smarty-2.6.26\templates\savory"
Add Comment
Please, Sign In to add comment