Example #1
0
 /**
  * Setup the settings file
  *
  * @return void
  */
 public static function setupSettings($settingsFile)
 {
     // Now get the settings file and parse it
     $configArray = File::parseIni($settingsFile);
     // Check to see if there is a valid config which matches
     // the SERVER_NAME and check that its not CLI mode
     if (php_sapi_name() != 'cli') {
         if (!isset($configArray[$_SERVER['SERVER_NAME']])) {
             throw new Exception\BasicException('There is no configuration for this server name');
         } else {
             $configArray = $configArray[$_SERVER['SERVER_NAME']];
         }
     } else {
         if (isset($configArray['console'])) {
             $configArray = $configArray['console'];
         } else {
             throw new Exception\BasicException('There is no configuration for console applications');
         }
     }
     // Create an object full of the settings variables
     // Supports up to 2 levels of recursion for creating
     // objects, after that the values will be stored in
     // arrays. E.g:
     // $settings->val->something['and']['another']
     $settings = new \StdClass();
     // Depth: 1
     foreach ($configArray as $setting => $value) {
         if (is_array($value)) {
             $valClass = new \StdClass();
             // Depth: 2
             foreach ($value as $key => $val) {
                 $valClass->{$key} = $val;
             }
             $value = $valClass;
         }
         // Finally assign all settings
         $settings->{$setting} = $value;
     }
     // Settings specific configuration options
     if (isset($settings->timezone)) {
         date_default_timezone_set($settings->timezone);
     } else {
         date_default_timezone_set('Europe/London');
     }
     // Add all neccessary variables to the Registry for later use and return
     // settings to avoid not using Dependency Injection
     Registry::set('settings', $settings);
     return $settings;
 }