|
| 1 | +<?php |
| 2 | + |
| 3 | +function phabricator_read_config_file($original_config) { |
| 4 | + |
| 5 | + $root = dirname(dirname(__FILE__)); |
| 6 | + |
| 7 | + // Accept either "myconfig" (preferred) or "myconfig.conf.php". |
| 8 | + $config = preg_replace('/\.conf\.php$/', '', $original_config); |
| 9 | + $full_config_path = $root.'/conf/'.$config.'.conf.php'; |
| 10 | + |
| 11 | + if (!Filesystem::pathExists($full_config_path)) { |
| 12 | + |
| 13 | + // These are very old configuration files which we used to ship with |
| 14 | + // by default. File based configuration was de-emphasized once web-based |
| 15 | + // configuration was built. The actual files were removed to reduce |
| 16 | + // user confusion over how to configure Phabricator. |
| 17 | + |
| 18 | + switch ($config) { |
| 19 | + case 'default': |
| 20 | + case 'production': |
| 21 | + return array(); |
| 22 | + case 'development': |
| 23 | + return array( |
| 24 | + 'phabricator.developer-mode' => true, |
| 25 | + 'darkconsole.enabled' => true, |
| 26 | + 'celerity.minify' => false, |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + $files = id(new FileFinder($root.'/conf/')) |
| 31 | + ->withType('f') |
| 32 | + ->withSuffix('conf.php') |
| 33 | + ->withFollowSymlinks(true) |
| 34 | + ->find(); |
| 35 | + |
| 36 | + foreach ($files as $key => $file) { |
| 37 | + $file = trim($file, './'); |
| 38 | + $files[$key] = preg_replace('/\.conf\.php$/', '', $file); |
| 39 | + } |
| 40 | + $files = " ".implode("\n ", $files); |
| 41 | + |
| 42 | + throw new Exception( |
| 43 | + "CONFIGURATION ERROR\n". |
| 44 | + "Config file '{$original_config}' does not exist. Valid config files ". |
| 45 | + "are:\n\n".$files); |
| 46 | + } |
| 47 | + |
| 48 | + // Make sure config file errors are reported. |
| 49 | + $old_error_level = error_reporting(E_ALL | E_STRICT); |
| 50 | + $old_display_errors = ini_get('display_errors'); |
| 51 | + ini_set('display_errors', 1); |
| 52 | + |
| 53 | + ob_start(); |
| 54 | + $conf = include $full_config_path; |
| 55 | + $errors = ob_get_clean(); |
| 56 | + |
| 57 | + error_reporting($old_error_level); |
| 58 | + ini_set('display_errors', $old_display_errors); |
| 59 | + |
| 60 | + if ($conf === false) { |
| 61 | + throw new Exception("Failed to read config file '{$config}': {$errors}"); |
| 62 | + } |
| 63 | + |
| 64 | + return $conf; |
| 65 | +} |
0 commit comments