Skip to content

[Validator] Add callback option to the ExpressionSyntax constraint #53569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

symfonyaml
Copy link
Contributor

@symfonyaml symfonyaml commented Jan 17, 2024

Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
License MIT

ExpressionSyntax

I introduced the ability to use a callback to specify allowed variables (basically it will set the $allowedVariables value from this callback). Exactly like the Choice callback constraint.

This feature will be useful if an expression use dynamic variables (like in my personal project 😋).

Example

class MyEntity
{
    public static function getVars(): array
    {
        // some cool logic with allowed expression variables ... 
        return ['symfony', $this->getUsername()];
    }

    #[Assert\ExpressionSyntax(allowedVariablesCallback: 'getVars')]
    protected string $expression;
}

@symfonyaml symfonyaml force-pushed the validator-expression-syntax-callback branch from 2a339fd to 20b3379 Compare February 4, 2024 15:29
@symfonyaml symfonyaml requested a review from xabbuh February 4, 2024 15:33
@symfonyaml symfonyaml force-pushed the validator-expression-syntax-callback branch from 257a2b9 to e55a937 Compare March 4, 2024 11:51
@symfonyaml symfonyaml force-pushed the validator-expression-syntax-callback branch from e55a937 to 6f28102 Compare April 12, 2024 08:14
@symfonyaml symfonyaml force-pushed the validator-expression-syntax-callback branch from 6f28102 to fd3e5c7 Compare April 19, 2024 17:49
@symfonyaml symfonyaml force-pushed the validator-expression-syntax-callback branch from d8ed419 to 91202c4 Compare May 7, 2024 18:02
…ression-syntax-callback""

This reverts commit 91202c4.
@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 13, 2024
@symfonyaml
Copy link
Contributor Author

Closed. We can use the ExpressionSyntax::$service option instead.

@symfonyaml symfonyaml closed this Nov 9, 2024
@symfonyaml symfonyaml deleted the validator-expression-syntax-callback branch November 9, 2024 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants