forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServicesTrait.php
More file actions
83 lines (73 loc) · 2.37 KB
/
Copy pathServicesTrait.php
File metadata and controls
83 lines (73 loc) · 2.37 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
<?php
/**
* @file
* Contains Drupal\AppConsole\Command\Helper\ServicesTrait.
*/
namespace Drupal\AppConsole\Command\Helper;
use Symfony\Component\Console\Helper\HelperInterface;
use Symfony\Component\Console\Output\OutputInterface;
trait ServicesTrait
{
/**
* @param OutputInterface $output
* @param HelperInterface $dialog
* @return mixed
*/
public function servicesQuestion(OutputInterface $output, HelperInterface $dialog)
{
if ($dialog->askConfirmation(
$output,
$dialog->getQuestion($this->trans('commands.common.questions.services.confirm'), 'no', '?'),
false
)
) {
$service_collection = [];
$output->writeln($this->trans('commands.common.questions.services.message'));
$services = $this->getServices();
while (true) {
$service = $dialog->askAndValidate(
$output,
$dialog->getQuestion($this->trans('commands.common.questions.services.name'), ''),
function ($service) use ($services) {
return $this->validateServiceExist($service, $services);
},
false,
null,
$services
);
if (empty($service)) {
break;
}
array_push($service_collection, $service);
$service_key = array_search($service, $services, true);
if ($service_key >= 0) {
unset($services[$service_key]);
}
}
return $service_collection;
}
return null;
}
/**
* @param Array $services
* @return Array
*/
public function buildServices($services)
{
if (!empty($services)) {
$build_service = [];
foreach ($services as $service) {
$class = get_class($this->getContainer()->get($service));
$explode_class = explode('\\', $class);
$build_service[$service] = [
'name' => $service,
'machine_name' => str_replace('.', '_', $service),
'class' => $class,
'short' => end($explode_class),
];
}
return $build_service;
}
return null;
}
}