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 ...@@ -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 * Such a function can then be used in any DQL statement in any place where string
* functions are allowed. * functions are allowed.
* *
* DQL function names are case-insensitive.
*
* @param string $name * @param string $name
* @param string $className * @param string $className
*/ */
...@@ -355,6 +357,7 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -355,6 +357,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/ */
public function getCustomStringFunction($name) public function getCustomStringFunction($name)
{ {
$name = strtolower($name);
return isset($this->_attributes['customStringFunctions'][$name]) ? return isset($this->_attributes['customStringFunctions'][$name]) ?
$this->_attributes['customStringFunctions'][$name] : null; $this->_attributes['customStringFunctions'][$name] : null;
} }
...@@ -371,7 +374,7 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -371,7 +374,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/ */
public function setCustomStringFunctions(array $functions) 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 ...@@ -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 * Such a function can then be used in any DQL statement in any place where numeric
* functions are allowed. * functions are allowed.
* *
* DQL function names are case-insensitive.
*
* @param string $name * @param string $name
* @param string $className * @param string $className
*/ */
...@@ -395,6 +400,7 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -395,6 +400,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/ */
public function getCustomNumericFunction($name) public function getCustomNumericFunction($name)
{ {
$name = strtolower($name);
return isset($this->_attributes['customNumericFunctions'][$name]) ? return isset($this->_attributes['customNumericFunctions'][$name]) ?
$this->_attributes['customNumericFunctions'][$name] : null; $this->_attributes['customNumericFunctions'][$name] : null;
} }
...@@ -411,7 +417,7 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -411,7 +417,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/ */
public function setCustomNumericFunctions(array $functions) 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 ...@@ -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 * Such a function can then be used in any DQL statement in any place where date/time
* functions are allowed. * functions are allowed.
* *
* DQL function names are case-insensitive.
*
* @param string $name * @param string $name
* @param string $className * @param string $className
*/ */
...@@ -435,6 +443,7 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -435,6 +443,7 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/ */
public function getCustomDatetimeFunction($name) public function getCustomDatetimeFunction($name)
{ {
$name = strtolower($name);
return isset($this->_attributes['customDatetimeFunctions'][$name]) ? return isset($this->_attributes['customDatetimeFunctions'][$name]) ?
$this->_attributes['customDatetimeFunctions'][$name] : null; $this->_attributes['customDatetimeFunctions'][$name] : null;
} }
...@@ -451,6 +460,6 @@ class Configuration extends \Doctrine\DBAL\Configuration ...@@ -451,6 +460,6 @@ class Configuration extends \Doctrine\DBAL\Configuration
*/ */
public function setCustomDatetimeFunctions(array $functions) 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 ...@@ -2619,9 +2619,10 @@ class Parser
public function CustomFunctionsReturningNumerics() public function CustomFunctionsReturningNumerics()
{ {
$funcNameLower = strtolower($this->_lexer->lookahead['value']); $funcName = strtolower($this->_lexer->lookahead['value']);
$funcClass = $this->_em->getConfiguration()->getCustomNumericFunction($funcNameLower); // getCustomNumericFunction is case-insensitive
$function = new $funcClass($funcNameLower); $funcClass = $this->_em->getConfiguration()->getCustomNumericFunction($funcName);
$function = new $funcClass($funcName);
$function->parse($this); $function->parse($this);
return $function; return $function;
...@@ -2642,9 +2643,10 @@ class Parser ...@@ -2642,9 +2643,10 @@ class Parser
public function CustomFunctionsReturningDatetime() public function CustomFunctionsReturningDatetime()
{ {
$funcNameLower = strtolower($this->_lexer->lookahead['value']); $funcName = $this->_lexer->lookahead['value'];
$funcClass = $this->_em->getConfiguration()->getCustomDatetimeFunction($funcNameLower); // getCustomDatetimeFunction is case-insensitive
$function = new $funcClass($funcNameLower); $funcClass = $this->_em->getConfiguration()->getCustomDatetimeFunction($funcName);
$function = new $funcClass($funcName);
$function->parse($this); $function->parse($this);
return $function; return $function;
...@@ -2670,9 +2672,10 @@ class Parser ...@@ -2670,9 +2672,10 @@ class Parser
public function CustomFunctionsReturningStrings() public function CustomFunctionsReturningStrings()
{ {
$funcNameLower = strtolower($this->_lexer->lookahead['value']); $funcName = $this->_lexer->lookahead['value'];
$funcClass = $this->_em->getConfiguration()->getCustomStringFunction($funcNameLower); // getCustomStringFunction is case-insensitive
$function = new $funcClass($funcNameLower); $funcClass = $this->_em->getConfiguration()->getCustomStringFunction($funcName);
$function = new $funcClass($funcName);
$function->parse($this); $function->parse($this);
return $function; 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