[DDC-551] Initial code for filter functionality
This commit is contained in:
parent
99bdf65c10
commit
a85902b08d
@ -515,4 +515,16 @@ class Configuration extends \Doctrine\DBAL\Configuration
|
|||||||
}
|
}
|
||||||
return $this->_attributes['classMetadataFactoryName'];
|
return $this->_attributes['classMetadataFactoryName'];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public function addFilter($name, $className)
|
||||||
|
{
|
||||||
|
$this->_attributes['filters'][strtolower($name)] = $className;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFilterClassName($name)
|
||||||
|
{
|
||||||
|
$name = strtolower($name);
|
||||||
|
return isset($this->_attributes['filters'][$name]) ?
|
||||||
|
$this->_attributes['filters'][$name] : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -110,6 +110,13 @@ class EntityManager implements ObjectManager
|
|||||||
*/
|
*/
|
||||||
private $closed = false;
|
private $closed = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instances of enabled filters.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $enabledFilters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new EntityManager that operates on the given database connection
|
* Creates a new EntityManager that operates on the given database connection
|
||||||
* and uses the given Configuration and EventManager implementations.
|
* and uses the given Configuration and EventManager implementations.
|
||||||
@ -739,4 +746,46 @@ class EntityManager implements ObjectManager
|
|||||||
|
|
||||||
return new EntityManager($conn, $config, $conn->getEventManager());
|
return new EntityManager($conn, $config, $conn->getEventManager());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return SQLFilter[] */
|
||||||
|
public function getEnabledFilters()
|
||||||
|
{
|
||||||
|
return $enabledFilters;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Throws exception if filter does not exist. No-op if the filter is alrady enabled.
|
||||||
|
* @return SQLFilter */
|
||||||
|
public function enableFilter($name)
|
||||||
|
{
|
||||||
|
if(null === $filterClass = $this->config->getFilter($name)) {
|
||||||
|
throw new \InvalidArgumentException("Filter '" . $name . "' is does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isset($this->enabledFilters[$name])) {
|
||||||
|
$this->enabledFilters[$name] = new $filterClass($this->conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->enabledFilters[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Disable the filter, looses the state */
|
||||||
|
public function disableFilter($name)
|
||||||
|
{
|
||||||
|
// Get the filter to return it
|
||||||
|
$filter = $this->getFilter($name);
|
||||||
|
|
||||||
|
unset($this->enabledFilters[$name]);
|
||||||
|
|
||||||
|
return $filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** throws exception if not in enabled filters */
|
||||||
|
public function getFilter($name)
|
||||||
|
{
|
||||||
|
if(!isset($this->enabledFilters[$name])) {
|
||||||
|
throw new \InvalidArgumentException("Filter '" . $name . "' is not enabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->enabledFilters[$name];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
61
lib/Doctrine/ORM/Query/Filter/SQLFilter.php
Normal file
61
lib/Doctrine/ORM/Query/Filter/SQLFilter.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many individuals
|
||||||
|
* and is licensed under the LGPL. For more information, see
|
||||||
|
* <http://www.doctrine-project.org>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Doctrine\ORM\Query\Filter;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base class that user defined filters should extend.
|
||||||
|
*
|
||||||
|
* Handles the setting and escaping of parameters.
|
||||||
|
*
|
||||||
|
* @author Alexander <iam.asm89@gmail.com>
|
||||||
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||||
|
* @abstract
|
||||||
|
*/
|
||||||
|
abstract class SQLFilter
|
||||||
|
{
|
||||||
|
private $conn;
|
||||||
|
|
||||||
|
private $parameters;
|
||||||
|
|
||||||
|
final public function __construct(Connection $conn)
|
||||||
|
{
|
||||||
|
$this->conn = $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
final function setParameter($name, $value, $type)
|
||||||
|
{
|
||||||
|
// @todo: check for a valid type?
|
||||||
|
$parameters[$name] = array('value' => $value, 'type' => $type);
|
||||||
|
}
|
||||||
|
|
||||||
|
final function getParameter($name)
|
||||||
|
{
|
||||||
|
if(!isset($parameters[$name])) {
|
||||||
|
throw new \InvalidArgumentException("Parameter '" . $name . "' is does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// @todo: espace the parameter
|
||||||
|
return $paramaters[$name]['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user