Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / policy / codex / PhabricatorPolicyCodex.php
blob9bccb842bb72ddf02701e310cac43966bd6e82d4
1 <?php
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 */
8 abstract class PhabricatorPolicyCodex
9 extends Phobject {
11 private $viewer;
12 private $object;
13 private $policy;
14 private $capability;
16 public function getPolicyShortName() {
17 return null;
20 public function getPolicyIcon() {
21 return null;
24 public function getPolicyTagClasses() {
25 return array();
28 public function getPolicySpecialRuleDescriptions() {
29 return array();
32 public function getPolicyForEdit($capability) {
33 return $this->getObject()->getPolicy($capability);
36 public function getDefaultPolicy() {
37 return PhabricatorPolicyQuery::getDefaultPolicyForObject(
38 $this->viewer,
39 $this->object,
40 $this->capability);
43 final protected function newRule() {
44 return new PhabricatorPolicyCodexRuleDescription();
47 final public function setViewer(PhabricatorUser $viewer) {
48 $this->viewer = $viewer;
49 return $this;
52 final public function getViewer() {
53 return $this->viewer;
56 final public function setObject(PhabricatorPolicyCodexInterface $object) {
57 $this->object = $object;
58 return $this;
61 final public function getObject() {
62 return $this->object;
65 final public function setCapability($capability) {
66 $this->capability = $capability;
67 return $this;
70 final public function getCapability() {
71 return $this->capability;
74 final public function setPolicy(PhabricatorPolicy $policy) {
75 $this->policy = $policy;
76 return $this;
79 final public function getPolicy() {
80 return $this->policy;
83 final public static function newFromObject(
84 PhabricatorPolicyCodexInterface $object,
85 PhabricatorUser $viewer) {
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'));
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 __CLASS__));
110 $codex
111 ->setObject($object)
112 ->setViewer($viewer);
114 return $codex;