1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\DashboardBundle\Command; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\DashboardBundle\Entity\AnalyticsConfig; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @final since 5.1 |
13
|
|
|
* NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages |
14
|
|
|
*/ |
15
|
|
|
class GoogleAnalyticsConfigsListCommand extends ContainerAwareCommand |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var EntityManagerInterface |
19
|
|
|
*/ |
20
|
|
|
private $em; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param EntityManagerInterface|null $em |
24
|
|
|
*/ |
25
|
|
|
public function __construct(/* EntityManagerInterface */ $em = null) |
26
|
|
|
{ |
27
|
|
|
parent::__construct(); |
28
|
|
|
|
29
|
|
|
if (!$em instanceof EntityManagerInterface) { |
30
|
|
|
@trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED); |
31
|
|
|
|
32
|
|
|
$this->setName(null === $em ? 'kuma:dashboard:widget:googleanalytics:config:list' : $em); |
33
|
|
|
|
34
|
|
|
return; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$this->em = $em; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function configure() |
41
|
|
|
{ |
42
|
|
|
$this |
43
|
|
|
->setName('kuma:dashboard:widget:googleanalytics:configs:list') |
44
|
|
|
->setDescription('List available configs'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param InputInterface $input |
49
|
|
|
* @param OutputInterface $output |
50
|
|
|
* |
51
|
|
|
* @return int|void|null |
52
|
|
|
*/ |
53
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
54
|
|
|
{ |
55
|
|
|
if (null === $this->em) { |
56
|
|
|
$this->em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$configs = $this->getconfigs(); |
60
|
|
|
|
61
|
|
|
if (\count($configs)) { |
62
|
|
|
$result = "\t".'<fg=green>' . \count($configs) . '</fg=green> configs found:'; |
63
|
|
|
$output->writeln($result); |
64
|
|
|
foreach ($configs as $config) { |
65
|
|
|
$result = "\t".'(id: <fg=cyan>' .$config->getId() . '</fg=cyan>)'; |
66
|
|
|
$result .= "\t" . $config->getName(); |
67
|
|
|
|
68
|
|
|
$output->writeln($result); |
69
|
|
|
} |
70
|
|
|
} else { |
71
|
|
|
$output->writeln('No configs found'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return 0; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* get all segments |
79
|
|
|
* |
80
|
|
|
* @return array |
|
|
|
|
81
|
|
|
*/ |
82
|
|
|
private function getconfigs() |
83
|
|
|
{ |
84
|
|
|
// get all segments |
85
|
|
|
$configRepository = $this->em->getRepository(AnalyticsConfig::class); |
86
|
|
|
|
87
|
|
|
return $configRepository->findAll(); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.