Merge pull request #16674 from alexymik/patch-2
[civicrm-core.git] / setup / src / Setup / Event / CheckRequirementsEvent.php
CommitLineData
4bcd4c62
TO
1<?php
2namespace Civi\Setup\Event;
3
4/**
5 * Check if the local system meets the installation requirements.
6 *
7 * Event Name: 'civi.setup.checkRequirements'
8 */
9class CheckRequirementsEvent extends BaseSetupEvent {
10
11 protected $messages;
12
13 /**
14 * @param string $severity
15 * Severity/level.
16 * Ex: 'info', 'warning', 'error'.
17 * @param string $section
18 * Symbolic machine name for this group of messages.
19 * Ex: 'database' or 'system'.
20 * @param string $name
21 * Symbolic machine name for this particular message.
22 * Ex: 'mysqlThreadstack'
23 * @param string $message
24 * Displayable explanation.
25 * Ex: 'The MySQL thread stack is too small.'
26 * @return $this
27 */
28 public function addMessage($severity, $section, $name, $message) {
29 $this->messages[$name] = array(
30 'section' => $section,
31 'name' => $name,
32 'message' => $message,
33 'severity' => $severity,
34 );
35 return $this;
36 }
37
38 public function addInfo($section, $name, $message = '') {
39 return $this->addMessage('info', $section, $name, $message);
40 }
41
42 public function addError($section, $name, $message = '') {
43 return $this->addMessage('error', $section, $name, $message);
44 }
45
46 public function addWarning($section, $name, $message = '') {
47 return $this->addMessage('warning', $section, $name, $message);
48 }
49
50 /**
51 * @param string|NULL $severity
52 * Filter by severity of the message.
53 * Ex: 'info', 'error', 'warning'.
54 * @return array
55 * List of messages. Each has fields:
56 * - name: string, symbolic name.
57 * - message: string, displayable message.
58 * - severity: string, ex: 'info', 'warning', 'error'.
59 */
60 public function getMessages($severity = NULL) {
61 if ($severity === NULL) {
62 return $this->messages;
63 }
64 else {
65 return array_filter($this->messages, function ($m) use ($severity) {
66 return $m['severity'] == $severity;
67 });
68 }
69 }
70
71 public function getInfos() {
72 return $this->getMessages('info');
73 }
74
75 public function getErrors() {
76 return $this->getMessages('error');
77 }
78
79 public function getWarnings() {
80 return $this->getMessages('warning');
81 }
82
83}