3 final class PhabricatorGuidanceEngine
7 private $guidanceContext;
9 public function setGuidanceContext(
10 PhabricatorGuidanceContext
$guidance_context) {
11 $this->guidanceContext
= $guidance_context;
15 public function getGuidanceContext() {
16 return $this->guidanceContext
;
19 public function setViewer(PhabricatorUser
$viewer) {
20 $this->viewer
= $viewer;
24 public function getViewer() {
28 public function newInfoView() {
29 $extensions = PhabricatorGuidanceEngineExtension
::getAllExtensions();
30 $context = $this->getGuidanceContext();
33 foreach ($extensions as $key => $extension) {
34 if (!$extension->canGenerateGuidance($context)) {
37 $keep[$key] = id(clone $extension);
40 $guidance_map = array();
41 foreach ($keep as $extension) {
42 $guidance_list = $extension->generateGuidance($context);
43 foreach ($guidance_list as $guidance) {
44 $key = $guidance->getKey();
46 if (isset($guidance_map[$key])) {
49 'Two guidance extensions generated guidance with the same '.
50 'key ("%s"). Each piece of guidance must have a unique key.',
54 $guidance_map[$key] = $guidance;
58 foreach ($keep as $extension) {
59 $guidance_map = $extension->didGenerateGuidance($context, $guidance_map);
66 $guidance_map = msortv($guidance_map, 'getSortVector');
68 $severity = PhabricatorGuidanceMessage
::SEVERITY_NOTICE
;
70 foreach ($guidance_map as $guidance) {
71 if ($strength !== null) {
72 if ($guidance->getSeverityStrength() <= $strength) {
77 $strength = $guidance->getSeverityStrength();
78 $severity = $guidance->getSeverity();
81 $severity_map = array(
82 PhabricatorGuidanceMessage
::SEVERITY_NOTICE
83 => PHUIInfoView
::SEVERITY_NOTICE
,
84 PhabricatorGuidanceMessage
::SEVERITY_WARNING
85 => PHUIInfoView
::SEVERITY_WARNING
,
88 $messages = mpull($guidance_map, 'getMessage', 'getKey');
90 return id(new PHUIInfoView())
91 ->setViewer($this->getViewer())
92 ->setSeverity(idx($severity_map, $severity, $severity))
93 ->setErrors($messages);