Skip to content

Commit

Permalink
allow adding custom types via module config
Browse files Browse the repository at this point in the history
  • Loading branch information
prolic committed Apr 29, 2015
1 parent e97996c commit 8d3f5dc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config/module.config.php
Expand Up @@ -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'
)
Expand Down
24 changes: 24 additions & 0 deletions src/DoctrineMongoODMModule/Options/Configuration.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions src/DoctrineMongoODMModule/Service/ConfigurationFactory.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 8d3f5dc

Please sign in to comment.