Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php abstract class HeraldAdapter extends Phobject { const CONDITION_CONTAINS = "\143\15..

Decoded Output download

<?php
 abstract class HeraldAdapter extends Phobject { const CONDITION_CONTAINS = "contains"; const CONDITION_NOT_CONTAINS = "!contains"; const CONDITION_IS = "is"; const CONDITION_IS_NOT = "!is"; const CONDITION_IS_ANY = "isany"; const CONDITION_IS_NOT_ANY = "!isany"; const CONDITION_INCLUDE_ALL = "all"; const CONDITION_INCLUDE_ANY = "any"; const CONDITION_INCLUDE_NONE = "none"; const CONDITION_IS_ME = "me"; const CONDITION_IS_NOT_ME = "!me"; const CONDITION_REGEXP = "regexp"; const CONDITION_NOT_REGEXP = "!regexp"; const CONDITION_RULE = "conditions"; const CONDITION_NOT_RULE = "!conditions"; const CONDITION_EXISTS = "exists"; const CONDITION_NOT_EXISTS = "!exists"; const CONDITION_UNCONDITIONALLY = "unconditionally"; const CONDITION_NEVER = "never"; const CONDITION_REGEXP_PAIR = "regexp-pair"; const CONDITION_HAS_BIT = "bit"; const CONDITION_NOT_BIT = "!bit"; const CONDITION_IS_TRUE = "true"; const CONDITION_IS_FALSE = "false"; private $contentSource; private $isNewObject; private $applicationEmail; private $appliedTransactions = array(); private $queuedTransactions = array(); private $emailPHIDs = array(); private $forcedEmailPHIDs = array(); private $fieldMap; private $actionMap; private $edgeCache = array(); private $forbiddenActions = array(); private $viewer; private $mustEncryptReasons = array(); private $actingAsPHID; private $webhookMap = array(); public function getEmailPHIDs() { return array_values($this->emailPHIDs); } public function getForcedEmailPHIDs() { return array_values($this->forcedEmailPHIDs); } public final function setActingAsPHID($acting_as_phid) { $this->actingAsPHID = $acting_as_phid; return $this; } public final function getActingAsPHID() { return $this->actingAsPHID; } public function addEmailPHID($phid, $force) { $this->emailPHIDs[$phid] = $phid; if ($force) { $this->forcedEmailPHIDs[$phid] = $phid; } return $this; } public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; return $this; } public function getViewer() { if ($this->viewer) { return $this->viewer; } return PhabricatorUser::getOmnipotentUser(); } public function setContentSource(PhabricatorContentSource $content_source) { $this->contentSource = $content_source; return $this; } public function getContentSource() { return $this->contentSource; } public function getIsNewObject() { if (is_bool($this->isNewObject)) { return $this->isNewObject; } throw new Exception(pht("You must %s to a boolean first!", "setIsNewObject()")); } public function setIsNewObject($new) { $this->isNewObject = (bool) $new; return $this; } public function supportsApplicationEmail() { return false; } public function setApplicationEmail(PhabricatorMetaMTAApplicationEmail $email) { $this->applicationEmail = $email; return $this; } public function getApplicationEmail() { return $this->applicationEmail; } public function getPHID() { return $this->getObject()->getPHID(); } public abstract function getHeraldName(); public final function willGetHeraldField($field_key) { $this->requireFieldImplementation($field_key); } public function getHeraldField($field_key) { return $this->requireFieldImplementation($field_key)->getHeraldFieldValue($this->getObject()); } public function applyHeraldEffects(array $effects) { assert_instances_of($effects, "HeraldEffect"); $result = array(); foreach ($effects as $effect) { $result[] = $this->applyStandardEffect($effect); } return $result; } public function isAvailableToUser(PhabricatorUser $viewer) { $applications = id(new PhabricatorApplicationQuery())->setViewer($viewer)->withInstalled(true)->withClasses(array($this->getAdapterApplicationClass()))->execute(); return !empty($applications); } public final function setAppliedTransactions(array $xactions) { assert_instances_of($xactions, "PhabricatorApplicationTransaction"); $this->appliedTransactions = $xactions; return $this; } public final function getAppliedTransactions() { return $this->appliedTransactions; } public final function queueTransaction(PhabricatorApplicationTransaction $transaction) { $this->queuedTransactions[] = $transaction; } public final function getQueuedTransactions() { return $this->queuedTransactions; } public final function newTransaction() { $object = $this->newObject(); if (!$object instanceof PhabricatorApplicationTransactionInterface) { throw new Exception(pht("Unable to build a new transaction for adapter object; it does " . "not implement "%s".", "PhabricatorApplicationTransactionInterface")); } $xaction = $object->getApplicationTransactionTemplate(); if (!$xaction instanceof PhabricatorApplicationTransaction) { throw new Exception(pht("Expected object (of class "%s") to return a transaction template " . "(of class "%s"), but it returned something else ("%s").", get_class($object), "PhabricatorApplicationTransaction", phutil_describe_type($xaction))); } return $xaction; } public function getAdapterContentType() { return get_class($this); } public abstract function getAdapterContentName(); public abstract function getAdapterContentDescription(); public abstract function getAdapterApplicationClass(); public abstract function getObject(); public function getAdapterContentIcon() { $application_class = $this->getAdapterApplicationClass(); $application = newv($application_class, array()); return $application->getIcon(); } protected function newObject() { return null; } public function supportsRuleType($rule_type) { return false; } public function canTriggerOnObject($object) { return false; } public function isTestAdapterForObject($object) { return false; } public function canCreateTestAdapterForObject($object) { return $this->isTestAdapterForObject($object); } public function newTestAdapter(PhabricatorUser $viewer, $object) { return id(clone $this)->setObject($object); } public function getAdapterTestDescription() { return null; } public function explainValidTriggerObjects() { return pht("This adapter can not trigger on objects."); } public function getTriggerObjectPHIDs() { return array($this->getPHID()); } public function getAdapterSortKey() { return sprintf("%08d%s", $this->getAdapterSortOrder(), $this->getAdapterContentName()); } public function getAdapterSortOrder() { return 1000; } private function getFieldImplementationMap() { if ($this->fieldMap === null) { $object = $this->getObject(); $map = array(); $all = HeraldField::getAllFields(); foreach ($all as $key => $field) { $field = id(clone $field)->setAdapter($this); if (!$field->supportsObject($object)) { continue; } $subfields = $field->getFieldsForObject($object); foreach ($subfields as $subkey => $subfield) { if (isset($map[$subkey])) { throw new Exception(pht("Two HeraldFields (of classes "%s" and "%s") have the same " . "field key ("%s") after expansion for an object of class " . ""%s" inside adapter "%s". Each field must have a unique " . "field key.", get_class($subfield), get_class($map[$subkey]), $subkey, get_class($object), get_class($this))); } $subfield = id(clone $subfield)->setAdapter($this); $map[$subkey] = $subfield; } } $this->fieldMap = $map; } return $this->fieldMap; } private function getFieldImplementation($key) { return idx($this->getFieldImplementationMap(), $key); } public function getFields() { return array_keys($this->getFieldImplementationMap()); } public function getFieldNameMap() { return mpull($this->getFieldImplementationMap(), "getHeraldFieldName"); } public function getFieldGroupKey($field_key) { $field = $this->getFieldImplementation($field_key); if (!$field) { return null; } return $field->getFieldGroupKey(); } public function isFieldAvailable($field_key) { $field = $this->getFieldImplementation($field_key); if (!$field) { return null; } return $field->isFieldAvailable(); } public function getConditionNameMap() { return array(self::CONDITION_CONTAINS => pht("contains"), self::CONDITION_NOT_CONTAINS => pht("does not contain"), self::CONDITION_IS => pht("is"), self::CONDITION_IS_NOT => pht("is not"), self::CONDITION_IS_ANY => pht("is any of"), self::CONDITION_IS_TRUE => pht("is true"), self::CONDITION_IS_FALSE => pht("is false"), self::CONDITION_IS_NOT_ANY => pht("is not any of"), self::CONDITION_INCLUDE_ALL => pht("include all of"), self::CONDITION_INCLUDE_ANY => pht("include any of"), self::CONDITION_INCLUDE_NONE => pht("include none of"), self::CONDITION_IS_ME => pht("is myself"), self::CONDITION_IS_NOT_ME => pht("is not myself"), self::CONDITION_REGEXP => pht("matches regexp"), self::CONDITION_NOT_REGEXP => pht("does not match regexp"), self::CONDITION_RULE => pht("matches:"), self::CONDITION_NOT_RULE => pht("does not match:"), self::CONDITION_EXISTS => pht("exists"), self::CONDITION_NOT_EXISTS => pht("does not exist"), self::CONDITION_UNCONDITIONALLY => '', self::CONDITION_NEVER => '', self::CONDITION_REGEXP_PAIR => pht("matches regexp pair"), self::CONDITION_HAS_BIT => pht("has bit"), self::CONDITION_NOT_BIT => pht("lacks bit")); } public function getConditionsForField($field) { return $this->requireFieldImplementation($field)->getHeraldFieldConditions(); } private function requireFieldImplementation($field_key) { $field = $this->getFieldImplementation($field_key); if (!$field) { throw new Exception(pht("No field with key "%s" is available to Herald adapter "%s".", $field_key, get_class($this))); } return $field; } public function doesConditionMatch(HeraldEngine $engine, HeraldRule $rule, HeraldCondition $condition, $field_value) { $condition_type = $condition->getFieldCondition(); $condition_value = $condition->getValue(); switch ($condition_type) { case self::CONDITION_CONTAINS: case self::CONDITION_NOT_CONTAINS: $result_if_match = $condition_type == self::CONDITION_CONTAINS; foreach ((array) $field_value as $value) { if (stripos($value, $condition_value) !== false) { return $result_if_match; } } return !$result_if_match; case self::CONDITION_IS: return $field_value == $condition_value; case self::CONDITION_IS_NOT: return $field_value != $condition_value; case self::CONDITION_IS_ME: return $field_value == $rule->getAuthorPHID(); case self::CONDITION_IS_NOT_ME: return $field_value != $rule->getAuthorPHID(); case self::CONDITION_IS_ANY: if (!is_array($condition_value)) { throw new HeraldInvalidConditionException(pht("Expected condition value to be an array.")); } $condition_value = array_fuse($condition_value); return isset($condition_value[$field_value]); case self::CONDITION_IS_NOT_ANY: if (!is_array($condition_value)) { throw new HeraldInvalidConditionException(pht("Expected condition value to be an array.")); } $condition_value = array_fuse($condition_value); return !isset($condition_value[$field_value]); case self::CONDITION_INCLUDE_ALL: if (!is_array($field_value)) { throw new HeraldInvalidConditionException(pht("Object produced non-array value!")); } if (!is_array($condition_value)) { throw new HeraldInvalidConditionException(pht("Expected condition value to be an array.")); } $have = array_select_keys(array_fuse($field_value), $condition_value); return count($have) == count($condition_value); case self::CONDITION_INCLUDE_ANY: return (bool) array_select_keys(array_fuse($field_value), $condition_value); case self::CONDITION_INCLUDE_NONE: return !array_select_keys(array_fuse($field_value), $condition_value); case self::CONDITION_EXISTS: case self::CONDITION_IS_TRUE: return (bool) $field_value; case self::CONDITION_NOT_EXISTS: case self::CONDITION_IS_FALSE: return !$field_value; case self::CONDITION_UNCONDITIONALLY: return (bool) $field_value; case self::CONDITION_NEVER: return false; case self::CONDITION_REGEXP: case self::CONDITION_NOT_REGEXP: $result_if_match = $condition_type == self::CONDITION_REGEXP; $condition_pattern = $condition_value . "S"; foreach ((array) $field_value as $value) { try { $result = phutil_preg_match($condition_pattern, $value); } catch (PhutilRegexException $ex) { $message = array(); $message[] = pht("Regular expression "%s" in Herald rule "%s" is not valid, " . "or exceeded backtracking or recursion limits while " . "executing. Verify the expression and correct it or rewrite " . "it with less backtracking.", $condition_value, $rule->getMonogram()); $message[] = $ex->getMessage(); $message = implode("

", $message); throw new HeraldInvalidConditionException($message); } if ($result) { return $result_if_match; } } return !$result_if_match; case self::CONDITION_REGEXP_PAIR: $regexp_pair = null; try { $regexp_pair = phutil_json_decode($condition_value); } catch (PhutilJSONParserException $ex) { throw new HeraldInvalidConditionException(pht("Regular expression pair is not valid JSON!")); } if (count($regexp_pair) != 2) { throw new HeraldInvalidConditionException(pht("Regular expression pair is not a pair!")); } $key_regexp = array_shift($regexp_pair); $value_regexp = array_shift($regexp_pair); foreach ((array) $field_value as $key => $value) { $key_matches = @preg_match($key_regexp, $key); if ($key_matches === false) { throw new HeraldInvalidConditionException(pht("First regular expression is invalid!")); } if ($key_matches) { $value_matches = @preg_match($value_regexp, $value); if ($value_matches === false) { throw new HeraldInvalidConditionException(pht("Second regular expression is invalid!")); } if ($value_matches) { return true; } } } return false; case self::CONDITION_RULE: case self::CONDITION_NOT_RULE: $rule = $engine->getRule($condition_value); if (!$rule) { throw new HeraldInvalidConditionException(pht("Condition references a rule which does not exist!")); } $is_not = $condition_type == self::CONDITION_NOT_RULE; $result = $engine->doesRuleMatch($rule, $this); if ($is_not) { $result = !$result; } return $result; case self::CONDITION_HAS_BIT: return ($condition_value & $field_value) === (int) $condition_value; case self::CONDITION_NOT_BIT: return ($condition_value & $field_value) !== (int) $condition_value; default: throw new HeraldInvalidConditionException(pht("Unknown condition '%s'.", $condition_type)); } } public function willSaveCondition(HeraldCondition $condition) { $condition_type = $condition->getFieldCondition(); $condition_value = $condition->getValue(); switch ($condition_type) { case self::CONDITION_REGEXP: case self::CONDITION_NOT_REGEXP: $ok = @preg_match($condition_value, ''); if ($ok === false) { throw new HeraldInvalidConditionException(pht("The regular expression "%s" is not valid. Regular expressions " . "must have enclosing characters (e.g. "@/path/to/file@", not " . ""/path/to/file") and be syntactically correct.", $condition_value)); } break; case self::CONDITION_REGEXP_PAIR: $json = null; try { $json = phutil_json_decode($condition_value); } catch (PhutilJSONParserException $ex) { throw new HeraldInvalidConditionException(pht("The regular expression pair "%s" is not valid JSON. Enter a " . "valid JSON array with two elements.", $condition_value)); } if (count($json) != 2) { throw new HeraldInvalidConditionException(pht("The regular expression pair "%s" must have exactly two " . "elements.", $condition_value)); } $key_regexp = array_shift($json); $val_regexp = array_shift($json); $key_ok = @preg_match($key_regexp, ''); if ($key_ok === false) { throw new HeraldInvalidConditionException(pht("The first regexp in the regexp pair, "%s", is not a valid " . "regexp.", $key_regexp)); } $val_ok = @preg_match($val_regexp, ''); if ($val_ok === false) { throw new HeraldInvalidConditionException(pht("The second regexp in the regexp pair, "%s", is not a valid " . "regexp.", $val_regexp)); } break; case self::CONDITION_CONTAINS: case self::CONDITION_NOT_CONTAINS: case self::CONDITION_IS: case self::CONDITION_IS_NOT: case self::CONDITION_IS_ANY: case self::CONDITION_IS_NOT_ANY: case self::CONDITION_INCLUDE_ALL: case self::CONDITION_INCLUDE_ANY: case self::CONDITION_INCLUDE_NONE: case self::CONDITION_IS_ME: case self::CONDITION_IS_NOT_ME: case self::CONDITION_RULE: case self::CONDITION_NOT_RULE: case self::CONDITION_EXISTS: case self::CONDITION_NOT_EXISTS: case self::CONDITION_UNCONDITIONALLY: case self::CONDITION_NEVER: case self::CONDITION_HAS_BIT: case self::CONDITION_NOT_BIT: case self::CONDITION_IS_TRUE: case self::CONDITION_IS_FALSE: break; default: throw new HeraldInvalidConditionException(pht("Unknown condition "%s"!", $condition_type)); } } private function getActionImplementationMap() { if ($this->actionMap === null) { $object = $this->getObject(); $map = array(); $all = HeraldAction::getAllActions(); foreach ($all as $key => $action) { $action = id(clone $action)->setAdapter($this); if (!$action->supportsObject($object)) { continue; } $subactions = $action->getActionsForObject($object); foreach ($subactions as $subkey => $subaction) { if (isset($map[$subkey])) { throw new Exception(pht("Two HeraldActions (of classes "%s" and "%s") have the same " . "action key ("%s") after expansion for an object of class " . ""%s" inside adapter "%s". Each action must have a unique " . "action key.", get_class($subaction), get_class($map[$subkey]), $subkey, get_class($object), get_class($this))); } $subaction = id(clone $subaction)->setAdapter($this); $map[$subkey] = $subaction; } } $this->actionMap = $map; } return $this->actionMap; } private function requireActionImplementation($action_key) { $action = $this->getActionImplementation($action_key); if (!$action) { throw new Exception(pht("No action with key "%s" is available to Herald adapter "%s".", $action_key, get_class($this))); } return $action; } private function getActionsForRuleType($rule_type) { $actions = $this->getActionImplementationMap(); foreach ($actions as $key => $action) { if (!$action->supportsRuleType($rule_type)) { unset($actions[$key]); } } return $actions; } public function getActionImplementation($key) { return idx($this->getActionImplementationMap(), $key); } public function getActionKeys() { return array_keys($this->getActionImplementationMap()); } public function getActionGroupKey($action_key) { $action = $this->getActionImplementation($action_key); if (!$action) { return null; } return $action->getActionGroupKey(); } public function isActionAvailable($action_key) { $action = $this->getActionImplementation($action_key); if (!$action) { return null; } return $action->isActionAvailable(); } public function getActions($rule_type) { $actions = array(); foreach ($this->getActionsForRuleType($rule_type) as $key => $action) { $actions[] = $key; } return $actions; } public function getActionNameMap($rule_type) { $map = array(); foreach ($this->getActionsForRuleType($rule_type) as $key => $action) { $map[$key] = $action->getHeraldActionName(); } return $map; } public function willSaveAction(HeraldRule $rule, HeraldActionRecord $action) { $impl = $this->requireActionImplementation($action->getAction()); $target = $action->getTarget(); $target = $impl->willSaveActionValue($target); $action->setTarget($target); } public function getValueTypeForFieldAndCondition($field, $condition) { return $this->requireFieldImplementation($field)->getHeraldFieldValueType($condition); } public function getValueTypeForAction($action, $rule_type) { $impl = $this->requireActionImplementation($action); return $impl->getHeraldActionValueType(); } private function buildTokenizerFieldValue(PhabricatorTypeaheadDatasource $datasource) { $key = "action." . get_class($datasource); return id(new HeraldTokenizerFieldValue())->setKey($key)->setDatasource($datasource); } public function getRepetitionOptions() { $options = array(); $options[] = HeraldRule::REPEAT_EVERY; if (!$this->isSingleEventAdapter()) { $options[] = HeraldRule::REPEAT_FIRST; $options[] = HeraldRule::REPEAT_CHANGE; } return $options; } protected function initializeNewAdapter() { $this->setObject($this->newObject()); return $this; } public function isSingleEventAdapter() { return false; } public static function getAllAdapters() { return id(new PhutilClassMapQuery())->setAncestorClass(__CLASS__)->setUniqueMethod("getAdapterContentType")->setSortMethod("getAdapterSortKey")->execute(); } public static function getAdapterForContentType($content_type) { $adapters = self::getAllAdapters(); foreach ($adapters as $adapter) { if ($adapter->getAdapterContentType() == $content_type) { $adapter = id(clone $adapter); $adapter->initializeNewAdapter(); return $adapter; } } throw new Exception(pht("No adapter exists for Herald content type "%s".", $content_type)); } public static function getEnabledAdapterMap(PhabricatorUser $viewer) { $map = array(); $adapters = self::getAllAdapters(); foreach ($adapters as $adapter) { if (!$adapter->isAvailableToUser($viewer)) { continue; } $type = $adapter->getAdapterContentType(); $name = $adapter->getAdapterContentName(); $map[$type] = $name; } return $map; } public function getEditorValueForCondition(PhabricatorUser $viewer, HeraldCondition $condition) { $field = $this->requireFieldImplementation($condition->getFieldName()); return $field->getEditorValue($viewer, $condition->getFieldCondition(), $condition->getValue()); } public function getEditorValueForAction(PhabricatorUser $viewer, HeraldActionRecord $action_record) { $action = $this->requireActionImplementation($action_record->getAction()); return $action->getEditorValue($viewer, $action_record->getTarget()); } public function renderRuleAsText(HeraldRule $rule, PhabricatorUser $viewer) { require_celerity_resource("herald-css"); $icon = id(new PHUIIconView())->setIcon("fa-chevron-circle-right lightgreytext")->addClass("herald-list-icon"); if ($rule->getMustMatchAll()) { $match_text = pht("When all of these conditions are met:"); } else { $match_text = pht("When any of these conditions are met:"); } $match_title = phutil_tag("p", array("class" => "herald-list-description"), $match_text); $match_list = array(); foreach ($rule->getConditions() as $condition) { $match_list[] = phutil_tag("div", array("class" => "herald-list-item"), array($icon, $this->renderConditionAsText($condition, $viewer))); } if ($rule->isRepeatFirst()) { $action_text = pht("Take these actions the first time this rule matches:"); } else { if ($rule->isRepeatOnChange()) { $action_text = pht("Take these actions if this rule did not match the last time:"); } else { $action_text = pht("Take these actions every time this rule matches:"); } } $action_title = phutil_tag("p", array("class" => "herald-list-description"), $action_text); $action_list = array(); foreach ($rule->getActions() as $action) { $action_list[] = phutil_tag("div", array("class" => "herald-list-item"), array($icon, $this->renderActionAsText($viewer, $action))); } return array($match_title, $match_list, $action_title, $action_list); } private function renderConditionAsText(HeraldCondition $condition, PhabricatorUser $viewer) { $field_type = $condition->getFieldName(); $field = $this->getFieldImplementation($field_type); if (!$field) { return pht("Unknown Field: "%s"", $field_type); } $field_name = $field->getHeraldFieldName(); $condition_type = $condition->getFieldCondition(); $condition_name = idx($this->getConditionNameMap(), $condition_type); $value = $this->renderConditionValueAsText($condition, $viewer); return array($field_name, " ", $condition_name, " ", $value); } private function renderActionAsText(PhabricatorUser $viewer, HeraldActionRecord $action_record) { $action_type = $action_record->getAction(); $action_value = $action_record->getTarget(); $action = $this->getActionImplementation($action_type); if (!$action) { return pht("Unknown Action ("%s")", $action_type); } $action->setViewer($viewer); return $action->renderActionDescription($action_value); } private function renderConditionValueAsText(HeraldCondition $condition, PhabricatorUser $viewer) { $field = $this->requireFieldImplementation($condition->getFieldName()); return $field->renderConditionValue($viewer, $condition->getFieldCondition(), $condition->getValue()); } public function renderFieldTranscriptValue(PhabricatorUser $viewer, $field_type, $field_value) { $field = $this->getFieldImplementation($field_type); if ($field) { return $field->renderTranscriptValue($viewer, $field_value); } return phutil_tag("em", array(), pht("Unable to render value for unknown field type ("%s").", $field_type)); } protected function applyStandardEffect(HeraldEffect $effect) { $action = $effect->getAction(); $rule_type = $effect->getRule()->getRuleType(); $impl = $this->getActionImplementation($action); if (!$impl) { return new HeraldApplyTranscript($effect, false, array(array(HeraldAction::DO_STANDARD_INVALID_ACTION, $action))); } if (!$impl->supportsRuleType($rule_type)) { return new HeraldApplyTranscript($effect, false, array(array(HeraldAction::DO_STANDARD_WRONG_RULE_TYPE, $rule_type))); } $impl->applyEffect($this->getObject(), $effect); return $impl->getApplyTranscript($effect); } public function loadEdgePHIDs($type) { if (!isset($this->edgeCache[$type])) { $phids = PhabricatorEdgeQuery::loadDestinationPHIDs($this->getObject()->getPHID(), $type); $this->edgeCache[$type] = array_fuse($phids); } return $this->edgeCache[$type]; } public final function getForbiddenActions() { return array_keys($this->forbiddenActions); } public final function setForbiddenAction($action, $reason) { $this->forbiddenActions[$action] = $reason; return $this; } public final function getRequiredFieldStates($field_key) { return $this->requireFieldImplementation($field_key)->getRequiredAdapterStates(); } public final function getRequiredActionStates($action_key) { return $this->requireActionImplementation($action_key)->getRequiredAdapterStates(); } public final function getForbiddenReason($action) { if (!isset($this->forbiddenActions[$action])) { throw new Exception(pht("Action "%s" is not forbidden!", $action)); } return $this->forbiddenActions[$action]; } public final function addMustEncryptReason($reason) { $this->mustEncryptReasons[] = $reason; return $this; } public final function getMustEncryptReasons() { return $this->mustEncryptReasons; } public function supportsWebhooks() { return true; } public final function queueWebhook($webhook_phid, $rule_phid) { $this->webhookMap[$webhook_phid][] = $rule_phid; return $this; } public final function getWebhookMap() { return $this->webhookMap; } } ?>

Did this file decode correctly?

Original Code

<?php
 abstract class HeraldAdapter extends Phobject { const CONDITION_CONTAINS = "\143\157\x6e\164\x61\x69\x6e\163"; const CONDITION_NOT_CONTAINS = "\x21\143\x6f\x6e\x74\x61\x69\x6e\x73"; const CONDITION_IS = "\x69\163"; const CONDITION_IS_NOT = "\x21\x69\163"; const CONDITION_IS_ANY = "\151\x73\x61\x6e\171"; const CONDITION_IS_NOT_ANY = "\41\151\x73\141\x6e\x79"; const CONDITION_INCLUDE_ALL = "\x61\x6c\x6c"; const CONDITION_INCLUDE_ANY = "\141\156\x79"; const CONDITION_INCLUDE_NONE = "\x6e\157\156\145"; const CONDITION_IS_ME = "\x6d\145"; const CONDITION_IS_NOT_ME = "\x21\155\145"; const CONDITION_REGEXP = "\x72\145\147\145\x78\x70"; const CONDITION_NOT_REGEXP = "\41\x72\x65\147\x65\x78\160"; const CONDITION_RULE = "\143\157\x6e\144\151\x74\x69\x6f\156\x73"; const CONDITION_NOT_RULE = "\41\143\157\x6e\144\151\x74\151\x6f\x6e\x73"; const CONDITION_EXISTS = "\145\x78\151\x73\164\163"; const CONDITION_NOT_EXISTS = "\x21\145\170\x69\x73\164\x73"; const CONDITION_UNCONDITIONALLY = "\165\x6e\x63\157\x6e\144\151\164\151\x6f\156\x61\x6c\154\171"; const CONDITION_NEVER = "\156\145\166\x65\162"; const CONDITION_REGEXP_PAIR = "\162\145\147\x65\x78\x70\55\x70\141\151\x72"; const CONDITION_HAS_BIT = "\x62\x69\164"; const CONDITION_NOT_BIT = "\x21\142\151\x74"; const CONDITION_IS_TRUE = "\x74\x72\165\145"; const CONDITION_IS_FALSE = "\x66\141\154\163\145"; private $contentSource; private $isNewObject; private $applicationEmail; private $appliedTransactions = array(); private $queuedTransactions = array(); private $emailPHIDs = array(); private $forcedEmailPHIDs = array(); private $fieldMap; private $actionMap; private $edgeCache = array(); private $forbiddenActions = array(); private $viewer; private $mustEncryptReasons = array(); private $actingAsPHID; private $webhookMap = array(); public function getEmailPHIDs() { return array_values($this->emailPHIDs); } public function getForcedEmailPHIDs() { return array_values($this->forcedEmailPHIDs); } public final function setActingAsPHID($acting_as_phid) { $this->actingAsPHID = $acting_as_phid; return $this; } public final function getActingAsPHID() { return $this->actingAsPHID; } public function addEmailPHID($phid, $force) { $this->emailPHIDs[$phid] = $phid; if ($force) { $this->forcedEmailPHIDs[$phid] = $phid; } return $this; } public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; return $this; } public function getViewer() { if ($this->viewer) { return $this->viewer; } return PhabricatorUser::getOmnipotentUser(); } public function setContentSource(PhabricatorContentSource $content_source) { $this->contentSource = $content_source; return $this; } public function getContentSource() { return $this->contentSource; } public function getIsNewObject() { if (is_bool($this->isNewObject)) { return $this->isNewObject; } throw new Exception(pht("\x59\157\165\x20\x6d\x75\163\x74\x20\x25\x73\40\164\157\x20\141\x20\142\x6f\x6f\154\145\141\156\x20\146\x69\x72\x73\164\41", "\x73\145\x74\x49\163\x4e\145\167\117\142\152\x65\x63\x74\50\51")); } public function setIsNewObject($new) { $this->isNewObject = (bool) $new; return $this; } public function supportsApplicationEmail() { return false; } public function setApplicationEmail(PhabricatorMetaMTAApplicationEmail $email) { $this->applicationEmail = $email; return $this; } public function getApplicationEmail() { return $this->applicationEmail; } public function getPHID() { return $this->getObject()->getPHID(); } public abstract function getHeraldName(); public final function willGetHeraldField($field_key) { $this->requireFieldImplementation($field_key); } public function getHeraldField($field_key) { return $this->requireFieldImplementation($field_key)->getHeraldFieldValue($this->getObject()); } public function applyHeraldEffects(array $effects) { assert_instances_of($effects, "\x48\145\x72\141\x6c\x64\105\146\x66\145\143\x74"); $result = array(); foreach ($effects as $effect) { $result[] = $this->applyStandardEffect($effect); } return $result; } public function isAvailableToUser(PhabricatorUser $viewer) { $applications = id(new PhabricatorApplicationQuery())->setViewer($viewer)->withInstalled(true)->withClasses(array($this->getAdapterApplicationClass()))->execute(); return !empty($applications); } public final function setAppliedTransactions(array $xactions) { assert_instances_of($xactions, "\x50\150\x61\142\x72\x69\x63\x61\x74\157\162\x41\x70\160\x6c\151\143\x61\x74\x69\x6f\156\x54\x72\141\156\x73\x61\x63\x74\x69\x6f\156"); $this->appliedTransactions = $xactions; return $this; } public final function getAppliedTransactions() { return $this->appliedTransactions; } public final function queueTransaction(PhabricatorApplicationTransaction $transaction) { $this->queuedTransactions[] = $transaction; } public final function getQueuedTransactions() { return $this->queuedTransactions; } public final function newTransaction() { $object = $this->newObject(); if (!$object instanceof PhabricatorApplicationTransactionInterface) { throw new Exception(pht("\125\156\141\x62\154\145\40\x74\157\40\142\165\x69\154\x64\40\x61\40\156\x65\x77\x20\x74\x72\141\x6e\x73\141\143\x74\x69\x6f\156\40\146\x6f\x72\40\141\144\141\160\x74\145\x72\x20\x6f\142\152\x65\143\x74\x3b\40\x69\164\40\x64\x6f\145\x73\40" . "\x6e\x6f\x74\x20\x69\x6d\160\x6c\145\155\145\156\x74\40\42\x25\x73\x22\56", "\120\x68\141\x62\x72\x69\143\141\164\x6f\x72\x41\160\x70\x6c\151\x63\x61\164\x69\157\156\x54\x72\141\156\163\141\143\x74\x69\157\156\111\156\x74\x65\162\146\x61\x63\145")); } $xaction = $object->getApplicationTransactionTemplate(); if (!$xaction instanceof PhabricatorApplicationTransaction) { throw new Exception(pht("\105\170\x70\x65\x63\x74\x65\144\40\157\x62\x6a\x65\143\164\40\50\157\146\x20\143\x6c\x61\163\163\x20\42\45\163\x22\51\x20\164\x6f\40\x72\x65\164\165\162\x6e\40\x61\40\164\x72\141\x6e\x73\x61\143\164\151\157\x6e\40\164\145\x6d\160\154\x61\x74\x65\x20" . "\50\157\x66\40\143\x6c\141\163\x73\x20\x22\x25\x73\42\x29\54\x20\x62\165\x74\x20\151\x74\x20\162\145\x74\165\x72\156\145\144\x20\x73\x6f\x6d\145\x74\150\x69\x6e\x67\x20\x65\x6c\163\x65\40\50\42\x25\x73\42\51\x2e", get_class($object), "\x50\x68\x61\x62\162\151\143\x61\x74\x6f\x72\101\x70\160\154\151\x63\x61\164\151\x6f\x6e\x54\162\x61\156\163\x61\143\164\x69\x6f\156", phutil_describe_type($xaction))); } return $xaction; } public function getAdapterContentType() { return get_class($this); } public abstract function getAdapterContentName(); public abstract function getAdapterContentDescription(); public abstract function getAdapterApplicationClass(); public abstract function getObject(); public function getAdapterContentIcon() { $application_class = $this->getAdapterApplicationClass(); $application = newv($application_class, array()); return $application->getIcon(); } protected function newObject() { return null; } public function supportsRuleType($rule_type) { return false; } public function canTriggerOnObject($object) { return false; } public function isTestAdapterForObject($object) { return false; } public function canCreateTestAdapterForObject($object) { return $this->isTestAdapterForObject($object); } public function newTestAdapter(PhabricatorUser $viewer, $object) { return id(clone $this)->setObject($object); } public function getAdapterTestDescription() { return null; } public function explainValidTriggerObjects() { return pht("\x54\150\151\x73\40\141\x64\x61\160\164\x65\x72\x20\x63\141\156\40\x6e\157\164\40\x74\162\x69\x67\147\145\x72\x20\157\x6e\x20\x6f\x62\152\x65\143\x74\163\x2e"); } public function getTriggerObjectPHIDs() { return array($this->getPHID()); } public function getAdapterSortKey() { return sprintf("\x25\x30\70\x64\x25\x73", $this->getAdapterSortOrder(), $this->getAdapterContentName()); } public function getAdapterSortOrder() { return 1000; } private function getFieldImplementationMap() { if ($this->fieldMap === null) { $object = $this->getObject(); $map = array(); $all = HeraldField::getAllFields(); foreach ($all as $key => $field) { $field = id(clone $field)->setAdapter($this); if (!$field->supportsObject($object)) { continue; } $subfields = $field->getFieldsForObject($object); foreach ($subfields as $subkey => $subfield) { if (isset($map[$subkey])) { throw new Exception(pht("\124\x77\x6f\40\110\x65\162\141\x6c\144\106\151\x65\x6c\144\x73\x20\x28\x6f\x66\x20\143\154\141\x73\x73\145\163\x20\42\45\163\42\40\x61\x6e\x64\x20\x22\x25\163\42\51\40\150\x61\x76\x65\40\164\150\x65\40\163\141\x6d\145\x20" . "\x66\x69\x65\x6c\144\x20\x6b\145\x79\x20\50\42\x25\163\x22\51\x20\141\146\164\145\162\40\x65\170\160\x61\156\163\x69\x6f\156\x20\146\x6f\x72\40\x61\x6e\40\157\142\x6a\x65\143\x74\40\157\146\40\143\x6c\x61\x73\x73\x20" . "\42\45\x73\42\40\x69\156\x73\x69\x64\145\40\x61\144\x61\160\x74\x65\162\x20\42\x25\x73\x22\x2e\x20\105\141\143\150\x20\146\151\x65\154\144\40\155\165\x73\164\x20\150\141\166\145\x20\141\40\x75\156\x69\x71\x75\x65\x20" . "\146\151\145\154\x64\40\x6b\145\171\x2e", get_class($subfield), get_class($map[$subkey]), $subkey, get_class($object), get_class($this))); } $subfield = id(clone $subfield)->setAdapter($this); $map[$subkey] = $subfield; } } $this->fieldMap = $map; } return $this->fieldMap; } private function getFieldImplementation($key) { return idx($this->getFieldImplementationMap(), $key); } public function getFields() { return array_keys($this->getFieldImplementationMap()); } public function getFieldNameMap() { return mpull($this->getFieldImplementationMap(), "\147\145\164\110\145\162\141\x6c\x64\106\x69\145\x6c\x64\116\141\x6d\145"); } public function getFieldGroupKey($field_key) { $field = $this->getFieldImplementation($field_key); if (!$field) { return null; } return $field->getFieldGroupKey(); } public function isFieldAvailable($field_key) { $field = $this->getFieldImplementation($field_key); if (!$field) { return null; } return $field->isFieldAvailable(); } public function getConditionNameMap() { return array(self::CONDITION_CONTAINS => pht("\143\x6f\x6e\164\x61\x69\156\163"), self::CONDITION_NOT_CONTAINS => pht("\x64\x6f\145\163\40\x6e\x6f\x74\x20\143\157\x6e\x74\x61\x69\x6e"), self::CONDITION_IS => pht("\151\163"), self::CONDITION_IS_NOT => pht("\151\x73\x20\156\157\164"), self::CONDITION_IS_ANY => pht("\x69\x73\x20\x61\x6e\x79\x20\x6f\x66"), self::CONDITION_IS_TRUE => pht("\151\163\40\x74\x72\165\145"), self::CONDITION_IS_FALSE => pht("\151\x73\40\146\x61\154\163\145"), self::CONDITION_IS_NOT_ANY => pht("\x69\x73\x20\156\157\164\x20\141\x6e\171\x20\x6f\x66"), self::CONDITION_INCLUDE_ALL => pht("\x69\156\x63\154\165\x64\x65\x20\141\154\154\x20\x6f\146"), self::CONDITION_INCLUDE_ANY => pht("\x69\156\x63\154\165\x64\145\x20\x61\x6e\x79\x20\x6f\146"), self::CONDITION_INCLUDE_NONE => pht("\151\x6e\x63\x6c\x75\x64\145\40\156\x6f\x6e\x65\40\x6f\x66"), self::CONDITION_IS_ME => pht("\x69\x73\40\x6d\x79\x73\x65\154\146"), self::CONDITION_IS_NOT_ME => pht("\151\x73\x20\x6e\157\164\40\155\x79\163\145\x6c\x66"), self::CONDITION_REGEXP => pht("\x6d\141\x74\x63\x68\x65\x73\x20\162\145\x67\145\170\x70"), self::CONDITION_NOT_REGEXP => pht("\x64\x6f\145\163\x20\x6e\x6f\x74\x20\155\141\164\x63\x68\x20\162\145\x67\145\170\160"), self::CONDITION_RULE => pht("\x6d\141\164\x63\150\145\x73\x3a"), self::CONDITION_NOT_RULE => pht("\x64\x6f\x65\x73\40\x6e\157\x74\40\x6d\141\164\143\x68\x3a"), self::CONDITION_EXISTS => pht("\x65\x78\151\163\x74\163"), self::CONDITION_NOT_EXISTS => pht("\x64\x6f\x65\x73\40\156\x6f\x74\40\145\170\151\163\x74"), self::CONDITION_UNCONDITIONALLY => '', self::CONDITION_NEVER => '', self::CONDITION_REGEXP_PAIR => pht("\x6d\x61\x74\x63\x68\145\x73\40\x72\145\x67\145\x78\160\40\x70\x61\151\162"), self::CONDITION_HAS_BIT => pht("\150\141\x73\x20\x62\x69\164"), self::CONDITION_NOT_BIT => pht("\154\141\143\153\x73\x20\x62\151\164")); } public function getConditionsForField($field) { return $this->requireFieldImplementation($field)->getHeraldFieldConditions(); } private function requireFieldImplementation($field_key) { $field = $this->getFieldImplementation($field_key); if (!$field) { throw new Exception(pht("\x4e\x6f\40\146\x69\145\x6c\x64\40\x77\x69\164\150\x20\x6b\x65\171\x20\x22\x25\163\x22\40\x69\x73\40\x61\166\141\x69\x6c\x61\142\x6c\145\40\164\x6f\x20\x48\x65\162\x61\154\x64\40\141\x64\x61\x70\164\145\x72\40\42\45\x73\42\56", $field_key, get_class($this))); } return $field; } public function doesConditionMatch(HeraldEngine $engine, HeraldRule $rule, HeraldCondition $condition, $field_value) { $condition_type = $condition->getFieldCondition(); $condition_value = $condition->getValue(); switch ($condition_type) { case self::CONDITION_CONTAINS: case self::CONDITION_NOT_CONTAINS: $result_if_match = $condition_type == self::CONDITION_CONTAINS; foreach ((array) $field_value as $value) { if (stripos($value, $condition_value) !== false) { return $result_if_match; } } return !$result_if_match; case self::CONDITION_IS: return $field_value == $condition_value; case self::CONDITION_IS_NOT: return $field_value != $condition_value; case self::CONDITION_IS_ME: return $field_value == $rule->getAuthorPHID(); case self::CONDITION_IS_NOT_ME: return $field_value != $rule->getAuthorPHID(); case self::CONDITION_IS_ANY: if (!is_array($condition_value)) { throw new HeraldInvalidConditionException(pht("\x45\x78\x70\x65\143\164\x65\x64\40\x63\157\156\x64\x69\x74\151\157\156\40\x76\141\x6c\x75\x65\x20\164\x6f\x20\x62\x65\40\x61\x6e\40\141\162\x72\x61\171\x2e")); } $condition_value = array_fuse($condition_value); return isset($condition_value[$field_value]); case self::CONDITION_IS_NOT_ANY: if (!is_array($condition_value)) { throw new HeraldInvalidConditionException(pht("\x45\x78\x70\x65\x63\x74\145\144\40\x63\157\x6e\x64\x69\x74\x69\x6f\156\40\x76\x61\154\165\145\40\x74\x6f\40\142\145\40\x61\156\40\141\x72\x72\x61\171\x2e")); } $condition_value = array_fuse($condition_value); return !isset($condition_value[$field_value]); case self::CONDITION_INCLUDE_ALL: if (!is_array($field_value)) { throw new HeraldInvalidConditionException(pht("\x4f\x62\152\x65\x63\164\x20\x70\162\157\x64\x75\143\145\x64\x20\x6e\157\x6e\x2d\141\x72\x72\141\171\x20\166\141\154\x75\x65\41")); } if (!is_array($condition_value)) { throw new HeraldInvalidConditionException(pht("\105\170\160\145\143\x74\x65\144\x20\x63\157\x6e\144\151\164\x69\x6f\x6e\x20\x76\141\x6c\x75\145\40\x74\157\40\x62\145\40\141\x6e\40\141\x72\162\141\171\56")); } $have = array_select_keys(array_fuse($field_value), $condition_value); return count($have) == count($condition_value); case self::CONDITION_INCLUDE_ANY: return (bool) array_select_keys(array_fuse($field_value), $condition_value); case self::CONDITION_INCLUDE_NONE: return !array_select_keys(array_fuse($field_value), $condition_value); case self::CONDITION_EXISTS: case self::CONDITION_IS_TRUE: return (bool) $field_value; case self::CONDITION_NOT_EXISTS: case self::CONDITION_IS_FALSE: return !$field_value; case self::CONDITION_UNCONDITIONALLY: return (bool) $field_value; case self::CONDITION_NEVER: return false; case self::CONDITION_REGEXP: case self::CONDITION_NOT_REGEXP: $result_if_match = $condition_type == self::CONDITION_REGEXP; $condition_pattern = $condition_value . "\123"; foreach ((array) $field_value as $value) { try { $result = phutil_preg_match($condition_pattern, $value); } catch (PhutilRegexException $ex) { $message = array(); $message[] = pht("\x52\x65\147\x75\154\x61\162\40\145\x78\x70\x72\145\x73\163\151\x6f\x6e\40\42\x25\x73\42\x20\x69\156\x20\110\145\162\x61\154\144\x20\162\165\x6c\145\40\x22\x25\x73\42\x20\151\163\x20\156\x6f\x74\40\166\141\x6c\151\x64\54\40" . "\157\162\x20\145\x78\x63\x65\145\x64\x65\x64\x20\142\x61\x63\x6b\164\x72\141\x63\153\x69\156\147\40\x6f\162\x20\x72\145\143\x75\162\163\151\157\156\40\x6c\x69\155\x69\x74\x73\40\167\150\151\x6c\145\x20" . "\x65\170\x65\x63\x75\x74\x69\156\147\x2e\x20\x56\x65\162\x69\146\x79\40\x74\x68\x65\x20\x65\170\160\x72\145\163\163\x69\x6f\x6e\x20\141\x6e\144\x20\x63\x6f\162\162\x65\143\164\x20\x69\x74\40\157\162\40\162\x65\167\x72\x69\164\x65\40" . "\x69\x74\x20\167\151\x74\x68\40\x6c\x65\x73\163\40\x62\x61\x63\x6b\x74\162\x61\x63\x6b\151\x6e\147\x2e", $condition_value, $rule->getMonogram()); $message[] = $ex->getMessage(); $message = implode("\12\12", $message); throw new HeraldInvalidConditionException($message); } if ($result) { return $result_if_match; } } return !$result_if_match; case self::CONDITION_REGEXP_PAIR: $regexp_pair = null; try { $regexp_pair = phutil_json_decode($condition_value); } catch (PhutilJSONParserException $ex) { throw new HeraldInvalidConditionException(pht("\122\x65\147\x75\x6c\141\x72\40\x65\170\x70\x72\145\x73\163\151\x6f\x6e\40\160\141\x69\162\40\151\163\40\x6e\x6f\164\40\x76\x61\154\151\x64\40\x4a\x53\117\116\41")); } if (count($regexp_pair) != 2) { throw new HeraldInvalidConditionException(pht("\x52\x65\147\165\x6c\141\162\x20\145\170\160\162\x65\x73\x73\151\x6f\156\x20\160\141\x69\x72\x20\151\x73\x20\x6e\157\x74\x20\141\x20\160\141\x69\x72\x21")); } $key_regexp = array_shift($regexp_pair); $value_regexp = array_shift($regexp_pair); foreach ((array) $field_value as $key => $value) { $key_matches = @preg_match($key_regexp, $key); if ($key_matches === false) { throw new HeraldInvalidConditionException(pht("\106\151\162\163\164\40\162\145\x67\165\x6c\141\x72\40\145\x78\160\162\145\x73\163\x69\x6f\x6e\x20\x69\163\40\151\x6e\166\x61\154\x69\144\x21")); } if ($key_matches) { $value_matches = @preg_match($value_regexp, $value); if ($value_matches === false) { throw new HeraldInvalidConditionException(pht("\x53\x65\x63\157\156\144\x20\x72\145\x67\165\x6c\141\162\40\x65\170\160\x72\145\163\x73\151\x6f\156\x20\x69\x73\x20\x69\156\x76\x61\154\151\x64\x21")); } if ($value_matches) { return true; } } } return false; case self::CONDITION_RULE: case self::CONDITION_NOT_RULE: $rule = $engine->getRule($condition_value); if (!$rule) { throw new HeraldInvalidConditionException(pht("\x43\x6f\x6e\144\x69\164\151\x6f\156\x20\x72\145\x66\x65\162\x65\x6e\143\x65\163\x20\141\x20\162\165\154\x65\x20\x77\150\x69\x63\150\40\144\x6f\145\163\40\x6e\x6f\x74\40\x65\x78\x69\x73\x74\x21")); } $is_not = $condition_type == self::CONDITION_NOT_RULE; $result = $engine->doesRuleMatch($rule, $this); if ($is_not) { $result = !$result; } return $result; case self::CONDITION_HAS_BIT: return ($condition_value & $field_value) === (int) $condition_value; case self::CONDITION_NOT_BIT: return ($condition_value & $field_value) !== (int) $condition_value; default: throw new HeraldInvalidConditionException(pht("\x55\156\153\x6e\157\167\x6e\40\x63\x6f\x6e\144\x69\164\151\157\156\40\47\x25\163\47\x2e", $condition_type)); } } public function willSaveCondition(HeraldCondition $condition) { $condition_type = $condition->getFieldCondition(); $condition_value = $condition->getValue(); switch ($condition_type) { case self::CONDITION_REGEXP: case self::CONDITION_NOT_REGEXP: $ok = @preg_match($condition_value, ''); if ($ok === false) { throw new HeraldInvalidConditionException(pht("\124\150\145\x20\162\x65\147\x75\x6c\141\162\40\145\170\160\x72\x65\x73\163\151\x6f\156\40\42\45\163\x22\40\151\x73\x20\156\157\164\x20\x76\x61\154\151\144\x2e\x20\x52\x65\147\x75\x6c\x61\162\x20\145\170\x70\x72\x65\163\x73\x69\x6f\x6e\x73\40" . "\155\165\163\164\40\x68\x61\166\x65\x20\x65\x6e\143\154\157\x73\x69\156\x67\40\143\x68\141\x72\141\x63\x74\145\162\163\x20\50\145\x2e\x67\x2e\x20\42\100\x2f\160\x61\164\x68\57\164\157\x2f\146\x69\154\145\100\x22\x2c\40\x6e\x6f\164\40" . "\42\57\x70\x61\x74\x68\57\x74\157\57\146\151\x6c\145\42\x29\40\x61\x6e\144\40\x62\145\40\x73\171\156\x74\x61\143\164\x69\x63\141\x6c\154\x79\40\x63\x6f\162\x72\145\143\x74\x2e", $condition_value)); } break; case self::CONDITION_REGEXP_PAIR: $json = null; try { $json = phutil_json_decode($condition_value); } catch (PhutilJSONParserException $ex) { throw new HeraldInvalidConditionException(pht("\124\150\145\40\162\145\x67\165\154\x61\x72\40\x65\170\160\162\x65\x73\x73\x69\157\156\40\160\x61\x69\162\x20\x22\x25\163\x22\x20\x69\163\40\x6e\x6f\164\x20\x76\x61\x6c\x69\x64\x20\112\x53\117\x4e\x2e\40\x45\156\x74\x65\x72\40\141\40" . "\166\x61\154\x69\x64\40\112\x53\117\116\40\x61\x72\162\141\x79\40\x77\151\164\x68\x20\164\167\157\x20\145\154\145\x6d\145\x6e\x74\163\56", $condition_value)); } if (count($json) != 2) { throw new HeraldInvalidConditionException(pht("\124\150\x65\x20\x72\145\x67\165\x6c\141\x72\x20\145\x78\160\162\145\163\x73\x69\x6f\156\x20\160\x61\x69\x72\x20\42\x25\x73\x22\40\155\x75\163\164\x20\150\141\166\x65\x20\145\170\x61\143\164\x6c\x79\40\164\x77\x6f\40" . "\x65\154\145\155\145\156\164\163\x2e", $condition_value)); } $key_regexp = array_shift($json); $val_regexp = array_shift($json); $key_ok = @preg_match($key_regexp, ''); if ($key_ok === false) { throw new HeraldInvalidConditionException(pht("\x54\x68\145\40\x66\151\162\163\164\x20\162\145\x67\145\x78\x70\x20\x69\156\40\164\150\x65\40\162\x65\x67\x65\x78\160\40\x70\141\x69\162\54\x20\x22\x25\163\42\x2c\40\x69\163\40\156\x6f\x74\40\141\x20\166\141\x6c\x69\x64\x20" . "\162\145\147\145\x78\x70\x2e", $key_regexp)); } $val_ok = @preg_match($val_regexp, ''); if ($val_ok === false) { throw new HeraldInvalidConditionException(pht("\124\150\145\40\x73\145\143\157\x6e\x64\x20\x72\145\147\x65\x78\160\40\151\156\40\x74\x68\x65\x20\x72\x65\x67\145\x78\160\40\x70\141\x69\x72\x2c\x20\42\45\x73\x22\x2c\x20\x69\x73\40\156\x6f\164\x20\x61\40\x76\141\x6c\x69\x64\40" . "\162\145\x67\x65\170\160\x2e", $val_regexp)); } break; case self::CONDITION_CONTAINS: case self::CONDITION_NOT_CONTAINS: case self::CONDITION_IS: case self::CONDITION_IS_NOT: case self::CONDITION_IS_ANY: case self::CONDITION_IS_NOT_ANY: case self::CONDITION_INCLUDE_ALL: case self::CONDITION_INCLUDE_ANY: case self::CONDITION_INCLUDE_NONE: case self::CONDITION_IS_ME: case self::CONDITION_IS_NOT_ME: case self::CONDITION_RULE: case self::CONDITION_NOT_RULE: case self::CONDITION_EXISTS: case self::CONDITION_NOT_EXISTS: case self::CONDITION_UNCONDITIONALLY: case self::CONDITION_NEVER: case self::CONDITION_HAS_BIT: case self::CONDITION_NOT_BIT: case self::CONDITION_IS_TRUE: case self::CONDITION_IS_FALSE: break; default: throw new HeraldInvalidConditionException(pht("\x55\156\153\156\x6f\167\156\x20\143\x6f\x6e\144\151\x74\151\157\x6e\40\x22\x25\x73\42\41", $condition_type)); } } private function getActionImplementationMap() { if ($this->actionMap === null) { $object = $this->getObject(); $map = array(); $all = HeraldAction::getAllActions(); foreach ($all as $key => $action) { $action = id(clone $action)->setAdapter($this); if (!$action->supportsObject($object)) { continue; } $subactions = $action->getActionsForObject($object); foreach ($subactions as $subkey => $subaction) { if (isset($map[$subkey])) { throw new Exception(pht("\x54\x77\157\40\x48\x65\x72\141\x6c\144\x41\143\x74\151\x6f\x6e\x73\40\x28\157\146\x20\143\x6c\x61\x73\x73\x65\163\40\42\45\x73\42\x20\x61\x6e\144\x20\42\45\x73\42\51\40\150\x61\x76\x65\40\x74\x68\x65\x20\x73\x61\x6d\145\40" . "\x61\x63\x74\151\157\x6e\40\153\145\171\40\50\42\45\163\42\51\40\x61\146\x74\145\162\x20\145\170\160\141\156\x73\x69\x6f\156\x20\x66\157\162\x20\141\x6e\40\157\x62\152\145\x63\x74\x20\x6f\146\x20\143\x6c\x61\163\163\x20" . "\42\45\163\42\40\151\156\x73\x69\144\x65\40\x61\x64\x61\x70\164\145\162\40\42\x25\x73\x22\x2e\x20\x45\x61\x63\150\40\141\143\x74\151\157\156\x20\155\165\163\164\x20\x68\141\x76\x65\x20\141\40\165\156\x69\x71\x75\145\40" . "\x61\143\x74\x69\x6f\156\x20\153\145\x79\x2e", get_class($subaction), get_class($map[$subkey]), $subkey, get_class($object), get_class($this))); } $subaction = id(clone $subaction)->setAdapter($this); $map[$subkey] = $subaction; } } $this->actionMap = $map; } return $this->actionMap; } private function requireActionImplementation($action_key) { $action = $this->getActionImplementation($action_key); if (!$action) { throw new Exception(pht("\x4e\157\x20\x61\x63\164\151\x6f\156\x20\x77\151\x74\150\x20\x6b\x65\x79\40\42\45\x73\x22\40\x69\x73\x20\141\x76\x61\151\x6c\141\142\x6c\x65\40\x74\x6f\40\x48\145\162\x61\154\144\x20\141\x64\141\160\164\145\x72\x20\42\45\x73\x22\x2e", $action_key, get_class($this))); } return $action; } private function getActionsForRuleType($rule_type) { $actions = $this->getActionImplementationMap(); foreach ($actions as $key => $action) { if (!$action->supportsRuleType($rule_type)) { unset($actions[$key]); } } return $actions; } public function getActionImplementation($key) { return idx($this->getActionImplementationMap(), $key); } public function getActionKeys() { return array_keys($this->getActionImplementationMap()); } public function getActionGroupKey($action_key) { $action = $this->getActionImplementation($action_key); if (!$action) { return null; } return $action->getActionGroupKey(); } public function isActionAvailable($action_key) { $action = $this->getActionImplementation($action_key); if (!$action) { return null; } return $action->isActionAvailable(); } public function getActions($rule_type) { $actions = array(); foreach ($this->getActionsForRuleType($rule_type) as $key => $action) { $actions[] = $key; } return $actions; } public function getActionNameMap($rule_type) { $map = array(); foreach ($this->getActionsForRuleType($rule_type) as $key => $action) { $map[$key] = $action->getHeraldActionName(); } return $map; } public function willSaveAction(HeraldRule $rule, HeraldActionRecord $action) { $impl = $this->requireActionImplementation($action->getAction()); $target = $action->getTarget(); $target = $impl->willSaveActionValue($target); $action->setTarget($target); } public function getValueTypeForFieldAndCondition($field, $condition) { return $this->requireFieldImplementation($field)->getHeraldFieldValueType($condition); } public function getValueTypeForAction($action, $rule_type) { $impl = $this->requireActionImplementation($action); return $impl->getHeraldActionValueType(); } private function buildTokenizerFieldValue(PhabricatorTypeaheadDatasource $datasource) { $key = "\141\x63\x74\151\x6f\x6e\x2e" . get_class($datasource); return id(new HeraldTokenizerFieldValue())->setKey($key)->setDatasource($datasource); } public function getRepetitionOptions() { $options = array(); $options[] = HeraldRule::REPEAT_EVERY; if (!$this->isSingleEventAdapter()) { $options[] = HeraldRule::REPEAT_FIRST; $options[] = HeraldRule::REPEAT_CHANGE; } return $options; } protected function initializeNewAdapter() { $this->setObject($this->newObject()); return $this; } public function isSingleEventAdapter() { return false; } public static function getAllAdapters() { return id(new PhutilClassMapQuery())->setAncestorClass(__CLASS__)->setUniqueMethod("\147\145\x74\x41\x64\141\x70\x74\145\162\x43\x6f\156\164\145\156\164\124\x79\160\x65")->setSortMethod("\147\x65\164\101\x64\141\x70\164\x65\162\123\x6f\x72\x74\113\x65\x79")->execute(); } public static function getAdapterForContentType($content_type) { $adapters = self::getAllAdapters(); foreach ($adapters as $adapter) { if ($adapter->getAdapterContentType() == $content_type) { $adapter = id(clone $adapter); $adapter->initializeNewAdapter(); return $adapter; } } throw new Exception(pht("\116\x6f\x20\x61\144\141\x70\164\145\162\40\145\170\151\x73\x74\163\40\x66\x6f\162\x20\x48\145\x72\141\154\x64\40\143\x6f\156\164\145\x6e\x74\x20\x74\x79\160\145\x20\x22\45\x73\42\56", $content_type)); } public static function getEnabledAdapterMap(PhabricatorUser $viewer) { $map = array(); $adapters = self::getAllAdapters(); foreach ($adapters as $adapter) { if (!$adapter->isAvailableToUser($viewer)) { continue; } $type = $adapter->getAdapterContentType(); $name = $adapter->getAdapterContentName(); $map[$type] = $name; } return $map; } public function getEditorValueForCondition(PhabricatorUser $viewer, HeraldCondition $condition) { $field = $this->requireFieldImplementation($condition->getFieldName()); return $field->getEditorValue($viewer, $condition->getFieldCondition(), $condition->getValue()); } public function getEditorValueForAction(PhabricatorUser $viewer, HeraldActionRecord $action_record) { $action = $this->requireActionImplementation($action_record->getAction()); return $action->getEditorValue($viewer, $action_record->getTarget()); } public function renderRuleAsText(HeraldRule $rule, PhabricatorUser $viewer) { require_celerity_resource("\150\145\162\x61\154\144\x2d\x63\x73\163"); $icon = id(new PHUIIconView())->setIcon("\x66\x61\x2d\143\150\x65\x76\162\157\156\x2d\143\x69\x72\143\154\x65\55\162\x69\x67\x68\x74\x20\x6c\x69\x67\x68\164\x67\x72\145\171\164\x65\x78\x74")->addClass("\150\x65\162\141\x6c\144\x2d\154\x69\163\x74\55\x69\143\157\x6e"); if ($rule->getMustMatchAll()) { $match_text = pht("\127\x68\145\156\40\x61\154\x6c\x20\x6f\x66\40\164\x68\145\163\145\x20\x63\x6f\156\144\x69\x74\151\157\156\163\x20\141\162\145\40\155\145\x74\72"); } else { $match_text = pht("\127\150\145\156\40\141\x6e\171\40\157\146\40\x74\150\x65\x73\x65\x20\x63\x6f\x6e\x64\151\x74\x69\x6f\156\x73\40\x61\x72\x65\x20\x6d\x65\x74\x3a"); } $match_title = phutil_tag("\160", array("\x63\154\141\163\x73" => "\x68\x65\x72\141\154\144\55\154\151\163\x74\55\x64\145\x73\143\x72\151\160\164\x69\x6f\156"), $match_text); $match_list = array(); foreach ($rule->getConditions() as $condition) { $match_list[] = phutil_tag("\x64\x69\x76", array("\x63\154\x61\163\x73" => "\150\x65\162\x61\154\144\55\x6c\x69\163\x74\x2d\x69\x74\145\x6d"), array($icon, $this->renderConditionAsText($condition, $viewer))); } if ($rule->isRepeatFirst()) { $action_text = pht("\124\x61\153\x65\x20\164\150\145\x73\x65\x20\141\143\x74\x69\157\x6e\x73\x20\164\x68\145\40\x66\x69\x72\163\164\x20\164\151\x6d\x65\40\164\150\x69\163\40\x72\165\x6c\x65\x20\155\x61\x74\143\x68\145\x73\72"); } else { if ($rule->isRepeatOnChange()) { $action_text = pht("\x54\x61\153\x65\40\x74\150\145\163\x65\40\141\143\x74\151\157\x6e\x73\x20\x69\146\x20\164\150\x69\163\40\162\165\154\145\40\x64\x69\144\x20\x6e\157\164\40\x6d\141\x74\x63\150\40\x74\150\145\40\x6c\141\163\164\40\164\x69\155\145\x3a"); } else { $action_text = pht("\x54\141\153\x65\40\x74\x68\x65\x73\x65\40\x61\x63\x74\x69\157\x6e\x73\x20\145\166\x65\162\x79\40\x74\x69\x6d\x65\x20\164\150\151\163\40\162\165\x6c\145\x20\x6d\141\164\143\150\145\x73\x3a"); } } $action_title = phutil_tag("\x70", array("\143\154\x61\163\x73" => "\x68\145\162\x61\154\144\55\x6c\151\x73\x74\55\144\x65\163\x63\162\x69\160\164\x69\157\156"), $action_text); $action_list = array(); foreach ($rule->getActions() as $action) { $action_list[] = phutil_tag("\144\151\x76", array("\143\x6c\x61\x73\163" => "\x68\145\162\141\154\144\55\x6c\x69\x73\x74\x2d\151\x74\145\155"), array($icon, $this->renderActionAsText($viewer, $action))); } return array($match_title, $match_list, $action_title, $action_list); } private function renderConditionAsText(HeraldCondition $condition, PhabricatorUser $viewer) { $field_type = $condition->getFieldName(); $field = $this->getFieldImplementation($field_type); if (!$field) { return pht("\x55\x6e\153\156\157\x77\x6e\40\106\151\x65\x6c\x64\x3a\40\x22\45\163\42", $field_type); } $field_name = $field->getHeraldFieldName(); $condition_type = $condition->getFieldCondition(); $condition_name = idx($this->getConditionNameMap(), $condition_type); $value = $this->renderConditionValueAsText($condition, $viewer); return array($field_name, "\x20", $condition_name, "\40", $value); } private function renderActionAsText(PhabricatorUser $viewer, HeraldActionRecord $action_record) { $action_type = $action_record->getAction(); $action_value = $action_record->getTarget(); $action = $this->getActionImplementation($action_type); if (!$action) { return pht("\x55\x6e\x6b\156\x6f\x77\x6e\40\101\143\x74\151\x6f\x6e\40\50\x22\x25\163\42\x29", $action_type); } $action->setViewer($viewer); return $action->renderActionDescription($action_value); } private function renderConditionValueAsText(HeraldCondition $condition, PhabricatorUser $viewer) { $field = $this->requireFieldImplementation($condition->getFieldName()); return $field->renderConditionValue($viewer, $condition->getFieldCondition(), $condition->getValue()); } public function renderFieldTranscriptValue(PhabricatorUser $viewer, $field_type, $field_value) { $field = $this->getFieldImplementation($field_type); if ($field) { return $field->renderTranscriptValue($viewer, $field_value); } return phutil_tag("\x65\155", array(), pht("\125\156\141\142\154\145\40\x74\157\x20\x72\145\x6e\x64\145\162\x20\x76\x61\154\165\145\x20\146\x6f\x72\x20\x75\156\x6b\156\x6f\167\x6e\40\x66\151\x65\x6c\144\x20\164\x79\160\x65\x20\x28\42\x25\x73\x22\51\56", $field_type)); } protected function applyStandardEffect(HeraldEffect $effect) { $action = $effect->getAction(); $rule_type = $effect->getRule()->getRuleType(); $impl = $this->getActionImplementation($action); if (!$impl) { return new HeraldApplyTranscript($effect, false, array(array(HeraldAction::DO_STANDARD_INVALID_ACTION, $action))); } if (!$impl->supportsRuleType($rule_type)) { return new HeraldApplyTranscript($effect, false, array(array(HeraldAction::DO_STANDARD_WRONG_RULE_TYPE, $rule_type))); } $impl->applyEffect($this->getObject(), $effect); return $impl->getApplyTranscript($effect); } public function loadEdgePHIDs($type) { if (!isset($this->edgeCache[$type])) { $phids = PhabricatorEdgeQuery::loadDestinationPHIDs($this->getObject()->getPHID(), $type); $this->edgeCache[$type] = array_fuse($phids); } return $this->edgeCache[$type]; } public final function getForbiddenActions() { return array_keys($this->forbiddenActions); } public final function setForbiddenAction($action, $reason) { $this->forbiddenActions[$action] = $reason; return $this; } public final function getRequiredFieldStates($field_key) { return $this->requireFieldImplementation($field_key)->getRequiredAdapterStates(); } public final function getRequiredActionStates($action_key) { return $this->requireActionImplementation($action_key)->getRequiredAdapterStates(); } public final function getForbiddenReason($action) { if (!isset($this->forbiddenActions[$action])) { throw new Exception(pht("\x41\143\164\151\x6f\x6e\x20\x22\x25\163\x22\x20\151\163\40\156\x6f\164\40\x66\157\x72\142\x69\144\x64\145\156\x21", $action)); } return $this->forbiddenActions[$action]; } public final function addMustEncryptReason($reason) { $this->mustEncryptReasons[] = $reason; return $this; } public final function getMustEncryptReasons() { return $this->mustEncryptReasons; } public function supportsWebhooks() { return true; } public final function queueWebhook($webhook_phid, $rule_phid) { $this->webhookMap[$webhook_phid][] = $rule_phid; return $this; } public final function getWebhookMap() { return $this->webhookMap; } }

Function Calls

None

Variables

None

Stats

MD5 986f8537a9426e8d345016a11d094324
Eval Count 0
Decode Time 124 ms