[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class PhabricatorPolicyCapability extends Phobject { 4 5 const CAN_VIEW = 'view'; 6 const CAN_EDIT = 'edit'; 7 const CAN_JOIN = 'join'; 8 9 /** 10 * Get the unique key identifying this capability. This key must be globally 11 * unique. Application capabilities should be namespaced. For example: 12 * 13 * application.create 14 * 15 * @return string Globally unique capability key. 16 */ 17 final public function getCapabilityKey() { 18 $class = new ReflectionClass($this); 19 20 $const = $class->getConstant('CAPABILITY'); 21 if ($const === false) { 22 throw new Exception( 23 pht( 24 'PolicyCapability class "%s" must define an CAPABILITY property.', 25 get_class($this))); 26 } 27 28 if (!is_string($const)) { 29 throw new Exception( 30 pht( 31 'PolicyCapability class "%s" has an invalid CAPABILITY '. 32 'property. Capability constants must be a string.', 33 get_class($this))); 34 } 35 36 return $const; 37 } 38 39 40 /** 41 * Return a human-readable descriptive name for this capability, like 42 * "Can View". 43 * 44 * @return string Human-readable name describing the capability. 45 */ 46 abstract public function getCapabilityName(); 47 48 49 /** 50 * Return a human-readable string describing what not having this capability 51 * prevents the user from doing. For example: 52 * 53 * - You do not have permission to edit this object. 54 * - You do not have permission to create new tasks. 55 * 56 * @return string Human-readable name describing what failing a check for this 57 * capability prevents the user from doing. 58 */ 59 public function describeCapabilityRejection() { 60 return null; 61 } 62 63 /** 64 * Can this capability be set to "public"? Broadly, this is only appropriate 65 * for view and view-related policies. 66 * 67 * @return bool True to allow the "public" policy. Returns false by default. 68 */ 69 public function shouldAllowPublicPolicySetting() { 70 return false; 71 } 72 73 final public static function getCapabilityByKey($key) { 74 return idx(self::getCapabilityMap(), $key); 75 } 76 77 final public static function getCapabilityMap() { 78 static $map; 79 if ($map === null) { 80 $capabilities = id(new PhutilSymbolLoader()) 81 ->setAncestorClass(__CLASS__) 82 ->loadObjects(); 83 84 $map = mpull($capabilities, null, 'getCapabilityKey'); 85 } 86 87 return $map; 88 } 89 90 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |