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