@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<?php
2
3abstract class PhabricatorFactEngine extends Phobject {
4
5 private $factMap;
6 private $viewer;
7
8 final public static function loadAllEngines() {
9 return id(new PhutilClassMapQuery())
10 ->setAncestorClass(self::class)
11 ->execute();
12 }
13
14 /**
15 * @return array All types of facts known by this FactEngine
16 */
17 abstract public function newFacts();
18
19 /**
20 * @return bool
21 */
22 abstract public function supportsDatapointsForObject(
23 PhabricatorLiskDAO $object);
24
25 /**
26 * Add new datapoints (due to a transaction) about an object
27 */
28 abstract public function newDatapointsForObject(PhabricatorLiskDAO $object);
29
30 final protected function getFact($key) {
31 if ($this->factMap === null) {
32 $facts = $this->newFacts();
33 $facts = mpull($facts, null, 'getKey');
34 $this->factMap = $facts;
35 }
36
37 if (!isset($this->factMap[$key])) {
38 throw new Exception(
39 pht(
40 'Unknown fact ("%s") for engine "%s".',
41 $key,
42 get_class($this)));
43 }
44
45 return $this->factMap[$key];
46 }
47
48 public function setViewer(PhabricatorUser $viewer) {
49 $this->viewer = $viewer;
50 return $this;
51 }
52
53 public function getViewer() {
54 if (!$this->viewer) {
55 throw new PhutilInvalidStateException('setViewer');
56 }
57
58 return $this->viewer;
59 }
60
61}