1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\ORM\Tools\Console\Command; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\MappingException; |
8
|
|
|
use Symfony\Component\Console\Command\Command; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Show information about mapped entities. |
15
|
|
|
*/ |
16
|
|
|
class InfoCommand extends Command |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
2 |
|
protected function configure() |
22
|
|
|
{ |
23
|
2 |
|
$this->setName('orm:info') |
24
|
2 |
|
->setDescription('Show basic information about all mapped entities') |
25
|
2 |
|
->setHelp(<<<'EOT' |
26
|
2 |
|
The <info>%command.name%</info> shows basic information about which |
27
|
|
|
entities exist and possibly if their mapping information contains errors or |
28
|
|
|
not. |
29
|
|
|
EOT |
30
|
|
|
); |
31
|
2 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
2 |
|
$ui = new SymfonyStyle($input, $output); |
39
|
|
|
|
40
|
|
|
/* @var $entityManager \Doctrine\ORM\EntityManagerInterface */ |
41
|
2 |
|
$entityManager = $this->getHelper('em')->getEntityManager(); |
42
|
|
|
|
43
|
2 |
|
$entityClassNames = $entityManager->getConfiguration() |
44
|
2 |
|
->getMetadataDriverImpl() |
45
|
2 |
|
->getAllClassNames(); |
46
|
|
|
|
47
|
2 |
|
if (! $entityClassNames) { |
|
|
|
|
48
|
1 |
|
$ui->caution( |
49
|
|
|
[ |
50
|
1 |
|
'You do not have any mapped Doctrine ORM entities according to the current configuration.', |
51
|
|
|
'If you have entities or mapping files you should check your mapping configuration for errors.', |
52
|
|
|
] |
53
|
|
|
); |
54
|
|
|
|
55
|
1 |
|
return 1; |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
$ui->text(sprintf('Found <info>%d</info> mapped entities:', count($entityClassNames))); |
59
|
1 |
|
$ui->newLine(); |
60
|
|
|
|
61
|
1 |
|
$failure = false; |
62
|
|
|
|
63
|
1 |
|
foreach ($entityClassNames as $entityClassName) { |
64
|
|
|
try { |
65
|
1 |
|
$entityManager->getClassMetadata($entityClassName); |
66
|
1 |
|
$ui->text(sprintf('<info>[OK]</info> %s', $entityClassName)); |
67
|
|
|
} catch (MappingException $e) { |
68
|
|
|
$ui->text( |
69
|
|
|
[ |
70
|
|
|
sprintf('<error>[FAIL]</error> %s', $entityClassName), |
71
|
|
|
sprintf('<comment>%s</comment>', $e->getMessage()), |
72
|
|
|
'', |
73
|
|
|
] |
74
|
|
|
); |
75
|
|
|
|
76
|
1 |
|
$failure = true; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
1 |
|
return $failure ? 1 : 0; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.