Commit 4b39705c authored by Roman S. Borschel's avatar Roman S. Borschel

Fixed case-sensitivity of custom DQL functions.

parent 01c2c06b
......@@ -339,6 +339,8 @@ class Configuration extends \Doctrine\DBAL\Configuration
* Such a function can then be used in any DQL statement in any place where string
* functions are allowed.
*
* DQL function names are case-insensitive.
*
* @param string $name
* @param string $className
*/
......@@ -355,6 +357,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/
public function getCustomStringFunction($name)
{
$name = strtolower($name);
return isset($this->_attributes['customStringFunctions'][$name]) ?
$this->_attributes['customStringFunctions'][$name] : null;
}
......@@ -371,7 +374,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/
public function setCustomStringFunctions(array $functions)
{
$this->_attributes['customStringFunctions'] = $functions;
$this->_attributes['customStringFunctions'] = array_change_key_case($functions);
}
/**
......@@ -379,6 +382,8 @@ class Configuration extends \Doctrine\DBAL\Configuration
* Such a function can then be used in any DQL statement in any place where numeric
* functions are allowed.
*
* DQL function names are case-insensitive.
*
* @param string $name
* @param string $className
*/
......@@ -395,6 +400,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/
public function getCustomNumericFunction($name)
{
$name = strtolower($name);
return isset($this->_attributes['customNumericFunctions'][$name]) ?
$this->_attributes['customNumericFunctions'][$name] : null;
}
......@@ -411,7 +417,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/
public function setCustomNumericFunctions(array $functions)
{
$this->_attributes['customNumericFunctions'] = $functions;
$this->_attributes['customNumericFunctions'] = array_change_key_case($functions);
}
/**
......@@ -419,6 +425,8 @@ class Configuration extends \Doctrine\DBAL\Configuration
* Such a function can then be used in any DQL statement in any place where date/time
* functions are allowed.
*
* DQL function names are case-insensitive.
*
* @param string $name
* @param string $className
*/
......@@ -435,6 +443,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/
public function getCustomDatetimeFunction($name)
{
$name = strtolower($name);
return isset($this->_attributes['customDatetimeFunctions'][$name]) ?
$this->_attributes['customDatetimeFunctions'][$name] : null;
}
......@@ -451,6 +460,6 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/
public function setCustomDatetimeFunctions(array $functions)
{
$this->_attributes['customDatetimeFunctions'] = $functions;
$this->_attributes['customDatetimeFunctions'] = array_change_key_case($functions);
}
}
\ No newline at end of file
......@@ -2619,9 +2619,10 @@ class Parser
public function CustomFunctionsReturningNumerics()
{
$funcNameLower = strtolower($this->_lexer->lookahead['value']);
$funcClass = $this->_em->getConfiguration()->getCustomNumericFunction($funcNameLower);
$function = new $funcClass($funcNameLower);
$funcName = strtolower($this->_lexer->lookahead['value']);
// getCustomNumericFunction is case-insensitive
$funcClass = $this->_em->getConfiguration()->getCustomNumericFunction($funcName);
$function = new $funcClass($funcName);
$function->parse($this);
return $function;
......@@ -2642,9 +2643,10 @@ class Parser
public function CustomFunctionsReturningDatetime()
{
$funcNameLower = strtolower($this->_lexer->lookahead['value']);
$funcClass = $this->_em->getConfiguration()->getCustomDatetimeFunction($funcNameLower);
$function = new $funcClass($funcNameLower);
$funcName = $this->_lexer->lookahead['value'];
// getCustomDatetimeFunction is case-insensitive
$funcClass = $this->_em->getConfiguration()->getCustomDatetimeFunction($funcName);
$function = new $funcClass($funcName);
$function->parse($this);
return $function;
......@@ -2670,9 +2672,10 @@ class Parser
public function CustomFunctionsReturningStrings()
{
$funcNameLower = strtolower($this->_lexer->lookahead['value']);
$funcClass = $this->_em->getConfiguration()->getCustomStringFunction($funcNameLower);
$function = new $funcClass($funcNameLower);
$funcName = $this->_lexer->lookahead['value'];
// getCustomStringFunction is case-insensitive
$funcClass = $this->_em->getConfiguration()->getCustomStringFunction($funcName);
$function = new $funcClass($funcName);
$function->parse($this);
return $function;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment