-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathReportServiceData.php
More file actions
141 lines (118 loc) · 3.01 KB
/
ReportServiceData.php
File metadata and controls
141 lines (118 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @file
* Contains DrupalCodeBuilder\Task\ReportServiceData.
*/
namespace DrupalCodeBuilder\Task;
use MutableTypedData\Definition\OptionSetDefininitionInterface;
use DrupalCodeBuilder\Task\Report\SectionReportInterface;
/**
* Task handler for reporting on service data.
*/
class ReportServiceData extends ReportHookDataFolder implements OptionSetDefininitionInterface, SectionReportInterface {
use OptionsProviderTrait;
use SectionReportSimpleCountTrait;
/**
* The sanity level this task requires to operate.
*/
protected $sanity_level = 'component_data_processed';
/**
* The service type data.
*
* @var array
*/
protected $serviceTypesData;
/**
* The services data.
*
* @var array
*/
protected $serviceData;
/**
* The name of the method providing an array of options as $value => $label.
*/
protected static $optionsMethod = 'listServiceNamesOptionsAll';
/**
* {@inheritdoc}
*/
public function getInfo(): array {
return [
'key' => 'services',
'label' => 'Services',
'weight' => 10,
];
}
/**
* {@inheritdoc}
*/
public function getDataSummary(): array {
return $this->listServiceNamesOptionsAll();
}
/**
* Get the list of Service data.
*
* @return
* The processed Service data.
*/
function listServiceData() {
$service_data = $this->loadServiceData();
return $service_data['all'];
}
/**
* Get a list of options of the major services.
*
* @return
* An array of Service types as options suitable for FormAPI.
*/
function listServiceNamesOptions() {
$service_data = $this->loadServiceData();
$return = [];
foreach ($service_data['primary'] as $service_id => $service_info) {
$return[$service_id] = $service_info['label'];
}
return $return;
}
/**
* Get a list of options of all the services.
*
* @return
* An array of Service types as options suitable for FormAPI.
*/
public function listServiceNamesOptionsAll() {
$service_data = $this->loadServiceData();
$return = [];
foreach ($service_data['all'] as $service_id => $service_info) {
$return[$service_id] = $service_info['label'];
}
return $return;
}
/**
* Get the list of Service types data.
*
* @return
* The processed Service types data.
*/
public function listServiceTypeData() {
if (!isset($this->serviceTypesData)) {
$this->serviceTypesData = $this->environment->getStorage()->retrieve('service_tag_types');
}
return $this->serviceTypesData;
}
/**
* Loads the service data from storage.
*
* @return
* The data array, as stored by the ServicesCollector.
*/
protected function loadServiceData() {
if (!isset($this->serviceData)) {
$this->serviceData = $this->environment->getStorage()->retrieve('services');
}
// Populate the keys, in case analysis crashed.
$this->serviceData += [
'primary' => [],
'all' => [],
];
return $this->serviceData;
}
}