-
Notifications
You must be signed in to change notification settings - Fork 9
Fix: Resolve env preprocessors for LateBoundDsnParameter #74
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
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d8b1159
Fix: Resolve env preprocessors for LateBoundDsnParameter
RikudouSage 3af9783
Add PR tests
RikudouSage 92ad6da
Fix composer.json update
RikudouSage fdb3def
Allow older version of phpunit
RikudouSage 3798a0c
Allow older symfony/yaml
RikudouSage b25e2c7
Allow older phpunit
RikudouSage 196caf1
Use older phpunit schema
RikudouSage 3edf321
Use phpunit bridge
RikudouSage ea87008
Require older phpunit
RikudouSage 7d60e90
Allow older version of php cs fixer
RikudouSage a33d5bd
Fix data provider
RikudouSage bd19db4
Use old syntax for functions
RikudouSage a979fe4
Disable deprecation failure
RikudouSage 118f58c
Switch back to raw phpunit
RikudouSage cf7ad23
Remove mixed type
RikudouSage f233bc0
Set reflection accessible
RikudouSage 6d67843
Only use shuffle on newer versions
RikudouSage 9327e91
Move shuffle to 8.1
RikudouSage 51d73b9
Move defined to 8.1
RikudouSage e273a28
Make reflection method accessible
RikudouSage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
/.idea | ||
/vendor | ||
/composer.lock | ||
/var | ||
|
||
/.php-cs-fixer.php | ||
/.php-cs-fixer.cache | ||
|
||
.phpunit.cache | ||
.phpunit.result.cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheResultFile=".phpunit.cache/test-results" | ||
executionOrder="depends,defects" | ||
beStrictAboutCoversAnnotation="true" | ||
beStrictAboutOutputDuringTests="true" | ||
beStrictAboutTodoAnnotatedTests="true" | ||
failOnRisky="true" | ||
failOnWarning="true" | ||
verbose="true"> | ||
<testsuites> | ||
<testsuite name="default"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<coverage cacheDirectory=".phpunit.cache/code-coverage" | ||
processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
|
||
<php> | ||
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[total]=1000"/> | ||
</php> | ||
</phpunit> |
28 changes: 28 additions & 0 deletions
28
src/DependencyInjection/Compiler/ProcessLateBoundParameters.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Unleash\Client\Bundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Unleash\Client\Bundle\DependencyInjection\Dsn\LateBoundDsnParameter; | ||
|
||
final class ProcessLateBoundParameters implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
$processors = array_map( | ||
fn (string $serviceName) => new Reference($serviceName), | ||
array_keys($container->findTaggedServiceIds('container.env_var_processor')), | ||
); | ||
|
||
foreach ($container->getDefinitions() as $definition) { | ||
if ($definition->getClass() !== LateBoundDsnParameter::class) { | ||
continue; | ||
} | ||
$definition->setArgument('$preprocessors', $processors); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Unleash\Client\Bundle\Exception; | ||
|
||
use Symfony\Component\Config\Definition\Exception\Exception; | ||
|
||
final class UnknownEnvPreprocessorException extends Exception | ||
{ | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Looking at this implementation and the tests required, it feels to me this is the wrong direction to take because it's duplicating what Symfony is already doing internally? Otherwise every single project allowing env processors in their DSN (like the linked Elastica bundle) would need to implement the same type of processing, but they don't.
Symfony already supports env var placeholders so this should be doable without implementing it yourself.
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.
I've found no documentation on how to do that. Of course we welcome a better implementation, I'm fine with scraping this code if something better comes along.
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.
There's
\Symfony\Component\DependencyInjection\ContainerBuilder::resolveEnvPlaceholders
, but there's also\Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass
which, from my understanding, should do it for you.There's also
\Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationContainerBuilder::resolveEnvPlaceholders
which I'm not sure is for. 🤔I've asked on Symfony Slack, maybe somebody will have a better idea how exactly this works.
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.
@RikudouSage here's a comment by @stof who is a Symfony core team member on the topic:
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.
@RikudouSage further discussion
@dkarlovi:
@stof:
So, if the DSN is injected into the client as is and then the client interprets then instead of the cotainer extension, it should just work without any further intervention.
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.
Nice, thanks for the info. I'll have to think how to incorporate the new informations into the existing code, so it may turn out the current code will be merged either way, but either way I'll keep that in mind for when the code will be rewritten.
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.
@RikudouSage I think the solution is to not parse the DSN into individual components while building the container but instead pass the configuration as is into a client factory.
Again @stof:
https://github.com/doctrine/DoctrineBundle/blob/2.12.x/src/ConnectionFactory.php