DDC-3054: [GH-991] Ability to define custom functions with callback instead of class name #3792

Closed
opened 2026-01-22 14:28:05 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 27, 2014).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user @doctrinebot:

This issue is created automatically through a Github pull request on behalf of mnapoli:

Url: https://github.com/doctrine/doctrine2/pull/991

Message:

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

$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:

$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.

Originally created by @doctrinebot on GitHub (Mar 27, 2014). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user @doctrinebot: This issue is created automatically through a Github pull request on behalf of mnapoli: Url: https://github.com/doctrine/doctrine2/pull/991 Message: 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.
admin added the Bug label 2026-01-22 14:28:05 +01:00
admin closed this issue 2026-01-22 14:28:05 +01:00
Author
Owner

@doctrinebot commented on GitHub (May 16, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-991] was closed:
https://github.com/doctrine/doctrine2/pull/991

@doctrinebot commented on GitHub (May 16, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-991] was closed: https://github.com/doctrine/doctrine2/pull/991
Author
Owner

@doctrinebot commented on GitHub (May 16, 2014):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (May 16, 2014): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3792