InfoCommand.php 3.2 KB

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