GenerateDoctrineCommand.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sensio\Bundle\GeneratorBundle\Command;
  11. use Symfony\Bundle\DoctrineBundle\Mapping\MetadataFactory;
  12. use Symfony\Bundle\DoctrineBundle\Command\DoctrineCommand;
  13. abstract class GenerateDoctrineCommand extends DoctrineCommand
  14. {
  15. protected function parseShortcutNotation($shortcut)
  16. {
  17. $entity = str_replace('/', '\\', $shortcut);
  18. if (false === $pos = strpos($entity, ':')) {
  19. throw new \InvalidArgumentException(sprintf('The entity name must contain a : ("%s" given, expecting something like AcmeBlogBundle:Blog/Post)', $entity));
  20. }
  21. return array(substr($entity, 0, $pos), substr($entity, $pos + 1));
  22. }
  23. protected function getEntityMetadata($entity)
  24. {
  25. $factory = new MetadataFactory($this->getContainer()->get('doctrine'));
  26. return $factory->getClassMetadata($entity)->getMetadata();
  27. }
  28. }