@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Further simplify PhabricatorCustomFieldInterface

Summary:
Ref T1703. Ref T3718. This introduces `PhabricatorCustomFieldAttachment`, which is just a fancy `array()`. The goal here is to simplify `PhabricatorCustomFieldInterface` as much as possible.

In particular, it can now use common infrastructure (`assertAttached()`) and is more difficult to get wrong.

Test Plan: Edited custom fields on profile.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1703, T3718

Differential Revision: https://secure.phabricator.com/D6752

+54 -32
+1
src/__phutil_library_map__.php
··· 1025 1025 'PhabricatorCrumbsView' => 'view/layout/PhabricatorCrumbsView.php', 1026 1026 'PhabricatorCursorPagedPolicyAwareQuery' => 'infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php', 1027 1027 'PhabricatorCustomField' => 'infrastructure/customfield/field/PhabricatorCustomField.php', 1028 + 'PhabricatorCustomFieldAttachment' => 'infrastructure/customfield/field/PhabricatorCustomFieldAttachment.php', 1028 1029 'PhabricatorCustomFieldConfigOptionType' => 'infrastructure/customfield/config/PhabricatorCustomFieldConfigOptionType.php', 1029 1030 'PhabricatorCustomFieldDataNotAvailableException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldDataNotAvailableException.php', 1030 1031 'PhabricatorCustomFieldImplementationIncompleteException' => 'infrastructure/customfield/exception/PhabricatorCustomFieldImplementationIncompleteException.php',
+5 -8
src/applications/people/storage/PhabricatorUser.php
··· 36 36 private $status = self::ATTACHABLE; 37 37 private $preferences = null; 38 38 private $omnipotent = false; 39 - private $customFields = array(); 39 + private $customFields = self::ATTACHABLE; 40 40 41 41 protected function readField($field) { 42 42 switch ($field) { ··· 843 843 return 'PhabricatorUserCustomField'; 844 844 } 845 845 846 - public function getCustomFields($role) { 847 - if (idx($this->customFields, $role) === null) { 848 - PhabricatorCustomField::raiseUnattachedException($this, $role); 849 - } 850 - return $this->customFields[$role]; 846 + public function getCustomFields() { 847 + return $this->assertAttached($this->customFields); 851 848 } 852 849 853 - public function attachCustomFields($role, PhabricatorCustomFieldList $list) { 854 - $this->customFields[$role] = $list; 850 + public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) { 851 + $this->customFields = $fields; 855 852 return $this; 856 853 } 857 854
+13 -14
src/infrastructure/customfield/field/PhabricatorCustomField.php
··· 33 33 /** 34 34 * @task apps 35 35 */ 36 - public static function raiseUnattachedException( 36 + public static function getObjectFields( 37 37 PhabricatorCustomFieldInterface $object, 38 38 $role) { 39 - throw new PhabricatorCustomFieldNotAttachedException( 40 - "Call attachCustomFields() before getCustomFields()!"); 41 - } 42 39 43 - 44 - /** 45 - * @task apps 46 - */ 47 - public static function getObjectFields( 48 - PhabricatorCustomFieldInterface $object, 49 - $role) { 40 + try { 41 + $attachment = $object->getCustomFields(); 42 + } catch (PhabricatorDataNotAttachedException $ex) { 43 + $attachment = new PhabricatorCustomFieldAttachment(); 44 + $object->attachCustomFields($attachment); 45 + } 50 46 51 47 try { 52 - $field_list = $object->getCustomFields($role); 48 + $field_list = $attachment->getCustomFieldList($role); 53 49 } catch (PhabricatorCustomFieldNotAttachedException $ex) { 54 50 $base_class = $object->getCustomFieldBaseClass(); 55 51 ··· 74 70 } 75 71 76 72 $field_list = new PhabricatorCustomFieldList($fields); 77 - $object->attachCustomFields($role, $field_list); 73 + $attachment->addCustomFieldList($role, $field_list); 78 74 } 79 75 80 76 return $field_list; ··· 88 84 PhabricatorCustomFieldInterface $object, 89 85 $role, 90 86 $field_key) { 91 - return idx(self::getObjectFields($object, $role)->getFields(), $field_key); 87 + 88 + $fields = self::getObjectFields($object, $role)->getFields(); 89 + 90 + return idx($fields, $field_key); 92 91 } 93 92 94 93
+28
src/infrastructure/customfield/field/PhabricatorCustomFieldAttachment.php
··· 1 + <?php 2 + 3 + /** 4 + * Convenience class which simplifies the implementation of 5 + * @{interface:PhabricatorCustomFieldInterface} by obscuring the details of how 6 + * custom fields are stored. 7 + * 8 + * Generally, you should not use this class directly. It is used by 9 + * @{class:PhabricatorCustomField} to manage field storage on objects. 10 + */ 11 + final class PhabricatorCustomFieldAttachment { 12 + 13 + private $lists = array(); 14 + 15 + public function addCustomFieldList($role, PhabricatorCustomFieldList $list) { 16 + $this->lists[$role] = $list; 17 + return $this; 18 + } 19 + 20 + public function getCustomFieldList($role) { 21 + if (empty($this->lists[$role])) { 22 + throw new PhabricatorCustomFieldNotAttachedException( 23 + "Role list '{$role}' is not available!"); 24 + } 25 + return $this->lists[$role]; 26 + } 27 + 28 + }
+7 -10
src/infrastructure/customfield/interface/PhabricatorCustomFieldInterface.php
··· 4 4 5 5 public function getCustomFieldBaseClass(); 6 6 public function getCustomFieldSpecificationForRole($role); 7 - public function getCustomFields($role); 8 - public function attachCustomFields($role, PhabricatorCustomFieldList $list); 7 + public function getCustomFields(); 8 + public function attachCustomFields(PhabricatorCustomFieldAttachment $fields); 9 9 10 10 } 11 11 ··· 16 16 /* -( PhabricatorCustomFieldInterface )------------------------------------ */ 17 17 /* 18 18 19 - private $customFields = array(); 19 + private $customFields = self::ATTACHABLE; 20 20 21 21 public function getCustomFieldSpecificationForRole($role) { 22 22 return PhabricatorEnv::getEnvConfig(<<<'application.fields'>>>); ··· 26 26 return <<<<'YourApplicationHereCustomField'>>>>; 27 27 } 28 28 29 - public function getCustomFields($role) { 30 - if (idx($this->customFields, $role) === null) { 31 - PhabricatorCustomField::raiseUnattachedException($this, $role); 32 - } 33 - return $this->customFields[$role]; 29 + public function getCustomFields() { 30 + return $this->assertAttached($this->customFields); 34 31 } 35 32 36 - public function attachCustomFields($role, PhabricatorCustomFieldList $list) { 37 - $this->customFields[$role] = $list; 33 + public function attachCustomFields(PhabricatorCustomFieldAttachment $fields) { 34 + $this->customFields = $fields; 38 35 return $this; 39 36 } 40 37