BaseEntityManager.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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 Sonata\CoreBundle\Model;
  11. use Doctrine\ORM\EntityManager;
  12. /**
  13. * @author Sylvain Deloux <sylvain.deloux@ekino.com>
  14. */
  15. abstract class BaseEntityManager extends BaseManager
  16. {
  17. /**
  18. * Make sure the code is compatible with legacy code.
  19. *
  20. * @param $name
  21. *
  22. * @return mixed
  23. */
  24. public function __get($name)
  25. {
  26. if ($name === 'em') {
  27. return $this->getObjectManager();
  28. }
  29. throw new \RuntimeException(sprintf('The property %s does not exists', $name));
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getConnection()
  35. {
  36. return $this->getEntityManager()->getConnection();
  37. }
  38. /**
  39. * @return EntityManager
  40. */
  41. public function getEntityManager()
  42. {
  43. return $this->getObjectManager();
  44. }
  45. }