@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.

at recaptime-dev/main 117 lines 2.7 kB view raw
1<?php 2 3/** 4 * Rendering extensions that allows an object to render custom strings, 5 * descriptions and explanations for the policy system to help users 6 * understand complex policies. 7 */ 8abstract class PhabricatorPolicyCodex 9 extends Phobject { 10 11 private $viewer; 12 private $object; 13 private $policy; 14 private $capability; 15 16 public function getPolicyShortName() { 17 return null; 18 } 19 20 public function getPolicyIcon() { 21 return null; 22 } 23 24 public function getPolicyTagClasses() { 25 return array(); 26 } 27 28 public function getPolicySpecialRuleDescriptions() { 29 return array(); 30 } 31 32 public function getPolicyForEdit($capability) { 33 return $this->getObject()->getPolicy($capability); 34 } 35 36 public function getDefaultPolicy() { 37 return PhabricatorPolicyQuery::getDefaultPolicyForObject( 38 $this->viewer, 39 $this->object, 40 $this->capability); 41 } 42 43 final protected function newRule() { 44 return new PhabricatorPolicyCodexRuleDescription(); 45 } 46 47 final public function setViewer(PhabricatorUser $viewer) { 48 $this->viewer = $viewer; 49 return $this; 50 } 51 52 final public function getViewer() { 53 return $this->viewer; 54 } 55 56 final public function setObject(PhabricatorPolicyCodexInterface $object) { 57 $this->object = $object; 58 return $this; 59 } 60 61 final public function getObject() { 62 return $this->object; 63 } 64 65 final public function setCapability($capability) { 66 $this->capability = $capability; 67 return $this; 68 } 69 70 final public function getCapability() { 71 return $this->capability; 72 } 73 74 final public function setPolicy(PhabricatorPolicy $policy) { 75 $this->policy = $policy; 76 return $this; 77 } 78 79 final public function getPolicy() { 80 return $this->policy; 81 } 82 83 final public static function newFromObject( 84 PhabricatorPolicyCodexInterface $object, 85 PhabricatorUser $viewer) { 86 87 if (!($object instanceof PhabricatorPolicyInterface)) { 88 throw new Exception( 89 pht( 90 'Object (of class "%s") implements interface "%s", but must also '. 91 'implement interface "%s".', 92 get_class($object), 93 'PhabricatorPolicyCodexInterface', 94 'PhabricatorPolicyInterface')); 95 } 96 97 $codex = $object->newPolicyCodex(); 98 if (!($codex instanceof PhabricatorPolicyCodex)) { 99 throw new Exception( 100 pht( 101 'Object (of class "%s") implements interface "%s", but defines '. 102 'method "%s" incorrectly: this method must return an object of '. 103 'class "%s".', 104 get_class($object), 105 'PhabricatorPolicyCodexInterface', 106 'newPolicyCodex()', 107 self::class)); 108 } 109 110 $codex 111 ->setObject($object) 112 ->setViewer($viewer); 113 114 return $codex; 115 } 116 117}