-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow internal functions to be overridden. #6500
Changes from all commits
914c400
e4ff7a3
866418e
e484753
966f9a8
3e3751c
49e4b10
05758f4
747c185
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -420,15 +420,9 @@ public function ensureProductionSettings() | |
* @param string|callable $className Class name or a callable that returns the function. | ||
* | ||
* @return void | ||
* | ||
* @throws ORMException | ||
*/ | ||
public function addCustomStringFunction($name, $className) | ||
{ | ||
if (Query\Parser::isInternalFunction($name)) { | ||
throw ORMException::overwriteInternalDQLFunctionNotAllowed($name); | ||
} | ||
|
||
$this->_attributes['customStringFunctions'][strtolower($name)] = $className; | ||
} | ||
|
||
|
@@ -478,15 +472,9 @@ public function setCustomStringFunctions(array $functions) | |
* @param string|callable $className Class name or a callable that returns the function. | ||
* | ||
* @return void | ||
* | ||
* @throws ORMException | ||
*/ | ||
public function addCustomNumericFunction($name, $className) | ||
{ | ||
if (Query\Parser::isInternalFunction($name)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
throw ORMException::overwriteInternalDQLFunctionNotAllowed($name); | ||
} | ||
|
||
$this->_attributes['customNumericFunctions'][strtolower($name)] = $className; | ||
} | ||
|
||
|
@@ -536,15 +524,9 @@ public function setCustomNumericFunctions(array $functions) | |
* @param string|callable $className Class name or a callable that returns the function. | ||
* | ||
* @return void | ||
* | ||
* @throws ORMException | ||
*/ | ||
public function addCustomDatetimeFunction($name, $className) | ||
{ | ||
if (Query\Parser::isInternalFunction($name)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
throw ORMException::overwriteInternalDQLFunctionNotAllowed($name); | ||
} | ||
|
||
$this->_attributes['customDatetimeFunctions'][strtolower($name)] = $className; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,16 +323,6 @@ public static function unrecognizedIdentifierFields($className, $fieldNames) | |
); | ||
} | ||
|
||
/** | ||
* @param string $functionName | ||
* | ||
* @return ORMException | ||
*/ | ||
public static function overwriteInternalDQLFunctionNotAllowed($functionName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method removal is effectively a BC break, and while it is an internal method, it should be documented in |
||
{ | ||
return new self("It is not allowed to overwrite internal function '$functionName' in the DQL parser through user-defined functions."); | ||
} | ||
|
||
/** | ||
* @return ORMException | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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 ")" | ||
* | ||
* @since 2.6 | ||
* @author Mathew Davies <thepixeldeveloper@icloud.com> | ||
*/ | ||
final class AvgFunction extends FunctionNode | ||
{ | ||
/** | ||
* @var AggregateExpression | ||
*/ | ||
private $aggregateExpression; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getSql(SqlWalker $sqlWalker): string | ||
{ | ||
return $this->aggregateExpression->dispatch($sqlWalker); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function parse(Parser $parser): void | ||
{ | ||
$this->aggregateExpression = $parser->AggregateExpression(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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 ")" | ||
* | ||
* @since 2.6 | ||
* @author Mathew Davies <thepixeldeveloper@icloud.com> | ||
*/ | ||
final class CountFunction extends FunctionNode | ||
{ | ||
/** | ||
* @var AggregateExpression | ||
*/ | ||
private $aggregateExpression; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getSql(SqlWalker $sqlWalker): string | ||
{ | ||
return $this->aggregateExpression->dispatch($sqlWalker); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function parse(Parser $parser): void | ||
{ | ||
$this->aggregateExpression = $parser->AggregateExpression(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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 ")" | ||
* | ||
* @since 2.6 | ||
* @author Mathew Davies <thepixeldeveloper@icloud.com> | ||
*/ | ||
final class MaxFunction extends FunctionNode | ||
{ | ||
/** | ||
* @var AggregateExpression | ||
*/ | ||
private $aggregateExpression; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getSql(SqlWalker $sqlWalker): string | ||
{ | ||
return $this->aggregateExpression->dispatch($sqlWalker); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function parse(Parser $parser): void | ||
{ | ||
$this->aggregateExpression = $parser->AggregateExpression(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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 ")" | ||
* | ||
* @since 2.6 | ||
* @author Mathew Davies <thepixeldeveloper@icloud.com> | ||
*/ | ||
final class MinFunction extends FunctionNode | ||
{ | ||
/** | ||
* @var AggregateExpression | ||
*/ | ||
private $aggregateExpression; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getSql(SqlWalker $sqlWalker): string | ||
{ | ||
return $this->aggregateExpression->dispatch($sqlWalker); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function parse(Parser $parser): void | ||
{ | ||
$this->aggregateExpression = $parser->AggregateExpression(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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 ")" | ||
* | ||
* @since 2.6 | ||
* @author Mathew Davies <thepixeldeveloper@icloud.com> | ||
*/ | ||
final class SumFunction extends FunctionNode | ||
{ | ||
/** | ||
* @var AggregateExpression | ||
*/ | ||
private $aggregateExpression; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getSql(SqlWalker $sqlWalker): string | ||
{ | ||
return $this->aggregateExpression->dispatch($sqlWalker); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function parse(Parser $parser): void | ||
{ | ||
$this->aggregateExpression = $parser->AggregateExpression(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@throws
in docblock needs to be removed