-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Using expressions with container throws exception #11995
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
Comments
As a workaround, I went without the check and just parameter('param'), doing the check somewhere else. |
@Stelian You could do this in the Bundle (Dependency Injection) Extension of your bundle. |
@hacfi, totally true, can even be solved in the a compiler pass, but it's pretty much a 1 to 1 use case as described in the docs here: http://symfony.com/doc/current/book/service_container.html#using-the-expression-language. This is pretty much the reason for opening the issue. |
@Stelian Sorry..wasn’t aware of that as I haven’t spent much time using the Expression Language. |
Actually, I'm not sure if this ever worked. Looks like it has been broken before the ExpressionLanguage component was merged (when |
What you can do in a PR for: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/ExpressionLanguage.php // add this code in the registerFunctions()
$this->register('has_parameter', function ($arg) {
return sprintf('$this->hasParameter(%s)', $arg);
}, function (array $variables, $value) {
return $variables['container']->hasParameter($value);
}); I'm not sure if this would be desired, but it's an option. If you make a PR with this code, you should update the docs too. This would allow:
|
#12030 should fix the problem. Can you confirm? |
@fabpot, yes it works with your commit, thank you. |
…ontainer" variable (fabpot) This PR was squashed before being merged into the 2.4 branch (closes #12030). Discussion ---------- Fix expression language in the container when using the "container" variable | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11995 | License | MIT | Doc PR | n/a See #11995 for the description of the problem. Commits ------- 2b2f0df Fix expression language in the container when using the "container" variable
gives an Undefined variable: container in the appDevDebugProjectContainer.php. The generated code for that error is
The text was updated successfully, but these errors were encountered: