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.
8 abstract class PhabricatorPolicyCodex
16 public function getPolicyShortName() {
20 public function getPolicyIcon() {
24 public function getPolicyTagClasses() {
28 public function getPolicySpecialRuleDescriptions() {
32 public function getPolicyForEdit($capability) {
33 return $this->getObject()->getPolicy($capability);
36 public function getDefaultPolicy() {
37 return PhabricatorPolicyQuery
::getDefaultPolicyForObject(
43 final protected function newRule() {
44 return new PhabricatorPolicyCodexRuleDescription();
47 final public function setViewer(PhabricatorUser
$viewer) {
48 $this->viewer
= $viewer;
52 final public function getViewer() {
56 final public function setObject(PhabricatorPolicyCodexInterface
$object) {
57 $this->object = $object;
61 final public function getObject() {
65 final public function setCapability($capability) {
66 $this->capability
= $capability;
70 final public function getCapability() {
71 return $this->capability
;
74 final public function setPolicy(PhabricatorPolicy
$policy) {
75 $this->policy
= $policy;
79 final public function getPolicy() {
83 final public static function newFromObject(
84 PhabricatorPolicyCodexInterface
$object,
85 PhabricatorUser
$viewer) {
87 if (!($object instanceof PhabricatorPolicyInterface
)) {
90 'Object (of class "%s") implements interface "%s", but must also '.
91 'implement interface "%s".',
93 'PhabricatorPolicyCodexInterface',
94 'PhabricatorPolicyInterface'));
97 $codex = $object->newPolicyCodex();
98 if (!($codex instanceof PhabricatorPolicyCodex
)) {
101 'Object (of class "%s") implements interface "%s", but defines '.
102 'method "%s" incorrectly: this method must return an object of '.
105 'PhabricatorPolicyCodexInterface',
112 ->setViewer($viewer);