You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.4 KiB
PHP
104 lines
3.4 KiB
PHP
<?php
|
|
|
|
class Configuration {
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* ! WARNING !
|
|
*
|
|
* Those are default values, if you need to change them for a particular host,
|
|
* please just create a file named 'configuration.local.php' in the same directory
|
|
* and redefine the values there !
|
|
*
|
|
* This file must contain an array named $configuration containing the keys you
|
|
* want to redefine. Then, those values will be used to replace those in the
|
|
* array defined just below.
|
|
*
|
|
* @var array configuration values
|
|
*/
|
|
private $values = array(
|
|
'db' => 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' => '',
|
|
'result_count' => 10,
|
|
),
|
|
'log' => array(
|
|
'file' => 'C:\inetpub\wwwroot\WebService\logs\log.txt',
|
|
// The greater the verbosity, the more is displayed
|
|
// 0 : no log at all
|
|
// 1 : log function calls and errors
|
|
// 2 : log parameters and sent data
|
|
'verbosity' => 0,
|
|
),
|
|
'session' => array(
|
|
'save_path' => ''
|
|
),
|
|
|
|
'checkfile_url' => '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)) {
|
|
require_once($this->custom_config);
|
|
|
|
if(! isset($configuration) || ! 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);
|
|
}
|
|
}
|