diff --git a/config/module.config.php b/config/module.config.php index 0264497..1ca947b 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -30,7 +30,10 @@ 'default_db' => null, - 'filters' => array() // array('filterName' => 'BSON\Filter\Class') + 'filters' => array(), // array('filterName' => 'BSON\Filter\Class') + + // custom types + 'types' => array() //'classMetadataFactoryName' => 'ClassName' ) diff --git a/src/DoctrineMongoODMModule/Options/Configuration.php b/src/DoctrineMongoODMModule/Options/Configuration.php index 55d9a54..fd55527 100644 --- a/src/DoctrineMongoODMModule/Options/Configuration.php +++ b/src/DoctrineMongoODMModule/Options/Configuration.php @@ -128,6 +128,14 @@ class Configuration extends AbstractOptions */ protected $retryQuery = 0; + /** + * Keys must be the name of the type identifier and value is + * the class name of the Type + * + * @var array + */ + protected $types = array(); + /** * * @param string $driver @@ -384,4 +392,20 @@ public function getRetryQuery() { return $this->retryQuery; } + + /** + * @param array $types + */ + public function setTypes(array $types) + { + $this->types = $types; + } + + /** + * @return array + */ + public function getTypes() + { + return $this->types; + } } diff --git a/src/DoctrineMongoODMModule/Service/ConfigurationFactory.php b/src/DoctrineMongoODMModule/Service/ConfigurationFactory.php index 15bc41d..457987b 100644 --- a/src/DoctrineMongoODMModule/Service/ConfigurationFactory.php +++ b/src/DoctrineMongoODMModule/Service/ConfigurationFactory.php @@ -18,6 +18,7 @@ */ namespace DoctrineMongoODMModule\Service; +use Doctrine\ODM\MongoDB\Types\Type; use DoctrineModule\Service\AbstractFactory; use Doctrine\ODM\MongoDB\Configuration; use Zend\ServiceManager\ServiceLocatorInterface; @@ -84,6 +85,15 @@ public function createService(ServiceLocatorInterface $serviceLocator) $config->setClassMetadataFactoryName($factoryName); } + // custom types + foreach ($options->getTypes() as $name => $class) { + if (Type::hasType($name)) { + Type::overrideType($name, $class); + } else { + Type::addType($name, $class); + } + } + return $config; }