Esempio n. 1
0
 /**
  * Create config.
  *
  * @param string $cwd
  *
  * @return Config
  */
 public static function createConfig($cwd = NULL)
 {
     $cwd = $cwd ?: getcwd();
     // determine home and cache dirs
     $home = $cwd;
     // self::getHomeDir();
     $cacheDir = self::getCacheDir($home);
     // protect directory against web access. Since HOME could be
     // the www-data's user home and be web-accessible it is a
     // potential security risk
     foreach ([$home, $cacheDir] as $dir) {
         if (!file_exists($dir . '/.htaccess')) {
             if (!is_dir($dir)) {
                 @mkdir($dir, 0777, TRUE);
             }
             @file_put_contents($dir . '/.htaccess', 'Deny from all');
         }
     }
     $settings = json_decode(file_get_contents(Factory::getSlicerFile()), TRUE);
     $settings['home'] = $home;
     $settings['cache-dir'] = $cacheDir;
     $settings['cwd'] = $cwd;
     if ('' === $settings['base-dir']) {
         $settings['base-dir'] = $cwd;
     }
     $config = new Config($settings);
     return $config;
 }