1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-05 12:21:02 +01:00

getConfigEnv fails fast when key is not found and no default value is given.

Summary:
T2345
getConfig throws an Exception when the key does not exist.
Also removes dead code that throws an Exception.

Test Plan:
Reloaded the Phabricator home page.  In the process, found
2 Exceptions thrown due to nonexistent keys.  After addressing these problems,
the home page loads without Exceptions.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4541
This commit is contained in:
Nick Pellegrino 2013-01-19 12:11:11 -08:00 committed by epriestley
parent 06bca93b47
commit 3e6fa43658
13 changed files with 29 additions and 53 deletions

View file

@ -41,7 +41,7 @@ final class PhabricatorConfigOption
} }
return idx( return idx(
PhabricatorEnv::getEnvConfig('config.mask', array()), PhabricatorEnv::getEnvConfig('config.mask'),
$this->getKey(), $this->getKey(),
false); false);
} }
@ -57,7 +57,7 @@ final class PhabricatorConfigOption
} }
return idx( return idx(
PhabricatorEnv::getEnvConfig('config.hide', array()), PhabricatorEnv::getEnvConfig('config.hide'),
$this->getKey(), $this->getKey(),
false); false);
} }
@ -77,7 +77,7 @@ final class PhabricatorConfigOption
} }
return idx( return idx(
PhabricatorEnv::getEnvConfig('config.lock', array()), PhabricatorEnv::getEnvConfig('config.lock'),
$this->getKey(), $this->getKey(),
false); false);
} }

View file

@ -127,6 +127,9 @@ final class PhabricatorCoreConfigOptions
$this->newOption('phabricator.setup', 'bool', false) $this->newOption('phabricator.setup', 'bool', false)
->setLocked(true) ->setLocked(true)
->setDescription(pht('Internal / deprecated.')), ->setDescription(pht('Internal / deprecated.')),
$this->newOption('test.value', 'wild', null)
->setLocked(true)
->setDescription(pht('Unit test value.')),
); );
} }

View file

@ -562,11 +562,11 @@ final class DifferentialRevisionViewController extends DifferentialController {
$status = $revision->getStatus(); $status = $revision->getStatus();
$allow_self_accept = PhabricatorEnv::getEnvConfig( $allow_self_accept = PhabricatorEnv::getEnvConfig(
'differential.allow-self-accept', false); 'differential.allow-self-accept');
$always_allow_close = PhabricatorEnv::getEnvConfig( $always_allow_close = PhabricatorEnv::getEnvConfig(
'differential.always-allow-close', false); 'differential.always-allow-close');
$allow_reopen = PhabricatorEnv::getEnvConfig( $allow_reopen = PhabricatorEnv::getEnvConfig(
'differential.allow-reopen', false); 'differential.allow-reopen');
if ($viewer_is_owner) { if ($viewer_is_owner) {
switch ($status) { switch ($status) {

View file

@ -99,11 +99,11 @@ final class DifferentialCommentEditor extends PhabricatorEditor {
$actor_phid = $actor->getPHID(); $actor_phid = $actor->getPHID();
$actor_is_author = ($actor_phid == $revision->getAuthorPHID()); $actor_is_author = ($actor_phid == $revision->getAuthorPHID());
$allow_self_accept = PhabricatorEnv::getEnvConfig( $allow_self_accept = PhabricatorEnv::getEnvConfig(
'differential.allow-self-accept', false); 'differential.allow-self-accept');
$always_allow_close = PhabricatorEnv::getEnvConfig( $always_allow_close = PhabricatorEnv::getEnvConfig(
'differential.always-allow-close', false); 'differential.always-allow-close');
$allow_reopen = PhabricatorEnv::getEnvConfig( $allow_reopen = PhabricatorEnv::getEnvConfig(
'differential.allow-reopen', false); 'differential.allow-reopen');
$revision_status = $revision->getStatus(); $revision_status = $revision->getStatus();
$revision->loadRelationships(); $revision->loadRelationships();
@ -652,7 +652,7 @@ final class DifferentialCommentEditor extends PhabricatorEditor {
$removed_reviewers = $this->getRemovedReviewers(); $removed_reviewers = $this->getRemovedReviewers();
$reviewer_phids = $revision->getReviewers(); $reviewer_phids = $revision->getReviewers();
$allow_self_accept = PhabricatorEnv::getEnvConfig( $allow_self_accept = PhabricatorEnv::getEnvConfig(
'differential.allow-self-accept', false); 'differential.allow-self-accept');
$reviewer_phids_map = array_fill_keys($reviewer_phids, true); $reviewer_phids_map = array_fill_keys($reviewer_phids, true);
foreach ($added_reviewers as $k => $user_phid) { foreach ($added_reviewers as $k => $user_phid) {

View file

@ -154,7 +154,7 @@ final class DifferentialCommentMail extends DifferentialMail {
$hunk_parser = new DifferentialHunkParser(); $hunk_parser = new DifferentialHunkParser();
if (PhabricatorEnv::getEnvConfig( if (PhabricatorEnv::getEnvConfig(
'metamta.differential.unified-comment-context', false)) { 'metamta.differential.unified-comment-context')) {
foreach ($changesets as $changeset) { foreach ($changesets as $changeset) {
$changeset->attachHunks($changeset->loadHunks()); $changeset->attachHunks($changeset->loadHunks());
} }
@ -176,7 +176,7 @@ final class DifferentialCommentMail extends DifferentialMail {
$inline_content = $inline->getContent(); $inline_content = $inline->getContent();
if (!PhabricatorEnv::getEnvConfig( if (!PhabricatorEnv::getEnvConfig(
'metamta.differential.unified-comment-context', false)) { 'metamta.differential.unified-comment-context')) {
$body[] = $this->formatText("{$file}:{$range} {$inline_content}"); $body[] = $this->formatText("{$file}:{$range} {$inline_content}");
} else { } else {
$body[] = "================"; $body[] = "================";

View file

@ -370,8 +370,7 @@ final class DifferentialChangesetParser {
if (!$generated_guess) { if (!$generated_guess) {
$generated_path_regexps = PhabricatorEnv::getEnvConfig( $generated_path_regexps = PhabricatorEnv::getEnvConfig(
'differential.generated-paths', 'differential.generated-paths');
array());
foreach ($generated_path_regexps as $regexp) { foreach ($generated_path_regexps as $regexp) {
if (preg_match($regexp, $this->changeset->getFilename())) { if (preg_match($regexp, $this->changeset->getFilename())) {
$generated_guess = true; $generated_guess = true;

View file

@ -258,8 +258,7 @@ final class DifferentialDiff extends DifferentialDAO {
->loadOneWhere('phid = %s', $this->getAuthorPHID()); ->loadOneWhere('phid = %s', $this->getAuthorPHID());
$use_emails = $use_emails =
PhabricatorEnv::getEnvConfig('differential.expose-emails-prudently', PhabricatorEnv::getEnvConfig('differential.expose-emails-prudently');
false);
switch ($this->getSourceControlSystem()) { switch ($this->getSourceControlSystem()) {
case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT: case PhabricatorRepositoryType::REPOSITORY_TYPE_GIT:

View file

@ -104,7 +104,7 @@ final class PhabricatorFeedStoryPublisher {
$this->sendNotification($chrono_key); $this->sendNotification($chrono_key);
} }
$uris = PhabricatorEnv::getEnvConfig('feed.http-hooks', array()); $uris = PhabricatorEnv::getEnvConfig('feed.http-hooks');
foreach ($uris as $uri) { foreach ($uris as $uri) {
$task = PhabricatorWorker::scheduleTask( $task = PhabricatorWorker::scheduleTask(
'FeedPublisherWorker', 'FeedPublisherWorker',

View file

@ -84,9 +84,7 @@ final class ManiphestTaskPriority extends ManiphestConstants {
*/ */
public static function getDefaultPriority() { public static function getDefaultPriority() {
return PhabricatorEnv::getEnvConfig( return PhabricatorEnv::getEnvConfig(
'maniphest.default-priority', 'maniphest.default-priority');
self::PRIORITY_TRIAGE
);
} }
/** /**

View file

@ -738,10 +738,7 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
* specified by the `metamta.user-address-format` configuration value. * specified by the `metamta.user-address-format` configuration value.
*/ */
private function getUserName($user) { private function getUserName($user) {
$format = PhabricatorEnv::getEnvConfig( $format = PhabricatorEnv::getEnvConfig('metamta.user-address-format');
'metamta.user-address-format',
'full'
);
switch ($format) { switch ($format) {
case 'short': case 'short':

View file

@ -14,7 +14,6 @@ final class PhabricatorSearchAbstractDocument {
private $relationships = array(); private $relationships = array();
public static function getSupportedTypes() { public static function getSupportedTypes() {
$more = PhabricatorEnv::getEnvConfig('search.more-document-types', array());
return array( return array(
PhabricatorPHIDConstants::PHID_TYPE_DREV => 'Differential Revisions', PhabricatorPHIDConstants::PHID_TYPE_DREV => 'Differential Revisions',
PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'Repository Commits', PhabricatorPHIDConstants::PHID_TYPE_CMIT => 'Repository Commits',
@ -22,7 +21,7 @@ final class PhabricatorSearchAbstractDocument {
PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Documents', PhabricatorPHIDConstants::PHID_TYPE_WIKI => 'Phriction Documents',
PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users', PhabricatorPHIDConstants::PHID_TYPE_USER => 'Phabricator Users',
PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Ponder Questions', PhabricatorPHIDConstants::PHID_TYPE_QUES => 'Ponder Questions',
) + $more; );
} }
public function setPHID($phid) { public function setPHID($phid) {

View file

@ -227,11 +227,17 @@ final class PhabricatorEnv {
/** /**
* Get the current configuration setting for a given key. * Get the current configuration setting for a given key.
* *
* If the key is not found, then throw an Exception.
*
* @task read * @task read
*/ */
public static function getEnvConfig($key, $default = null) { public static function getEnvConfig($key) {
$result = self::$sourceStack->getKeys(array($key)); $result = self::$sourceStack->getKeys(array($key));
return idx($result, $key, $default); if (array_key_exists($key, $result)) {
return $result[$key];
} else {
throw new Exception("No config value specified for key '{$key}'.");
}
} }

View file

@ -187,7 +187,6 @@ abstract class LiskDAO {
private $__missingFields = array(); private $__missingFields = array();
private static $processIsolationLevel = 0; private static $processIsolationLevel = 0;
private static $transactionIsolationLevel = 0; private static $transactionIsolationLevel = 0;
private static $__checkedClasses = array();
private $__ephemeral = false; private $__ephemeral = false;
@ -213,30 +212,6 @@ abstract class LiskDAO {
if ($this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) { if ($this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) {
$this->resetDirtyFields(); $this->resetDirtyFields();
$this_class = get_class($this);
if (empty(self::$__checkedClasses[$this_class])) {
self::$__checkedClasses = true;
if (PhabricatorEnv::getEnvConfig('lisk.check_property_methods')) {
$class = new ReflectionClass(get_class($this));
$methods = $class->getMethods();
$properties = $this->getProperties();
foreach ($methods as $method) {
$name = strtolower($method->getName());
if (!(strncmp($name, 'get', 3) && strncmp($name, 'set', 3))) {
$name = substr($name, 3);
$declaring_class_name = $method->getDeclaringClass()->getName();
if (isset($properties[$name]) &&
$declaring_class_name !== 'LiskDAO') {
throw new Exception(
"Cannot implement method {$method->getName()} in ".
"{$declaring_class_name}.");
}
}
}
}
}
} }
} }