The same way, i replaced EntityManager like this, but i suppose it's not the
best way.
I wanted to try to develop a new module for that, but i'm not a killer like
you @Ocramius lol
public function getOm()
{
return $this->getServiceLocator()->get('om');
}
'om' => 'Application\Service\ObjectManagerFactory',
ObjectManagerFactory:
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('config');
switch ($config['Application']['object_manager']) {
case 'orm':
$entityManager =
$serviceLocator->get('doctrine.entitymanager.orm_default');
$object = new EntityManagerDecorator($entityManager);
break;
case 'odm':
$documentManager =
$serviceLocator->get('doctrine.documentmanager.odm_default');
$object = new
DocumentManagerDecorator($documentManager);
break;
default:
throw new \Exception('Object Manager undefined');
break;
}
return $object;
}
class EntityManagerDecorator extends ObjectManagerDecorator
{
public function __construct($em) {
$this->wrapped = $em;
}
public function __call($method, $args) {
return call_user_func_array(array($this->wrapped, $method),
$args);
}
public function getRepository($class) {
$class = str_replace("\\Document\\", "\\Entity\\", $class);
return $this->wrapped->getRepository($class);
}
}
class DocumentManagerDecorator extends ObjectManagerDecorator
{
public function __construct($dm) {
$this->wrapped = $dm;
}
public function __call($method, $args) {
return call_user_func_array(array($this->wrapped, $method),
$args);
}
public function getRepository($class) {
$class = str_replace("\\Entity\\", "\\Document\\", $class);
return $this->wrapped->getRepository($class);
}
}
--
View this message in context:
http://zend-framework-community.634137.n4.nabble.com/ZF2-Enable-additional-modules-in-local-development-environment-tp4657754p4659889.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]