Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phid/PhabricatorObjectHandle.php
| Show All 26 Lines | final class PhabricatorObjectHandle | ||||
| private $availability = self::AVAILABILITY_FULL; | private $availability = self::AVAILABILITY_FULL; | ||||
| private $complete; | private $complete; | ||||
| private $objectName; | private $objectName; | ||||
| private $policyFiltered; | private $policyFiltered; | ||||
| private $subtitle; | private $subtitle; | ||||
| private $tokenIcon; | private $tokenIcon; | ||||
| private $commandLineObjectName; | private $commandLineObjectName; | ||||
| private $mailStampName; | private $mailStampName; | ||||
| private $capabilities = array(); | |||||
| public function setIcon($icon) { | public function setIcon($icon) { | ||||
| $this->icon = $icon; | $this->icon = $icon; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getIcon() { | public function getIcon() { | ||||
| if ($this->getPolicyFiltered()) { | if ($this->getPolicyFiltered()) { | ||||
| ▲ Show 20 Lines • Show All 340 Lines • ▼ Show 20 Lines | public function getLinkName() { | ||||
| return $name; | return $name; | ||||
| } | } | ||||
| protected function getPHIDType() { | protected function getPHIDType() { | ||||
| $types = PhabricatorPHIDType::getAllTypes(); | $types = PhabricatorPHIDType::getAllTypes(); | ||||
| return idx($types, $this->getType()); | return idx($types, $this->getType()); | ||||
| } | } | ||||
| public function hasCapabilities() { | |||||
| return ($this->getType() === PhabricatorPeopleUserPHIDType::TYPECONST); | |||||
| } | |||||
| public function attachCapability( | |||||
| PhabricatorPolicyInterface $object, | |||||
| $capability, | |||||
| $has_capability) { | |||||
| if (!$this->hasCapabilities()) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Attempting to attach capability ("%s") for object ("%s") to '. | |||||
| 'handle, but this handle (of type "%s") can not have '. | |||||
| 'capabilities.', | |||||
| $capability, | |||||
| get_class($object), | |||||
| $this->getType())); | |||||
| } | |||||
| $object_key = $this->getObjectCapabilityKey($object); | |||||
| $this->capabilities[$object_key][$capability] = $has_capability; | |||||
| return $this; | |||||
| } | |||||
| public function hasViewCapability(PhabricatorPolicyInterface $object) { | |||||
| return $this->hasCapability($object, PhabricatorPolicyCapability::CAN_VIEW); | |||||
| } | |||||
| private function hasCapability( | |||||
| PhabricatorPolicyInterface $object, | |||||
| $capability) { | |||||
| $object_key = $this->getObjectCapabilityKey($object); | |||||
| if (!isset($this->capabilities[$object_key][$capability])) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Attempting to test capability "%s" for handle of type "%s", but '. | |||||
| 'this capability has not been attached.', | |||||
| $capability, | |||||
| $this->getType())); | |||||
| } | |||||
| return $this->capabilities[$object_key][$capability]; | |||||
| } | |||||
| private function getObjectCapabilityKey(PhabricatorPolicyInterface $object) { | |||||
| $object_phid = $object->getPHID(); | |||||
| if (!$object_phid) { | |||||
| throw new Exception( | |||||
| pht( | |||||
| 'Object (of class "%s") has no PHID, so handles can not interact '. | |||||
| 'with capabilities for it.', | |||||
| get_class($object))); | |||||
| } | |||||
| return $object_phid; | |||||
| } | |||||
| /* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
| public function getCapabilities() { | public function getCapabilities() { | ||||
| return array( | return array( | ||||
| PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
| ); | ); | ||||
| Show All 17 Lines | |||||