Skip to content

Commit

Permalink
Merge pull request #127 from bsahlhof/master
Browse files Browse the repository at this point in the history
Add ability to define SQLFilters within ZF2 configuration
  • Loading branch information
Ocramius committed Oct 8, 2012
2 parents 71b0e01 + 344a4a9 commit 28eb1c1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineORMModule/Proxy',
'proxy_namespace' => 'DoctrineORMModule\Proxy'
'proxy_namespace' => 'DoctrineORMModule\Proxy',
'filters' => array()
)
),

Expand Down
26 changes: 26 additions & 0 deletions src/DoctrineORMModule/Options/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ class Configuration extends DBALConfiguration
*/
protected $numericFunctions = array();

/**
* Keys must be the name of the custom filter and the value must be
* the class name for the custom filter.
*
* @var array
*/
protected $filters = array();

/**
* Keys must be the name of the query and values the DQL query string.
*
Expand Down Expand Up @@ -268,6 +276,24 @@ public function getNumericFunctions()
return $this->numericFunctions;
}

/**
*
* @param array $filters
* @return self
*/
public function setFilters($filters) {
$this->filters = $filters;
return $this;
}

/**
*
* @return array
*/
public function getFilters() {
return $this->filters;
}

/**
* @param string $proxyDir
* @return self
Expand Down
4 changes: 4 additions & 0 deletions src/DoctrineORMModule/Service/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function createService(ServiceLocatorInterface $serviceLocator)
foreach ($options->getCustomHydrationModes() AS $modeName => $hydrator) {
$config->addCustomHydrationMode($modeName, $hydrator);
}

foreach ($options->getFilters() as $name => $class) {
$config->addFilter($name, $class);
}

$config->setMetadataCacheImpl($serviceLocator->get($options->getMetadataCache()));
$config->setQueryCacheImpl($serviceLocator->get($options->getQueryCache()));
Expand Down

0 comments on commit 28eb1c1

Please sign in to comment.