diff --git a/src/applications/conpherence/storage/ConpherenceThread.php b/src/applications/conpherence/storage/ConpherenceThread.php index 607eeea726..e5657c9232 100644 --- a/src/applications/conpherence/storage/ConpherenceThread.php +++ b/src/applications/conpherence/storage/ConpherenceThread.php @@ -13,11 +13,11 @@ final class ConpherenceThread extends ConpherenceDAO protected $recentParticipantPHIDs = array(); protected $mailKey; - private $participants; - private $transactions; - private $handles; - private $filePHIDs; - private $widgetData; + private $participants = self::ATTACHABLE; + private $transactions = self::ATTACHABLE; + private $handles = self::ATTACHABLE; + private $filePHIDs = self::ATTACHABLE; + private $widgetData = self::ATTACHABLE; private $images = array(); public function getConfiguration() { @@ -47,12 +47,7 @@ final class ConpherenceThread extends ConpherenceDAO return $this; } public function getParticipants() { - if ($this->participants === null) { - throw new Exception( - 'You must attachParticipants first!' - ); - } - return $this->participants; + return $this->assertAttached($this->participants); } public function getParticipant($phid) { $participants = $this->getParticipants(); @@ -69,12 +64,7 @@ final class ConpherenceThread extends ConpherenceDAO return $this; } public function getHandles() { - if ($this->handles === null) { - throw new Exception( - 'You must attachHandles first!' - ); - } - return $this->handles; + return $this->assertAttached($this->handles); } public function attachTransactions(array $transactions) { @@ -83,26 +73,14 @@ final class ConpherenceThread extends ConpherenceDAO return $this; } public function getTransactions() { - if ($this->transactions === null) { - throw new Exception( - 'You must attachTransactions first!' - ); - } - return $this->transactions; + return $this->assertAttached($this->transactions); } public function getTransactionsFrom($begin = 0, $amount = null) { $length = count($this->transactions); - if ($amount === null) { - $amount === $length; - } - if ($this->transactions === null) { - throw new Exception( - 'You must attachTransactions first!' - ); - } + return array_slice( - $this->transactions, + $this->getTransactions(), $length - $begin - $amount, $amount); } @@ -112,12 +90,7 @@ final class ConpherenceThread extends ConpherenceDAO return $this; } public function getFilePHIDs() { - if ($this->filePHIDs === null) { - throw new Exception( - 'You must attachFilePHIDs first!' - ); - } - return $this->filePHIDs; + return $this->assertAttached($this->filePHIDs); } public function attachWidgetData(array $widget_data) { @@ -125,12 +98,7 @@ final class ConpherenceThread extends ConpherenceDAO return $this; } public function getWidgetData() { - if ($this->widgetData === null) { - throw new Exception( - 'You must attachWidgetData first!' - ); - } - return $this->widgetData; + return $this->assertAttached($this->widgetData); } public function getDisplayData(PhabricatorUser $user) { diff --git a/src/applications/differential/storage/DifferentialChangeset.php b/src/applications/differential/storage/DifferentialChangeset.php index 5aa9898338..bd6ce67af6 100644 --- a/src/applications/differential/storage/DifferentialChangeset.php +++ b/src/applications/differential/storage/DifferentialChangeset.php @@ -15,7 +15,7 @@ final class DifferentialChangeset extends DifferentialDAO { protected $delLines; private $unsavedHunks = array(); - private $hunks; + private $hunks = self::ATTACHABLE; const TABLE_CACHE = 'differential_changeset_parse_cache'; @@ -40,10 +40,7 @@ final class DifferentialChangeset extends DifferentialDAO { } public function getHunks() { - if ($this->hunks === null) { - throw new Exception("Must load and attach hunks first!"); - } - return $this->hunks; + return $this->assertAttached($this->hunks); } public function getDisplayFilename() { @@ -55,7 +52,7 @@ final class DifferentialChangeset extends DifferentialDAO { } public function addUnsavedHunk(DifferentialHunk $hunk) { - if ($this->hunks === null) { + if ($this->hunks === self::ATTACHABLE) { $this->hunks = array(); } $this->hunks[] = $hunk; diff --git a/src/applications/differential/storage/DifferentialDiff.php b/src/applications/differential/storage/DifferentialDiff.php index b64fc8ca46..9b6c35937a 100644 --- a/src/applications/differential/storage/DifferentialDiff.php +++ b/src/applications/differential/storage/DifferentialDiff.php @@ -30,7 +30,7 @@ final class DifferentialDiff protected $description; private $unsavedChangesets = array(); - private $changesets; + private $changesets = self::ATTACHABLE; public function addUnsavedChangeset(DifferentialChangeset $changeset) { if ($this->changesets === null) { @@ -48,10 +48,7 @@ final class DifferentialDiff } public function getChangesets() { - if ($this->changesets === null) { - throw new Exception("Must load and attach changesets first!"); - } - return $this->changesets; + return $this->assertAttached($this->changesets); } public function loadChangesets() { diff --git a/src/applications/differential/storage/DifferentialRevision.php b/src/applications/differential/storage/DifferentialRevision.php index 45970a280d..75902087d9 100644 --- a/src/applications/differential/storage/DifferentialRevision.php +++ b/src/applications/differential/storage/DifferentialRevision.php @@ -26,13 +26,13 @@ final class DifferentialRevision extends DifferentialDAO protected $branchName; protected $arcanistProjectPHID; - private $relationships; - private $commits; - private $activeDiff = false; - private $diffIDs; - private $hashes; + private $relationships = self::ATTACHABLE; + private $commits = self::ATTACHABLE; + private $activeDiff = self::ATTACHABLE; + private $diffIDs = self::ATTACHABLE; + private $hashes = self::ATTACHABLE; - private $reviewerStatus; + private $reviewerStatus = self::ATTACHABLE; const RELATIONSHIP_TABLE = 'differential_relationship'; const TABLE_COMMIT = 'differential_commit'; @@ -86,10 +86,7 @@ final class DifferentialRevision extends DifferentialDAO } public function getCommitPHIDs() { - if ($this->commits === null) { - throw new Exception("Must attach commits first!"); - } - return $this->commits; + return $this->assertAttached($this->commits); } public function getActiveDiff() { @@ -98,10 +95,7 @@ final class DifferentialRevision extends DifferentialDAO // It would be good to get rid of this once we make diff-attaching // transactional. - if ($this->activeDiff === false) { - throw new Exception("Must attach active diff first!"); - } - return $this->activeDiff; + return $this->assertAttached($this->activeDiff); } public function attachActiveDiff($diff) { @@ -110,10 +104,7 @@ final class DifferentialRevision extends DifferentialDAO } public function getDiffIDs() { - if ($this->diffIDs === null) { - throw new Exception("Must attach diff IDs first!"); - } - return $this->diffIDs; + return $this->assertAttached($this->diffIDs); } public function attachDiffIDs(array $ids) { @@ -256,9 +247,7 @@ final class DifferentialRevision extends DifferentialDAO } private function getRelatedPHIDs($relation) { - if ($this->relationships === null) { - throw new Exception("Must load relationships!"); - } + $this->assertAttached($this->relationships); return ipull($this->getRawRelations($relation), 'objectPHID'); } @@ -304,10 +293,7 @@ final class DifferentialRevision extends DifferentialDAO } public function getHashes() { - if ($this->hashes === null) { - throw new Exception("Call attachHashes() before getHashes()!"); - } - return $this->hashes; + return $this->assertAttached($this->hashes); } public function attachHashes(array $hashes) { @@ -337,12 +323,7 @@ final class DifferentialRevision extends DifferentialDAO } public function getReviewerStatus() { - if ($this->reviewerStatus === null) { - throw new Exception( - "Call attachReviewerStatus() before getReviewerStatus()!" - ); - } - return $this->reviewerStatus; + return $this->assertAttached($this->reviewerStatus); } public function attachReviewerStatus(array $reviewers) { diff --git a/src/applications/drydock/storage/DrydockLease.php b/src/applications/drydock/storage/DrydockLease.php index 71f624f3af..9e08dbd3b1 100644 --- a/src/applications/drydock/storage/DrydockLease.php +++ b/src/applications/drydock/storage/DrydockLease.php @@ -10,7 +10,7 @@ final class DrydockLease extends DrydockDAO { protected $status = DrydockLeaseStatus::STATUS_PENDING; protected $taskID; - private $resource; + private $resource = self::ATTACHABLE; private $releaseOnDestruction; /** @@ -64,10 +64,7 @@ final class DrydockLease extends DrydockDAO { } public function getResource() { - if ($this->resource === null) { - throw new Exception("Resource is not yet loaded."); - } - return $this->resource; + return $this->assertAttached($this->resource); } public function attachResource(DrydockResource $resource) { diff --git a/src/applications/herald/storage/HeraldRule.php b/src/applications/herald/storage/HeraldRule.php index b5dc2f62cd..50c564370f 100644 --- a/src/applications/herald/storage/HeraldRule.php +++ b/src/applications/herald/storage/HeraldRule.php @@ -15,7 +15,7 @@ final class HeraldRule extends HeraldDAO protected $configVersion = 9; - private $ruleApplied = array(); // phids for which this rule has been applied + private $ruleApplied = self::ATTACHABLE; // phids for which this rule has been applied private $validAuthor = self::ATTACHABLE; private $conditions; private $actions; @@ -31,13 +31,13 @@ final class HeraldRule extends HeraldDAO } public function getRuleApplied($phid) { - if (idx($this->ruleApplied, $phid) === null) { - throw new Exception("Call setRuleApplied() before getRuleApplied()!"); - } - return $this->ruleApplied[$phid]; + return $this->assertAttachedKey($this->ruleApplied, $phid); } public function setRuleApplied($phid, $applied) { + if ($this->ruleApplied === self::ATTACHABLE) { + $this->ruleApplied = array(); + } $this->ruleApplied[$phid] = $applied; return $this; } diff --git a/src/applications/legalpad/storage/LegalpadDocument.php b/src/applications/legalpad/storage/LegalpadDocument.php index 2f5b25e937..665370333d 100644 --- a/src/applications/legalpad/storage/LegalpadDocument.php +++ b/src/applications/legalpad/storage/LegalpadDocument.php @@ -20,8 +20,8 @@ final class LegalpadDocument extends LegalpadDAO protected $editPolicy; protected $mailKey; - private $documentBody; - private $contributors; + private $documentBody = self::ATTACHABLE; + private $contributors = self::ATTACHABLE; public function getConfiguration() { return array( @@ -38,12 +38,7 @@ final class LegalpadDocument extends LegalpadDAO } public function getDocumentBody() { - if ($this->documentBody === null) { - throw new Exception( - 'You must attachDocumentBody before you can getDocumentBody.'); - } - - return $this->documentBody; + return $this->assertAttached($this->documentBody); } public function attachDocumentBody(LegalpadDocumentBody $body) { @@ -52,12 +47,7 @@ final class LegalpadDocument extends LegalpadDAO } public function getContributors() { - if ($this->contributors === null) { - throw new Exception( - 'You must attachContributors before you can getContributors.'); - } - - return $this->contributors; + return $this->assertAttached($this->contributors); } public function attachContributors(array $contributors) { diff --git a/src/applications/macro/storage/PhabricatorFileImageMacro.php b/src/applications/macro/storage/PhabricatorFileImageMacro.php index 7fb8935b36..b708bc9668 100644 --- a/src/applications/macro/storage/PhabricatorFileImageMacro.php +++ b/src/applications/macro/storage/PhabricatorFileImageMacro.php @@ -12,7 +12,7 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO protected $name; protected $isDisabled = 0; - private $file; + private $file = self::ATTACHABLE; public function attachFile(PhabricatorFile $file) { $this->file = $file; @@ -20,11 +20,7 @@ final class PhabricatorFileImageMacro extends PhabricatorFileDAO } public function getFile() { - if (!$this->file) { - throw new Exception("Attach a file with attachFile() first!"); - } - - return $this->file; + return $this->assertAttached($this->file); } public function getConfiguration() { diff --git a/src/applications/maniphest/storage/ManiphestTask.php b/src/applications/maniphest/storage/ManiphestTask.php index 32314f4505..3ac3f68962 100644 --- a/src/applications/maniphest/storage/ManiphestTask.php +++ b/src/applications/maniphest/storage/ManiphestTask.php @@ -34,7 +34,7 @@ final class ManiphestTask extends ManiphestDAO protected $ownerOrdering; - private $auxiliaryAttributes; + private $auxiliaryAttributes = self::ATTACHABLE; private $auxiliaryDirty = array(); public function getConfiguration() { @@ -95,16 +95,13 @@ final class ManiphestTask extends ManiphestDAO } public function getAuxiliaryAttribute($key, $default = null) { - if ($this->auxiliaryAttributes === null) { - throw new Exception("Attach auxiliary attributes before getting them!"); - } + $this->assertAttached($this->auxiliaryAttributes); return idx($this->auxiliaryAttributes, $key, $default); } public function setAuxiliaryAttribute($key, $val) { - if ($this->auxiliaryAttributes === null) { - throw new Exception("Attach auxiliary attributes before setting them!"); - } + $this->assertAttached($this->auxiliaryAttributes); + $this->auxiliaryAttributes[$key] = $val; $this->auxiliaryDirty[$key] = true; return $this; diff --git a/src/applications/paste/storage/PhabricatorPaste.php b/src/applications/paste/storage/PhabricatorPaste.php index df31901698..ba1081f53a 100644 --- a/src/applications/paste/storage/PhabricatorPaste.php +++ b/src/applications/paste/storage/PhabricatorPaste.php @@ -18,8 +18,8 @@ final class PhabricatorPaste extends PhabricatorPasteDAO protected $viewPolicy; protected $mailKey; - private $content; - private $rawContent; + private $content = self::ATTACHABLE; + private $rawContent = self::ATTACHABLE; public function getURI() { return '/P'.$this->getID(); @@ -70,10 +70,7 @@ final class PhabricatorPaste extends PhabricatorPasteDAO } public function getContent() { - if ($this->content === null) { - throw new Exception("Call attachContent() before getContent()!"); - } - return $this->content; + return $this->assertAttached($this->content); } public function attachContent($content) { @@ -82,10 +79,7 @@ final class PhabricatorPaste extends PhabricatorPasteDAO } public function getRawContent() { - if ($this->rawContent === null) { - throw new Exception("Call attachRawContent() before getRawContent()!"); - } - return $this->rawContent; + return $this->assertAttached($this->rawContent); } public function attachRawContent($raw_content) { diff --git a/src/applications/people/storage/PhabricatorExternalAccount.php b/src/applications/people/storage/PhabricatorExternalAccount.php index bb860503cc..1e0c347418 100644 --- a/src/applications/people/storage/PhabricatorExternalAccount.php +++ b/src/applications/people/storage/PhabricatorExternalAccount.php @@ -17,13 +17,10 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO protected $profileImagePHID; protected $properties = array(); - private $profileImageFile; + private $profileImageFile = self::ATTACHABLE; public function getProfileImageFile() { - if ($this->profileImageFile === null) { - throw new Exception("Call attachProfileImageFile() first!"); - } - return $this->profileImageFile; + return $this->assertAttached($this->profileImageFile); } public function attachProfileImageFile(PhabricatorFile $file) { diff --git a/src/applications/phame/storage/PhameBlog.php b/src/applications/phame/storage/PhameBlog.php index 45c79688c2..127ffbf392 100644 --- a/src/applications/phame/storage/PhameBlog.php +++ b/src/applications/phame/storage/PhameBlog.php @@ -21,8 +21,8 @@ final class PhameBlog extends PhameDAO protected $editPolicy; protected $joinPolicy; - private $bloggerPHIDs; - private $bloggers; + private $bloggerPHIDs = self::ATTACHABLE; + private $bloggers = self::ATTACHABLE; static private $requestBlog; @@ -110,13 +110,7 @@ final class PhameBlog extends PhameDAO } public function getBloggerPHIDs() { - if ($this->bloggerPHIDs === null) { - throw new Exception( - 'You must loadBloggerPHIDs before you can getBloggerPHIDs!' - ); - } - - return $this->bloggerPHIDs; + return $this->assertAttached($this->bloggerPHIDs); } public function loadBloggers() { @@ -149,13 +143,7 @@ final class PhameBlog extends PhameDAO } public function getBloggers() { - if ($this->bloggers === null) { - throw new Exception( - 'You must loadBloggers or attachBloggers before you can getBloggers!' - ); - } - - return $this->bloggers; + return $this->assertAttached($this->bloggers); } public function getSkin() { diff --git a/src/applications/phortune/storage/PhortuneAccount.php b/src/applications/phortune/storage/PhortuneAccount.php index 560781d975..cdd597d94f 100644 --- a/src/applications/phortune/storage/PhortuneAccount.php +++ b/src/applications/phortune/storage/PhortuneAccount.php @@ -12,7 +12,7 @@ final class PhortuneAccount extends PhortuneDAO protected $name; protected $balanceInCents = 0; - private $memberPHIDs; + private $memberPHIDs = self::ATTACHABLE; public function getConfiguration() { return array( @@ -26,10 +26,7 @@ final class PhortuneAccount extends PhortuneDAO } public function getMemberPHIDs() { - if ($this->memberPHIDs === null) { - throw new Exception("Call attachMemberPHIDs() before getMemberPHIDs()!"); - } - return $this->memberPHIDs; + return $this->assertAttached($this->memberPHIDs); } public function attachMemberPHIDs(array $phids) { diff --git a/src/applications/phortune/storage/PhortuneCart.php b/src/applications/phortune/storage/PhortuneCart.php index 3c4238a62e..6da64fc368 100644 --- a/src/applications/phortune/storage/PhortuneCart.php +++ b/src/applications/phortune/storage/PhortuneCart.php @@ -6,7 +6,7 @@ final class PhortuneCart extends PhortuneDAO { protected $ownerPHID; protected $metadata; - private $purchases; + private $purchases = self::ATTACHABLE; public function getConfiguration() { return array( @@ -33,10 +33,7 @@ final class PhortuneCart extends PhortuneDAO { } public function getPurchases() { - if ($this->purchases === null) { - throw new Exception("Purchases not attached to cart!"); - } - return $this->purchases; + return $this->assertAttached($this->purchases); } } diff --git a/src/applications/phortune/storage/PhortunePaymentMethod.php b/src/applications/phortune/storage/PhortunePaymentMethod.php index 67ca35154e..59799fbe11 100644 --- a/src/applications/phortune/storage/PhortunePaymentMethod.php +++ b/src/applications/phortune/storage/PhortunePaymentMethod.php @@ -22,7 +22,7 @@ final class PhortunePaymentMethod extends PhortuneDAO protected $providerType; protected $providerDomain; - private $account; + private $account = self::ATTACHABLE; public function getConfiguration() { return array( @@ -44,10 +44,7 @@ final class PhortunePaymentMethod extends PhortuneDAO } public function getAccount() { - if (!$this->account) { - throw new Exception("Call attachAccount() before getAccount()!"); - } - return $this->account; + return $this->assertAttached($this->account); } public function getDescription() { diff --git a/src/applications/project/storage/PhabricatorProject.php b/src/applications/project/storage/PhabricatorProject.php index 0ed774e83e..cd93909e84 100644 --- a/src/applications/project/storage/PhabricatorProject.php +++ b/src/applications/project/storage/PhabricatorProject.php @@ -15,8 +15,8 @@ final class PhabricatorProject extends PhabricatorProjectDAO protected $joinPolicy; private $subprojectsNeedUpdate; - private $memberPHIDs; - private $sparseMembers = array(); + private $memberPHIDs = self::ATTACHABLE; + private $sparseMembers = self::ATTACHABLE; public function getCapabilities() { return array( @@ -61,14 +61,13 @@ final class PhabricatorProject extends PhabricatorProjectDAO } public function isUserMember($user_phid) { - if (!isset($this->sparseMembers[$user_phid])) { - throw new Exception( - "Call setIsUserMember() before isUserMember()!"); - } - return $this->sparseMembers[$user_phid]; + return $this->assertAttachedKey($this->sparseMembers, $user_phid); } public function setIsUserMember($user_phid, $is_member) { + if ($this->sparseMembers === self::ATTACHABLE) { + $this->sparseMembers = array(); + } $this->sparseMembers[$user_phid] = $is_member; return $this; } @@ -100,10 +99,7 @@ final class PhabricatorProject extends PhabricatorProjectDAO } public function getMemberPHIDs() { - if ($this->memberPHIDs === null) { - throw new Exception("Call attachMemberPHIDs() first!"); - } - return $this->memberPHIDs; + return $this->assertAttached($this->memberPHIDs); } public function loadMemberPHIDs() { diff --git a/src/applications/releeph/storage/ReleephRequest.php b/src/applications/releeph/storage/ReleephRequest.php index 091e72f272..4e68fb54fe 100644 --- a/src/applications/releeph/storage/ReleephRequest.php +++ b/src/applications/releeph/storage/ReleephRequest.php @@ -22,7 +22,7 @@ final class ReleephRequest extends ReleephDAO protected $commitPHID; // Pre-populated handles that we'll bulk load in ReleephBranch - private $handles; + private $handles = self::ATTACHABLE; private $customFields = self::ATTACHABLE; @@ -148,11 +148,7 @@ final class ReleephRequest extends ReleephDAO } public function getHandles() { - if (!$this->handles) { - throw new Exception( - "You must call ReleephBranch::populateReleephRequestHandles() first"); - } - return $this->handles; + return $this->assertAttached($this->handles); } public function getDetail($key, $default = null) { diff --git a/src/applications/repository/storage/PhabricatorRepositoryCommit.php b/src/applications/repository/storage/PhabricatorRepositoryCommit.php index 51002bdc77..a7815a950c 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryCommit.php +++ b/src/applications/repository/storage/PhabricatorRepositoryCommit.php @@ -15,7 +15,7 @@ final class PhabricatorRepositoryCommit protected $auditStatus = PhabricatorAuditCommitStatusConstants::NONE; protected $summary = ''; - private $commitData; + private $commitData = self::ATTACHABLE; private $audits; private $isUnparsed; private $repository = self::ATTACHABLE; @@ -65,10 +65,7 @@ final class PhabricatorRepositoryCommit } public function getCommitData() { - if (!$this->commitData) { - throw new Exception("Attach commit data with attachCommitData() first!"); - } - return $this->commitData; + return $this->assertAttached($this->commitData); } public function attachAudits(array $audits) { diff --git a/src/applications/repository/storage/PhabricatorRepositorySymbol.php b/src/applications/repository/storage/PhabricatorRepositorySymbol.php index fb24bb215a..08e00bf687 100644 --- a/src/applications/repository/storage/PhabricatorRepositorySymbol.php +++ b/src/applications/repository/storage/PhabricatorRepositorySymbol.php @@ -18,9 +18,9 @@ final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO { protected $pathID; protected $lineNumber; - private $path = false; - private $arcanistProject = false; - private $repository = false; + private $path = self::ATTACHABLE; + private $arcanistProject = self::ATTACHABLE; + private $repository = self::ATTACHABLE; public function getConfiguration() { return array( @@ -51,10 +51,7 @@ final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO { } public function getPath() { - if ($this->path === false) { - throw new Exception('Call attachPath() before getPath()!'); - } - return $this->path; + return $this->assertAttached($this->path); } public function attachPath($path) { @@ -63,10 +60,7 @@ final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO { } public function getRepository() { - if ($this->repository === false) { - throw new Exception('Call attachRepository() before getRepository()!'); - } - return $this->repository; + return $this->assertAttached($this->repository); } public function attachRepository($repository) { @@ -75,11 +69,7 @@ final class PhabricatorRepositorySymbol extends PhabricatorRepositoryDAO { } public function getArcanistProject() { - if ($this->arcanistProject === false) { - throw new Exception( - 'Call attachArcanistProject() before getArcanistProject()!'); - } - return $this->arcanistProject; + return $this->assertAttached($this->arcanistProject); } public function attachArcanistProject($project) { diff --git a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php index 3e3f8ad343..ad55b8bacc 100644 --- a/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php +++ b/src/applications/slowvote/storage/PhabricatorSlowvotePoll.php @@ -24,9 +24,9 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO protected $method; protected $viewPolicy; - private $options; - private $choices; - private $viewerChoices = array(); + private $options = self::ATTACHABLE; + private $choices = self::ATTACHABLE; + private $viewerChoices = self::ATTACHABLE; public function getConfiguration() { return array( @@ -40,10 +40,7 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO } public function getOptions() { - if ($this->options === null) { - throw new Exception("Call attachOptions() before getOptions()!"); - } - return $this->options; + return $this->assertAttached($this->options); } public function attachOptions(array $options) { @@ -53,10 +50,7 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO } public function getChoices() { - if ($this->choices === null) { - throw new Exception("Call attachChoices() before getChoices()!"); - } - return $this->choices; + return $this->assertAttached($this->choices); } public function attachChoices(array $choices) { @@ -66,14 +60,13 @@ final class PhabricatorSlowvotePoll extends PhabricatorSlowvoteDAO } public function getViewerChoices(PhabricatorUser $viewer) { - if (idx($this->viewerChoices, $viewer->getPHID()) === null) { - throw new Exception( - "Call attachViewerChoices() before getViewerChoices()!"); - } - return idx($this->viewerChoices, $viewer->getPHID()); + return $this->assertAttachedKey($this->viewerChoices, $viewer->getPHID()); } public function attachViewerChoices(PhabricatorUser $viewer, array $choices) { + if ($this->viewerChoices === self::ATTACHABLE) { + $this->viewerChoices = array(); + } assert_instances_of($choices, 'PhabricatorSlowvoteChoice'); $this->viewerChoices[$viewer->getPHID()] = $choices; return $this; diff --git a/src/applications/tokens/storage/PhabricatorTokenGiven.php b/src/applications/tokens/storage/PhabricatorTokenGiven.php index 384447f6de..b3f2b21480 100644 --- a/src/applications/tokens/storage/PhabricatorTokenGiven.php +++ b/src/applications/tokens/storage/PhabricatorTokenGiven.php @@ -7,7 +7,7 @@ final class PhabricatorTokenGiven extends PhabricatorTokenDAO protected $objectPHID; protected $tokenPHID; - private $object; + private $object = self::ATTACHABLE; public function attachObject(PhabricatorTokenReceiverInterface $object) { $this->object = $object; @@ -15,10 +15,7 @@ final class PhabricatorTokenGiven extends PhabricatorTokenDAO } public function getObject() { - if ($this->object === null) { - throw new Exception("Call attachObject() before getObject()!"); - } - return $this->object; + return $this->assertAttached($this->object); } public function getCapabilities() { diff --git a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php index 7844f158bf..3d99cc3ae2 100644 --- a/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php +++ b/src/infrastructure/storage/lisk/PhabricatorLiskDAO.php @@ -6,7 +6,7 @@ */ abstract class PhabricatorLiskDAO extends LiskDAO { - private $edges = array(); + private $edges = self::ATTACHABLE; private static $namespaceStack = array(); const ATTACHABLE = ""; @@ -29,11 +29,7 @@ abstract class PhabricatorLiskDAO extends LiskDAO { * @task edges */ public function getEdges($type) { - $edges = idx($this->edges, $type); - if ($edges === null) { - throw new Exception("Call attachEdges() before getEdges()!"); - } - return $edges; + return $this->assertAttachedKey($this->edges, $type); } @@ -208,7 +204,6 @@ abstract class PhabricatorLiskDAO extends LiskDAO { return $result; } - protected function assertAttached($property) { if ($property === self::ATTACHABLE) { throw new PhabricatorDataNotAttachedException($this); @@ -216,4 +211,12 @@ abstract class PhabricatorLiskDAO extends LiskDAO { return $property; } + protected function assertAttachedKey($value, $key) { + $this->assertAttached($value); + if (!array_key_exists($key, $value)) { + throw new PhabricatorDataNotAttachedException($this); + } + return $value[$key]; + } + }