Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/env/PhabricatorEnv.php
| Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | final class PhabricatorEnv { | ||||
| private static function initializeCommonEnvironment() { | private static function initializeCommonEnvironment() { | ||||
| PhutilErrorHandler::initialize(); | PhutilErrorHandler::initialize(); | ||||
| self::buildConfigurationSourceStack(); | self::buildConfigurationSourceStack(); | ||||
| // Force a valid timezone. If both PHP and Phabricator configuration are | // Force a valid timezone. If both PHP and Phabricator configuration are | ||||
| // invalid, use UTC. | // invalid, use UTC. | ||||
| $tz = PhabricatorEnv::getEnvConfig('phabricator.timezone'); | $tz = self::getEnvConfig('phabricator.timezone'); | ||||
| if ($tz) { | if ($tz) { | ||||
| @date_default_timezone_set($tz); | @date_default_timezone_set($tz); | ||||
| } | } | ||||
| $ok = @date_default_timezone_set(date_default_timezone_get()); | $ok = @date_default_timezone_set(date_default_timezone_get()); | ||||
| if (!$ok) { | if (!$ok) { | ||||
| date_default_timezone_set('UTC'); | date_default_timezone_set('UTC'); | ||||
| } | } | ||||
| // Prepend '/support/bin' and append any paths to $PATH if we need to. | // Prepend '/support/bin' and append any paths to $PATH if we need to. | ||||
| $env_path = getenv('PATH'); | $env_path = getenv('PATH'); | ||||
| $phabricator_path = dirname(phutil_get_library_root('phabricator')); | $phabricator_path = dirname(phutil_get_library_root('phabricator')); | ||||
| $support_path = $phabricator_path.'/support/bin'; | $support_path = $phabricator_path.'/support/bin'; | ||||
| $env_path = $support_path.PATH_SEPARATOR.$env_path; | $env_path = $support_path.PATH_SEPARATOR.$env_path; | ||||
| $append_dirs = PhabricatorEnv::getEnvConfig('environment.append-paths'); | $append_dirs = self::getEnvConfig('environment.append-paths'); | ||||
| if (!empty($append_dirs)) { | if (!empty($append_dirs)) { | ||||
| $append_path = implode(PATH_SEPARATOR, $append_dirs); | $append_path = implode(PATH_SEPARATOR, $append_dirs); | ||||
| $env_path = $env_path.PATH_SEPARATOR.$append_path; | $env_path = $env_path.PATH_SEPARATOR.$append_path; | ||||
| } | } | ||||
| putenv('PATH='.$env_path); | putenv('PATH='.$env_path); | ||||
| // Write this back into $_ENV, too, so ExecFuture picks it up when creating | // Write this back into $_ENV, too, so ExecFuture picks it up when creating | ||||
| // subprocess environments. | // subprocess environments. | ||||
| $_ENV['PATH'] = $env_path; | $_ENV['PATH'] = $env_path; | ||||
| // If an instance identifier is defined, write it into the environment so | // If an instance identifier is defined, write it into the environment so | ||||
| // it's available to subprocesses. | // it's available to subprocesses. | ||||
| $instance = PhabricatorEnv::getEnvConfig('cluster.instance'); | $instance = self::getEnvConfig('cluster.instance'); | ||||
| if (strlen($instance)) { | if (strlen($instance)) { | ||||
| putenv('PHABRICATOR_INSTANCE='.$instance); | putenv('PHABRICATOR_INSTANCE='.$instance); | ||||
| $_ENV['PHABRICATOR_INSTANCE'] = $instance; | $_ENV['PHABRICATOR_INSTANCE'] = $instance; | ||||
| } | } | ||||
| PhabricatorEventEngine::initialize(); | PhabricatorEventEngine::initialize(); | ||||
| // TODO: Add a "locale.default" config option once we have some reasonable | // TODO: Add a "locale.default" config option once we have some reasonable | ||||
| // defaults which aren't silly nonsense. | // defaults which aren't silly nonsense. | ||||
| self::setLocaleCode('en_US'); | self::setLocaleCode('en_US'); | ||||
| } | } | ||||
| public static function setLocaleCode($locale_code) { | public static function setLocaleCode($locale_code) { | ||||
| if ($locale_code == self::$localeCode) { | if ($locale_code == self::$localeCode) { | ||||
| return; | return; | ||||
| } | } | ||||
| try { | try { | ||||
| $locale = PhutilLocale::loadLocale($locale_code); | $locale = PhutilLocale::loadLocale($locale_code); | ||||
| $translations = PhutilTranslation::getTranslationMapForLocale( | $translations = PhutilTranslation::getTranslationMapForLocale( | ||||
| $locale_code); | $locale_code); | ||||
| $override = PhabricatorEnv::getEnvConfig('translation.override'); | $override = self::getEnvConfig('translation.override'); | ||||
| if (!is_array($override)) { | if (!is_array($override)) { | ||||
| $override = array(); | $override = array(); | ||||
| } | } | ||||
| PhutilTranslator::getInstance() | PhutilTranslator::getInstance() | ||||
| ->setLocale($locale) | ->setLocale($locale) | ||||
| ->setTranslations($override + $translations); | ->setTranslations($override + $translations); | ||||
| Show All 22 Lines | private static function buildConfigurationSourceStack() { | ||||
| $stack->pushSource( | $stack->pushSource( | ||||
| id(new PhabricatorConfigLocalSource()) | id(new PhabricatorConfigLocalSource()) | ||||
| ->setName(pht('Local Config'))); | ->setName(pht('Local Config'))); | ||||
| // If the install overrides the database adapter, we might need to load | // If the install overrides the database adapter, we might need to load | ||||
| // the database adapter class before we can push on the database config. | // the database adapter class before we can push on the database config. | ||||
| // This config is locked and can't be edited from the web UI anyway. | // This config is locked and can't be edited from the web UI anyway. | ||||
| foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) { | foreach (self::getEnvConfig('load-libraries') as $library) { | ||||
| phutil_load_library($library); | phutil_load_library($library); | ||||
| } | } | ||||
| // If custom libraries specify config options, they won't get default | // If custom libraries specify config options, they won't get default | ||||
| // values as the Default source has already been loaded, so we get it to | // values as the Default source has already been loaded, so we get it to | ||||
| // pull in all options from non-phabricator libraries now they are loaded. | // pull in all options from non-phabricator libraries now they are loaded. | ||||
| $default_source->loadExternalOptions(); | $default_source->loadExternalOptions(); | ||||
| ▲ Show 20 Lines • Show All 614 Lines • ▼ Show 20 Lines | if (!$address) { | ||||
| 'Unable to test remote address against cluster whitelist: '. | 'Unable to test remote address against cluster whitelist: '. | ||||
| 'REMOTE_ADDR is not defined.')); | 'REMOTE_ADDR is not defined.')); | ||||
| } | } | ||||
| return self::isClusterAddress($address); | return self::isClusterAddress($address); | ||||
| } | } | ||||
| public static function isClusterAddress($address) { | public static function isClusterAddress($address) { | ||||
| $cluster_addresses = PhabricatorEnv::getEnvConfig('cluster.addresses'); | $cluster_addresses = self::getEnvConfig('cluster.addresses'); | ||||
| if (!$cluster_addresses) { | if (!$cluster_addresses) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| 'Phabricator is not configured to serve cluster requests. '. | 'Phabricator is not configured to serve cluster requests. '. | ||||
| 'Set `cluster.addresses` in the configuration to whitelist '. | 'Set `cluster.addresses` in the configuration to whitelist '. | ||||
| 'cluster hosts before sending requests that use a cluster '. | 'cluster hosts before sending requests that use a cluster '. | ||||
| 'authentication mechanism.')); | 'authentication mechanism.')); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines | |||||