array( 'driver' => 'SQL Server Native Client 11.0', 'server' => 'BSR2012\SQLEXPRESS', 'port' => '1433', 'username' => 'alcoda', 'password' => 'alcodaonly', 'name' => 'NetBiblio3', ), 'solr' => array( 'server' => '192.168.1.250', 'port' => '8983', 'username' => '', 'password' => '', 'path' => 'solr/bsr1', 'result_count' => 10, ), 'log' => array( 'file' => 'C:\inetpub\wwwroot\WebService\logs\log.txt', 'format' => '%ip% - [%date%] - %status% %error% - %time% - %func%', // The greater the verbosity, the more is displayed // 0 : no log at all // 1 : log summary // 2 : log response 'verbosity' => 0, ), 'session' => array( 'save_path' => '' ), 'checkfile_url' => 'http://medias.bibliothequesonore.ch/checkfile.php?', 'checkfile_url_old' => 'http://fichiers.bibliothequesonore.ch/checkfile.php?', 'netbiblio_worker_id' => 45, 'www_employee_id' => 45, 'www_library_id' => 2, ); private $custom_config = 'configuration.local.php'; private function __construct() { // by default, set the session save path to the default value; $this->values['session']['save_path'] = session_save_path(); if(!file_exists($this->custom_config)) { throw new \Exception\UsageException('No configuration.local.php file was found. Create it with the proper config.'); } $configuration = include_once $this->custom_config; if(!is_array($configuration)) { throw new \RuntimeException("You custom configuration in '{$this->custom_config}' must be in a variable named '\$configuration' and be an array."); } $this->values = array_replace_recursive($this->values, $configuration); } private function dotNotationAccess($data, $key, $default=null) { $keys = explode('.', $key); foreach ($keys as $k) { if (!is_array($data)) { throw new \Exception("Try to access non-array as array, key '$key''"); } if (!isset($data[$k])) { return $default; } $data = $data[$k]; } return $data; } private function value($name, $default) { return $this->dotNotationAccess($this->values, $name, $default); } /** * @param $name * @param mixed $default the default value for your configuration option * @return mixed return the configuration value if the key is find, the default otherwise */ public static function get($name, $default = null) { if(is_null(self::$instance)) { self::$instance = new Configuration(); } return self::$instance->value($name, $default); } }