[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/policy/rule/ -> PhabricatorPolicyRule.php (source)

   1  <?php
   2  
   3  abstract class PhabricatorPolicyRule {
   4  
   5    const CONTROL_TYPE_TEXT       = 'text';
   6    const CONTROL_TYPE_SELECT     = 'select';
   7    const CONTROL_TYPE_TOKENIZER  = 'tokenizer';
   8    const CONTROL_TYPE_NONE       = 'none';
   9  
  10    abstract public function getRuleDescription();
  11    abstract public function applyRule(PhabricatorUser $viewer, $value);
  12  
  13    public function willApplyRules(PhabricatorUser $viewer, array $values) {
  14      return;
  15    }
  16  
  17    public function getValueControlType() {
  18      return self::CONTROL_TYPE_TEXT;
  19    }
  20  
  21    public function getValueControlTemplate() {
  22      return null;
  23    }
  24  
  25    public function getRuleOrder() {
  26      return 500;
  27    }
  28  
  29    public function getValueForStorage($value) {
  30      return $value;
  31    }
  32  
  33    public function getValueForDisplay(PhabricatorUser $viewer, $value) {
  34      return $value;
  35    }
  36  
  37    public function getRequiredHandlePHIDsForSummary($value) {
  38      $phids = array();
  39      switch ($this->getValueControlType()) {
  40        case self::CONTROL_TYPE_TOKENIZER:
  41          $phids = $value;
  42          break;
  43        case self::CONTROL_TYPE_TEXT:
  44        case self::CONTROL_TYPE_SELECT:
  45        case self::CONTROL_TYPE_NONE:
  46        default:
  47          if (phid_get_type($value) !=
  48              PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) {
  49            $phids = array($value);
  50          } else {
  51            $phids = array();
  52          }
  53          break;
  54      }
  55  
  56      return $phids;
  57    }
  58  
  59    /**
  60     * Return true if the given value creates a rule with a meaningful effect.
  61     * An example of a rule with no meaningful effect is a "users" rule with no
  62     * users specified.
  63     *
  64     * @return bool True if the value creates a meaningful rule.
  65     */
  66    public function ruleHasEffect($value) {
  67      return true;
  68    }
  69  
  70  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1