-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass #34783
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
[DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass #34783
Conversation
src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php
Outdated
Show resolved
Hide resolved
There's something we do in Config: we replace env placeholders with credible values. The goal of the command is not to prove a theoretical point but to help spot errors quickly. We should skip instead. |
748d88e
to
28dc7ca
Compare
df891df
to
47e9a0f
Compare
src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php
Show resolved
Hide resolved
$value = $this->container->getParameter($match[1]); | ||
} elseif (\is_string($value)) { | ||
if ('%' === ($value[0] ?? '') && preg_match('/^%([^%]+)%$/', $value, $match)) { | ||
// Only array parameters are not inlined when dumped. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comments because those things are kind of hard to follow. We actually don't need to resolve the value here since we only care about the type.
} elseif ($envPlaceholderUniquePrefix && false !== strpos($value, 'env_')) { | ||
// If the value is an env placeholder that is either mixed with a string or with another env placeholder, then its resolved value will always be a string, so we don't need to resolve it. | ||
// We don't need to change the value because it is already a string. | ||
if ('' === preg_replace('/'.$envPlaceholderUniquePrefix.'_\w+_[a-f0-9]{32}/U', '', $value, -1, $c) && 1 === $c) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 cases here (with param: "%env(FOO)%"
:
- only 1 env placeholder (eg:
%param%
) -> we try to resolve it to get its type. - more than 1 chained env placeholder (eg:
%param%%param%
) -> it has to be a string - mixed env placeholder with a string (eg :
foo%param%
) -> it has to be a string
47e9a0f
to
e1df59a
Compare
e1df59a
to
c357485
Compare
src/Symfony/Component/DependencyInjection/Compiler/CheckTypeDeclarationsPass.php
Show resolved
Hide resolved
Thank you @fancyweb. |
…TypeDeclarationsPass (fancyweb) This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - A case we forgot to handle. Commits ------- c357485 [DependencyInjection] Handle env var placeholders in CheckTypeDeclarationsPass
A case we forgot to handle.