Skip to content

Commit

Permalink
No longer treat aggregate functions as a special case.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathew Davies authored and lcobucci committed Jun 20, 2017
1 parent e4ff7a3 commit 866418e
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 79 deletions.
12 changes: 0 additions & 12 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,6 @@ public function ensureProductionSettings()
*/
public function addCustomStringFunction($name, $className)
{
if (Query\Parser::isInternalFunction($name)) {
throw ORMException::overwriteInternalDQLFunctionNotAllowed($name);
}

$this->_attributes['customStringFunctions'][strtolower($name)] = $className;
}

Expand Down Expand Up @@ -483,10 +479,6 @@ public function setCustomStringFunctions(array $functions)
*/
public function addCustomNumericFunction($name, $className)
{
if (Query\Parser::isInternalFunction($name)) {
throw ORMException::overwriteInternalDQLFunctionNotAllowed($name);
}

$this->_attributes['customNumericFunctions'][strtolower($name)] = $className;
}

Expand Down Expand Up @@ -541,10 +533,6 @@ public function setCustomNumericFunctions(array $functions)
*/
public function addCustomDatetimeFunction($name, $className)
{
if (Query\Parser::isInternalFunction($name)) {
throw ORMException::overwriteInternalDQLFunctionNotAllowed($name);
}

$this->_attributes['customDatetimeFunctions'][strtolower($name)] = $className;
}

Expand Down
10 changes: 0 additions & 10 deletions lib/Doctrine/ORM/ORMException.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,16 +323,6 @@ public static function unrecognizedIdentifierFields($className, $fieldNames)
);
}

/**
* @param string $functionName
*
* @return ORMException
*/
public static function overwriteInternalDQLFunctionNotAllowed($functionName)
{
return new self("It is not allowed to overwrite internal function '$functionName' in the DQL parser through user-defined functions.");
}

/**
* @return ORMException
*/
Expand Down
55 changes: 55 additions & 0 deletions lib/Doctrine/ORM/Query/AST/Functions/AvgFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\AST\AggregateExpression;

/**
* "AVG" "(" ["DISTINCT"] StringPrimary ")"
*
* @link www.doctrine-project.org
* @since 2.0
* @author Mathew Davies <[email protected]>
*/
class AvgFunction extends FunctionNode
{
/**
* @var AggregateExpression
*/
public $aggregateExpression;

/**
* @inheritDoc
*/
public function getSql(SqlWalker $sqlWalker)
{
return $this->aggregateExpression->dispatch($sqlWalker);
}

/**
* @inheritDoc
*/
public function parse(Parser $parser)
{
$this->aggregateExpression = $parser->AggregateExpression();
}
}
55 changes: 55 additions & 0 deletions lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\AST\AggregateExpression;

/**
* "COUNT" "(" ["DISTINCT"] StringPrimary ")"
*
* @link www.doctrine-project.org
* @since 2.0
* @author Mathew Davies <[email protected]>
*/
class CountFunction extends FunctionNode
{
/**
* @var AggregateExpression
*/
public $aggregateExpression;

/**
* @inheritDoc
*/
public function getSql(SqlWalker $sqlWalker)
{
return $this->aggregateExpression->dispatch($sqlWalker);
}

/**
* @inheritDoc
*/
public function parse(Parser $parser)
{
$this->aggregateExpression = $parser->AggregateExpression();
}
}
55 changes: 55 additions & 0 deletions lib/Doctrine/ORM/Query/AST/Functions/MaxFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\AST\AggregateExpression;

/**
* "MAX" "(" ["DISTINCT"] StringPrimary ")"
*
* @link www.doctrine-project.org
* @since 2.0
* @author Mathew Davies <[email protected]>
*/
class MaxFunction extends FunctionNode
{
/**
* @var AggregateExpression
*/
public $aggregateExpression;

/**
* @inheritDoc
*/
public function getSql(SqlWalker $sqlWalker)
{
return $this->aggregateExpression->dispatch($sqlWalker);
}

/**
* @inheritDoc
*/
public function parse(Parser $parser)
{
$this->aggregateExpression = $parser->AggregateExpression();
}
}
55 changes: 55 additions & 0 deletions lib/Doctrine/ORM/Query/AST/Functions/MinFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\AST\AggregateExpression;

/**
* "MIN" "(" ["DISTINCT"] StringPrimary ")"
*
* @link www.doctrine-project.org
* @since 2.0
* @author Mathew Davies <[email protected]>
*/
class MinFunction extends FunctionNode
{
/**
* @var AggregateExpression
*/
public $aggregateExpression;

/**
* @inheritDoc
*/
public function getSql(SqlWalker $sqlWalker)
{
return $this->aggregateExpression->dispatch($sqlWalker);
}

/**
* @inheritDoc
*/
public function parse(Parser $parser)
{
$this->aggregateExpression = $parser->AggregateExpression();
}
}
55 changes: 55 additions & 0 deletions lib/Doctrine/ORM/Query/AST/Functions/SumFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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 MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/

namespace Doctrine\ORM\Query\AST\Functions;

use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;
use Doctrine\ORM\Query\AST\AggregateExpression;

/**
* "SUM" "(" ["DISTINCT"] StringPrimary ")"
*
* @link www.doctrine-project.org
* @since 2.0
* @author Mathew Davies <[email protected]>
*/
class SumFunction extends FunctionNode
{
/**
* @var AggregateExpression
*/
public $aggregateExpression;

/**
* @inheritDoc
*/
public function getSql(SqlWalker $sqlWalker)
{
return $this->aggregateExpression->dispatch($sqlWalker);
}

/**
* @inheritDoc
*/
public function parse(Parser $parser)
{
$this->aggregateExpression = $parser->AggregateExpression();
}
}
Loading

0 comments on commit 866418e

Please sign in to comment.