Esempio n. 1
0
 /**
  * load the configuration of jelix-scripts
  * @param string $appname the application name
  * @return JelixScriptCommandConfig
  */
 static function loadConfig($appname = '')
 {
     $config = new JelixScriptCommandConfig();
     if ($appname == '') {
         $appname = $config->loadFromProject();
     }
     $home = '';
     if (isset($_SERVER['HOME'])) {
         $home = $_SERVER['HOME'];
     } else {
         if (isset($_ENV['HOME'])) {
             $home = $_ENV['HOME'];
         } else {
             if (isset($_SERVER['USERPROFILE'])) {
                 // windows
                 $home = $_SERVER['USERPROFILE'];
             } else {
                 if (isset($_SERVER['HOMEDRIVE']) && isset($_SERVER['HOMEPATH'])) {
                     // windows
                     $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
                 }
             }
         }
     }
     if ($home) {
         if (file_exists($home . DIRECTORY_SEPARATOR . '.jelix-scripts.ini')) {
             $config->loadFromIni($home . DIRECTORY_SEPARATOR . '.jelix-scripts.ini', $appname);
         } else {
             $config->loadFromIni($home . DIRECTORY_SEPARATOR . 'jelix-scripts.ini', $appname);
         }
         // windows users doesn't often use dot files.
     }
     self::$debugMode = $config->debugMode;
     if (function_exists('date_default_timezone_set')) {
         date_default_timezone_set($config->infoTimezone);
     }
     $config->appName = $appname;
     return $config;
 }
Esempio n. 2
0
 /**
  * load the configuration of jelix-scripts
  * @param string $appname the application name
  * @return JelixScriptCommandConfig
  */
 static function loadConfig($appname = '')
 {
     $config = new JelixScriptCommandConfig();
     if ($appname === '') {
         $appname = $config->loadFromProject();
     } else {
         if ($appname === false) {
             // don't load from project..
             $appname = '';
         }
     }
     // try to find a .jelix-scripts.ini in the current directory or parent directories
     $dir = getcwd();
     $found = false;
     do {
         if (file_exists($dir . DIRECTORY_SEPARATOR . '.jelix-scripts.ini')) {
             $config->loadFromIni($dir . DIRECTORY_SEPARATOR . '.jelix-scripts.ini', $appname);
             $found = true;
         } else {
             if (file_exists($dir . DIRECTORY_SEPARATOR . 'jelix-scripts.ini')) {
                 $config->loadFromIni($dir . DIRECTORY_SEPARATOR . 'jelix-scripts.ini', $appname);
                 // windows users don't often use dot files.
                 $found = true;
             }
         }
         $previousdir = $dir;
         $dir = dirname($dir);
     } while ($dir != '.' && $dir != $previousdir && !$found);
     // we didn't find a .jelix-scripts, try to read one from the home directory
     if (!$found) {
         $home = '';
         if (isset($_SERVER['HOME'])) {
             $home = $_SERVER['HOME'];
         } else {
             if (isset($_ENV['HOME'])) {
                 $home = $_ENV['HOME'];
             } else {
                 if (isset($_SERVER['USERPROFILE'])) {
                     // windows
                     $home = $_SERVER['USERPROFILE'];
                 } else {
                     if (isset($_SERVER['HOMEDRIVE']) && isset($_SERVER['HOMEPATH'])) {
                         // windows
                         $home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
                     }
                 }
             }
         }
         if ($home) {
             if (file_exists($home . DIRECTORY_SEPARATOR . '.jelix-scripts.ini')) {
                 $config->loadFromIni($home . DIRECTORY_SEPARATOR . '.jelix-scripts.ini', $appname);
             } else {
                 $config->loadFromIni($home . DIRECTORY_SEPARATOR . 'jelix-scripts.ini', $appname);
             }
             // windows users don't often use dot files.
         }
     }
     self::$debugMode = $config->debugMode;
     if (function_exists('date_default_timezone_set')) {
         date_default_timezone_set($config->infoTimezone);
     }
     $config->appName = $appname;
     return $config;
 }