Permalink
Browse files

Add entity manager to container. Allow passing in of Pimple container…

… to allow easy replacement within tests.
  • Loading branch information...
1 parent 0c47100 commit 7ff20c40271d05c0d28c970065a2d62fae877988 @adeslade committed Jan 15, 2012
Showing with 16 additions and 3 deletions.
  1. +15 −2 library/Example/Application/Resource/Container.php
  2. +1 −1 public/index.php
@@ -2,6 +2,8 @@
namespace Example\Application\Resource;
use Zend_Application_Resource_ResourceAbstract,
+ Doctrine\ORM\EntityManager,
+ Doctrine\ORM\Tools\Setup,
Pimple;
class Container extends Zend_Application_Resource_ResourceAbstract
@@ -10,15 +12,26 @@ class Container extends Zend_Application_Resource_ResourceAbstract
protected $container;
- public function __construct($options = null)
+ public function __construct($options = null, $container = null)
{
parent::__construct($options);
- $this->container = new Pimple;
+ $this->container = $container;
}
public function init()
{
+ $options = $this->getBootstrap()->getOptions();
+ $db = $options['db'];
+
+ $this->container['entityManager'] = $this->container->share(function ($c) use ($db) {
+ $isDevMode = APPLICATION_ENV == 'development';
+
+ $config = Setup::createAnnotationMetadataConfiguration(array(APPLICATION_PATH . '/models'), $isDevMode);
+
+ return EntityManager::create($db, $config);
+ });
+
return $this->container;
}
}
View
@@ -23,7 +23,7 @@
APPLICATION_PATH . '/configs/application.ini'
);
-$resource = new \Example\Application\Resource\Container;
+$resource = new \Example\Application\Resource\Container(null, new Pimple);
$application->getBootstrap()->registerPluginResource($resource);
$application->bootstrap()

0 comments on commit 7ff20c4

Please sign in to comment.