1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

Fixed case-sensitivity of custom DQL functions.

This commit is contained in:
Roman S. Borschel 2010-04-15 20:14:03 +02:00
parent 01c2c06bbf
commit 4b39705cd4
2 changed files with 24 additions and 12 deletions

View file

@ -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
*/ */
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
*/ */
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
* 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
*/ */
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
*/ */
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
* 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
*/ */
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
*/ */
public function setCustomDatetimeFunctions(array $functions) public function setCustomDatetimeFunctions(array $functions)
{ {
$this->_attributes['customDatetimeFunctions'] = $functions; $this->_attributes['customDatetimeFunctions'] = array_change_key_case($functions);
} }
} }

View file

@ -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
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
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;