Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/storage/PhabricatorUser.php
| Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | final class PhabricatorUser | ||||
| private $usableCacheData = array(); | private $usableCacheData = array(); | ||||
| private $authorities = array(); | private $authorities = array(); | ||||
| private $handlePool; | private $handlePool; | ||||
| private $csrfSalt; | private $csrfSalt; | ||||
| private $settingCacheKeys = array(); | private $settingCacheKeys = array(); | ||||
| private $settingCache = array(); | private $settingCache = array(); | ||||
| private $allowInlineCacheGeneration; | |||||
| protected function readField($field) { | protected function readField($field) { | ||||
| switch ($field) { | switch ($field) { | ||||
| // Make sure these return booleans. | // Make sure these return booleans. | ||||
| case 'isAdmin': | case 'isAdmin': | ||||
| return (bool)$this->isAdmin; | return (bool)$this->isAdmin; | ||||
| case 'isDisabled': | case 'isDisabled': | ||||
| return (bool)$this->isDisabled; | return (bool)$this->isDisabled; | ||||
| ▲ Show 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | /* -( Settings )----------------------------------------------------------- */ | ||||
| public function getUserSetting($key) { | public function getUserSetting($key) { | ||||
| // NOTE: We store available keys and cached values separately to make it | // NOTE: We store available keys and cached values separately to make it | ||||
| // faster to check for `null` in the cache, which is common. | // faster to check for `null` in the cache, which is common. | ||||
| if (isset($this->settingCacheKeys[$key])) { | if (isset($this->settingCacheKeys[$key])) { | ||||
| return $this->settingCache[$key]; | return $this->settingCache[$key]; | ||||
| } | } | ||||
| $settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES; | $settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES; | ||||
| if ($this->getPHID()) { | |||||
| $settings = $this->requireCacheData($settings_key); | $settings = $this->requireCacheData($settings_key); | ||||
| } else { | |||||
| $settings = array(); | |||||
| } | |||||
| $defaults = PhabricatorSetting::getAllEnabledSettings($this); | $defaults = PhabricatorSetting::getAllEnabledSettings($this); | ||||
| if (array_key_exists($key, $settings)) { | if (array_key_exists($key, $settings)) { | ||||
| $value = $settings[$key]; | $value = $settings[$key]; | ||||
| // Make sure the value is valid before we return it. This makes things | // Make sure the value is valid before we return it. This makes things | ||||
| // more robust when options are changed or removed. | // more robust when options are changed or removed. | ||||
| ▲ Show 20 Lines • Show All 986 Lines • ▼ Show 20 Lines | /* -( User Cache )--------------------------------------------------------- */ | ||||
| /** | /** | ||||
| * @task cache | * @task cache | ||||
| */ | */ | ||||
| public function attachRawCacheData(array $data) { | public function attachRawCacheData(array $data) { | ||||
| $this->rawCacheData = $data + $this->rawCacheData; | $this->rawCacheData = $data + $this->rawCacheData; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function setAllowInlineCacheGeneration($allow_cache_generation) { | |||||
| $this->allowInlineCacheGeneration = $allow_cache_generation; | |||||
| return $this; | |||||
| } | |||||
| /** | /** | ||||
| * @task cache | * @task cache | ||||
| */ | */ | ||||
| protected function requireCacheData($key) { | protected function requireCacheData($key) { | ||||
| if (isset($this->usableCacheData[$key])) { | if (isset($this->usableCacheData[$key])) { | ||||
| return $this->usableCacheData[$key]; | return $this->usableCacheData[$key]; | ||||
| } | } | ||||
| $type = PhabricatorUserCacheType::requireCacheTypeForKey($key); | $type = PhabricatorUserCacheType::requireCacheTypeForKey($key); | ||||
| if (isset($this->rawCacheData[$key])) { | if (isset($this->rawCacheData[$key])) { | ||||
| $raw_value = $this->rawCacheData[$key]; | $raw_value = $this->rawCacheData[$key]; | ||||
| $usable_value = $type->getValueFromStorage($raw_value); | $usable_value = $type->getValueFromStorage($raw_value); | ||||
| $this->usableCacheData[$key] = $usable_value; | $this->usableCacheData[$key] = $usable_value; | ||||
| return $usable_value; | return $usable_value; | ||||
| } | } | ||||
| // By default, we throw if a cache isn't available. This is consistent | |||||
| // with the standard `needX()` + `attachX()` + `getX()` interaction. | |||||
| if (!$this->allowInlineCacheGeneration) { | |||||
| throw new PhabricatorDataNotAttachedException($this); | |||||
| } | |||||
| $usable_value = $type->getDefaultValue(); | $usable_value = $type->getDefaultValue(); | ||||
| $user_phid = $this->getPHID(); | $user_phid = $this->getPHID(); | ||||
| if ($user_phid) { | if ($user_phid) { | ||||
| $map = $type->newValueForUsers($key, array($this)); | $map = $type->newValueForUsers($key, array($this)); | ||||
| if (array_key_exists($user_phid, $map)) { | if (array_key_exists($user_phid, $map)) { | ||||
| $usable_value = $map[$user_phid]; | $usable_value = $map[$user_phid]; | ||||
| $raw_value = $type->getValueForStorage($usable_value); | $raw_value = $type->getValueForStorage($usable_value); | ||||
| Show All 26 Lines | |||||