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 LGPL. 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\Input\InputOption; |
---|
24 | use Symfony\Component\Console\Input\InputInterface; |
---|
25 | use Symfony\Component\Console\Output\OutputInterface; |
---|
26 | use Symfony\Component\Console\Command\Command; |
---|
27 | |
---|
28 | /** |
---|
29 | * Show information about mapped entities |
---|
30 | * |
---|
31 | * @license http://www.opensource.org/licenses/lgpl-license.php LGPL |
---|
32 | * @link www.doctrine-project.org |
---|
33 | * @since 2.1 |
---|
34 | * @author Benjamin Eberlei <kontakt@beberlei.de> |
---|
35 | */ |
---|
36 | class InfoCommand extends Command |
---|
37 | { |
---|
38 | protected function configure() |
---|
39 | { |
---|
40 | $this |
---|
41 | ->setName('orm:info') |
---|
42 | ->setDescription('Show basic information about all mapped entities') |
---|
43 | ->setHelp(<<<EOT |
---|
44 | The <info>doctrine:mapping:info</info> shows basic information about which |
---|
45 | entities exist and possibly if their mapping information contains errors or |
---|
46 | not. |
---|
47 | EOT |
---|
48 | ); |
---|
49 | } |
---|
50 | |
---|
51 | protected function execute(InputInterface $input, OutputInterface $output) |
---|
52 | { |
---|
53 | /* @var $entityManager \Doctrine\ORM\EntityManager */ |
---|
54 | $entityManager = $this->getHelper('em')->getEntityManager(); |
---|
55 | |
---|
56 | $entityClassNames = $entityManager->getConfiguration() |
---|
57 | ->getMetadataDriverImpl() |
---|
58 | ->getAllClassNames(); |
---|
59 | |
---|
60 | if (!$entityClassNames) { |
---|
61 | throw new \Exception( |
---|
62 | 'You do not have any mapped Doctrine ORM entities according to the current configuration. '. |
---|
63 | 'If you have entities or mapping files you should check your mapping configuration for errors.' |
---|
64 | ); |
---|
65 | } |
---|
66 | |
---|
67 | $output->writeln(sprintf("Found <info>%d</info> mapped entities:", count($entityClassNames))); |
---|
68 | |
---|
69 | foreach ($entityClassNames as $entityClassName) { |
---|
70 | try { |
---|
71 | $cm = $entityManager->getClassMetadata($entityClassName); |
---|
72 | $output->writeln(sprintf("<info>[OK]</info> %s", $entityClassName)); |
---|
73 | } catch (MappingException $e) { |
---|
74 | $output->writeln("<error>[FAIL]</error> ".$entityClassName); |
---|
75 | $output->writeln(sprintf("<comment>%s</comment>", $e->getMessage())); |
---|
76 | $output->writeln(''); |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | } |
---|