doctrine/doctrine2 — pull request #991 by mnapoli (2014-03-27 17:09:17+00:00)
Title: Ability to define custom functions with callback instead of class name

Right now the only way to define custom DQL functions is by giving the class name, and Doctrine will create the class:

```php
$config->addCustomNumericFunction('FOO', 'My\Custom\DqlFunction');
```

This is very limiting when the custom functions has dependencies, for example it can't be created by a DI container.

The approach I have taken here is very simple: it allows to define a callback instead of the class name: the callback will be called and it should return the instance:

```php
$config->addCustomNumericFunction('FOO', function($funcName) {
return new My\Custom\DqlFunction($funcName);
});
```

On a side note, I think it would be great to generalize that approach because currently there are a lot of places where the same constraints apply.