1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ORM\Tools\Console\Command; |
21
|
|
|
|
22
|
|
|
use Doctrine\ORM\Mapping\MappingException; |
23
|
|
|
use Symfony\Component\Console\Command\Command; |
24
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
25
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
26
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Show information about mapped entities. |
30
|
|
|
* |
31
|
|
|
* @link www.doctrine-project.org |
32
|
|
|
* @since 2.1 |
33
|
|
|
* @author Benjamin Eberlei <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class InfoCommand extends Command |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
3 |
|
protected function configure() |
41
|
|
|
{ |
42
|
3 |
|
$this->setName('orm:info') |
43
|
3 |
|
->setDescription('Show basic information about all mapped entities') |
44
|
3 |
|
->setHelp(<<<EOT |
45
|
3 |
|
The <info>%command.name%</info> shows basic information about which |
46
|
|
|
entities exist and possibly if their mapping information contains errors or |
47
|
|
|
not. |
48
|
|
|
EOT |
49
|
|
|
); |
50
|
3 |
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
3 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
56
|
|
|
{ |
57
|
3 |
|
$ui = new SymfonyStyle($input, $output); |
58
|
|
|
|
59
|
|
|
/* @var $entityManager \Doctrine\ORM\EntityManager */ |
60
|
3 |
|
$entityManager = $this->getHelper('em')->getEntityManager(); |
61
|
|
|
|
62
|
3 |
|
$entityClassNames = $entityManager->getConfiguration() |
63
|
3 |
|
->getMetadataDriverImpl() |
64
|
3 |
|
->getAllClassNames(); |
65
|
|
|
|
66
|
3 |
|
if ( ! $entityClassNames) { |
|
|
|
|
67
|
1 |
|
$ui->caution( |
68
|
|
|
[ |
69
|
1 |
|
'You do not have any mapped Doctrine ORM entities according to the current configuration.', |
70
|
|
|
'If you have entities or mapping files you should check your mapping configuration for errors.' |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
|
74
|
1 |
|
return 1; |
75
|
|
|
} |
76
|
|
|
|
77
|
2 |
|
$ui->text(sprintf("Found <info>%d</info> mapped entities:", count($entityClassNames))); |
78
|
2 |
|
$ui->newLine(); |
79
|
|
|
|
80
|
2 |
|
$failure = false; |
81
|
|
|
|
82
|
2 |
|
foreach ($entityClassNames as $entityClassName) { |
83
|
|
|
try { |
84
|
2 |
|
$entityManager->getClassMetadata($entityClassName); |
85
|
1 |
|
$ui->text(sprintf("<info>[OK]</info> %s", $entityClassName)); |
86
|
1 |
|
} catch (MappingException $e) { |
87
|
1 |
|
$ui->text( |
88
|
|
|
[ |
89
|
1 |
|
sprintf("<error>[FAIL]</error> %s", $entityClassName), |
90
|
1 |
|
sprintf("<comment>%s</comment>", $e->getMessage()), |
91
|
1 |
|
'' |
92
|
|
|
] |
93
|
|
|
); |
94
|
|
|
|
95
|
2 |
|
$failure = true; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
2 |
|
return $failure ? 1 : 0; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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.