Skip to content

Commit

Permalink
Merge pull request #1031 from mnapoli/custom-functions-callback-docum…
Browse files Browse the repository at this point in the history
…entation

Documentation for #991
  • Loading branch information
Ocramius committed May 16, 2014
2 parents 47ca100 + 5a4c558 commit 8babb77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
11 changes: 11 additions & 0 deletions docs/en/cookbook/dql-user-defined-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
$config = new \Doctrine\ORM\Configuration();
$config->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:

Expand Down
12 changes: 6 additions & 6 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ public function ensureProductionSettings()
*
* 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
*
Expand Down Expand Up @@ -459,8 +459,8 @@ public function setCustomStringFunctions(array $functions)
*
* 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
*
Expand Down Expand Up @@ -517,8 +517,8 @@ public function setCustomNumericFunctions(array $functions)
*
* 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
*
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Query/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3411,7 +3411,7 @@ public function CustomFunctionsReturningNumerics()

$function = is_string($functionClass)
? new $functionClass($functionName)
: $functionClass($functionName);
: call_user_func($functionClass, $functionName);

$function->parse($this);

Expand Down Expand Up @@ -3450,7 +3450,7 @@ public function CustomFunctionsReturningDatetime()

$function = is_string($functionClass)
? new $functionClass($functionName)
: $functionClass($functionName);
: call_user_func($functionClass, $functionName);

$function->parse($this);

Expand Down Expand Up @@ -3490,7 +3490,7 @@ public function CustomFunctionsReturningStrings()

$function = is_string($functionClass)
? new $functionClass($functionName)
: $functionClass($functionName);
: call_user_func($functionClass, $functionName);

$function->parse($this);

Expand Down

0 comments on commit 8babb77

Please sign in to comment.