Browse Source

Merge remote branch 'weaverryan/doctrine_controller_methods'

* weaverryan/doctrine_controller_methods:
  [FrameworkBundle] Adding a check for the existence of the Doctrine service
  [DoctrineBundle] Fixing error per @stloyd
  [FrameworkBundle][DoctrineBundle] Adding a few shortcut methods
Fabien Potencier 14 years ago
parent
commit
604b043d6e

+ 13 - 0
src/Symfony/Bundle/DoctrineBundle/Registry.php

@@ -108,6 +108,19 @@ class Registry
         return $this->container->get($this->entityManagers[$name]);
     }
 
+    /**
+     * Shortcut method to return the EntityRepository for an entity.
+     *
+     * @param string $entityName The name of the entity.
+     * @param string $entityManagerNAme The entity manager name (null for the default one)
+     * @return Doctrine\ORM\EntityRepository
+     */
+    public function getRepository($entityName, $entityManagerName = null)
+    {
+        return $this->getEntityManager($entityManagerName)
+            ->getRespository($entityName);
+    }
+
     /**
      * Resets a named entity manager.
      *

+ 14 - 0
src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

@@ -137,6 +137,20 @@ class Controller extends ContainerAware
         return $this->get('form.factory')->createBuilder('form', $data, $options);
     }
 
+    /**
+     * Shortcut to return the Doctrine Registry class
+     *
+     * @return Symfony\Bundle\DoctrineBundle\Registry
+     */
+    public function getDoctrine()
+    {
+        if (!$this->has('doctrine')) {
+            throw new \LogicException('The DoctrineBundle is not installed in your application.');
+        }
+
+        return $this->get('doctrine');
+    }
+
     /**
      * Returns true if the service id is defined.
      *