8000 [FeatureFlag] Add ArgumentResolver by Jean-Beru · Pull Request #8 · Jean-Beru/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FeatureFlag] Add ArgumentResolver #8

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

Open
wants to merge 36 commits into
base: rfc/simple-feature-flag
Choose a base branch
from

Conversation

Jean-Beru
Copy link
Owner
Q A
Branch? 7.2
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

Adds a ArgumentResolverInterface to resolve feature's arguments.

@Jean-Beru Jean-Beru force-pushed the rfc/simple-feature-flag-argument-resolver branch 2 times, most recently from f3a25d2 to f64b650 Compare October 9, 2024 21:31
@Jean-Beru Jean-Beru force-pushed the rfc/simple-feature-flag-argument-resolver branch from f64b650 to 5e44fa4 Compare October 9, 2024 21:48
@@ -20,6 +20,7 @@ final class InMemoryProvider implements ProviderInterface
*/
public function __construct(
private readonly array $features,
private readonly ArgumentResolverInterface|null $argumentResolver = null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have a ArgumentResolverAwareChecker : allows to enable / disable this feature per project and becomes global to all providers. what about chain provider ? Shouldn't it be done recurisvely then ?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will an ArgumentResolver be used outside the InMemoryProvider? Argument resolving, and so TypeInfo usage, may not be necessary for some feature providers (ex: based on a database or a SaaS service).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some clearly it would'nt be useful. But having a way to enable it would be great eitehr through a tag (controller like) or though an interface or both.

$feature = $this->features[$featureName] ?? fn() => false;

return function() use ($feature): mixed {
$arguments = $this->argumentResolver?->getArguments($feature) ?? [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth to have a InMemoryCache for argument resolver ? In case of controller they are not called multiple times. But flags might be.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that is necessary since the feature's value is already cached by the FeatureChecker service.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if we move the argument resolver to checker it might be worth don't you think ? Or maybe I am missing somehting.

@@ -17,7 +17,8 @@
],
"require": {
"php": ">=8.2",
"psr/container": "^1.1|^2.0"
"psr/container": "^1.1|^2.0",
"symfony/type-info": "^7.2"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be optional IMO.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Jean-Beru pushed a commit that referenced this pull request Nov 4, 2024
…rsimpsons)

This PR was merged into the 5.4 branch.

Discussion
----------

[Yaml] 🐛 throw ParseException on invalid date

| Q             | A
| ------------- | ---
| Branch?       | 5.4 <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        | None <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT

(found in symfony-tools/docs-builder#179)

When parsing the following yaml:
```
date: 6418-75-51
```

`symfony/yaml` will throw an exception:
```
$ php main.php
PHP Fatal error:  Uncaught Exception: Failed to parse time string (6418-75-51) at position 6 (5): Unexpected character in /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php:714
Stack trace:
#0 /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php(714): DateTimeImmutable->__construct()
#1 /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php(312): Symfony\Component\Yaml\Inline::evaluateScalar()
#2 /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php(80): Symfony\Component\Yaml\Inline::parseScalar()
#3 /tmp/symfony-yaml/vendor/symfony/yaml/Parser.php(790): Symfony\Component\Yaml\Inline::parse()
#4 /tmp/symfony-yaml/vendor/symfony/yaml/Parser.php(341): Symfony\Component\Yaml\Parser->parseValue()
#5 /tmp/symfony-yaml/vendor/symfony/yaml/Parser.php(86): Symfony\Component\Yaml\Parser->doParse()
#6 /tmp/symfony-yaml/vendor/symfony/yaml/Yaml.php(77): Symfony\Component\Yaml\Parser->parse()
#7 /tmp/symfony-yaml/main.php(8): Symfony\Component\Yaml\Yaml::parse()
#8 {main}
  thrown in /tmp/symfony-yaml/vendor/symfony/yaml/Inline.php on line 714
```

This is because the "month" is invalid. Fixing the "month" will trigger about the same issue because the "day" would be invalid.

With the current change it will throw a `ParseException`.

Commits
-------

6d71a7e 🐛 throw ParseException on invalid date
@Jean-Beru Jean-Beru force-pushed the rfc/simple-feature-flag branch 2 times, most recently from 265286b to f81d729 Compare January 7, 2025 15:07
@Jean-Beru Jean-Beru force-pushed the rfc/simple-feature-flag branch from f81d729 to 47d16ba Compare March 17, 2025 16:22
@Jean-Beru Jean-Beru force-pushed the rfc/simple-feature-flag branch from 47d16ba to 2f490f8 Compare May 2, 2025 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0