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