diff --git a/docs/en/cookbook/dql-user-defined-functions.rst b/docs/en/cookbook/dql-user-defined-functions.rst index 77d66ad82..a3a7606ad 100644 --- a/docs/en/cookbook/dql-user-defined-functions.rst +++ b/docs/en/cookbook/dql-user-defined-functions.rst @@ -53,6 +53,17 @@ DQL query. ``$class`` is a string of a class-name which has to extend ``Doctrine\ORM\Query\Node\FunctionNode``. This is a class that offers all the necessary API and methods to implement a UDF. +Instead of providing the function class name, you can also provide +a callable that returns the function object: + +.. code-block:: php + + addCustomStringFunction($name, function () { + return new MyCustomFunction(); + }); + In this post we will implement some MySql specific Date calculation methods, which are quite handy in my opinion: diff --git a/lib/Doctrine/ORM/Configuration.php b/lib/Doctrine/ORM/Configuration.php index d9ff96b47..02433b93c 100644 --- a/lib/Doctrine/ORM/Configuration.php +++ b/lib/Doctrine/ORM/Configuration.php @@ -401,8 +401,8 @@ class Configuration extends \Doctrine\DBAL\Configuration * * DQL function names are case-insensitive. * - * @param string $name - * @param string $className + * @param string $name Function name. + * @param string|callable $className Class name or a callable that returns the function. * * @return void * @@ -459,8 +459,8 @@ class Configuration extends \Doctrine\DBAL\Configuration * * DQL function names are case-insensitive. * - * @param string $name - * @param string $className + * @param string $name Function name. + * @param string|callable $className Class name or a callable that returns the function. * * @return void * @@ -517,8 +517,8 @@ class Configuration extends \Doctrine\DBAL\Configuration * * DQL function names are case-insensitive. * - * @param string $name - * @param string $className + * @param string $name Function name. + * @param string|callable $className Class name or a callable that returns the function. * * @return void * diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index 762cf67ce..c64e731c6 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -3411,7 +3411,7 @@ class Parser $function = is_string($functionClass) ? new $functionClass($functionName) - : $functionClass($functionName); + : call_user_func($functionClass, $functionName); $function->parse($this); @@ -3450,7 +3450,7 @@ class Parser $function = is_string($functionClass) ? new $functionClass($functionName) - : $functionClass($functionName); + : call_user_func($functionClass, $functionName); $function->parse($this); @@ -3490,7 +3490,7 @@ class Parser $function = is_string($functionClass) ? new $functionClass($functionName) - : $functionClass($functionName); + : call_user_func($functionClass, $functionName); $function->parse($this);