Skip to content

[FeatureFlags] Propose a new component #51649

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 25 commits into
base: 7.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
129043f
[FeatureToggle] Import component from private sources
Neirda24 Jul 28, 2023
48819ec
[UPDATE] Fix twig function must be snake_case + gitattributes for bundle
Neirda24 Jul 30, 2023
2f875ea
cleanup before RFC (#1)
Jean-Beru Sep 7, 2023
f2cc75b
[UPDATE] Removed the Random Strategy & Provider
Neirda24 Sep 7, 2023
13d6176
[UPDATE] According to comments
Neirda24 Sep 13, 2023
1d4fb6c
[FabBot] Apply some patches
Neirda24 Sep 13, 2023
a8a2536
[UPDATE] Remove Outer*Interface's
Neirda24 Sep 21, 2023
844ae65
[UPDATE] Use Traversable instead of ArrayIterator
Neirda24 Sep 21, 2023
0473edc
[UPDATE] Remove forgottent Outer*Interface's
Neirda24 Sep 21, 2023
ba54221
[UPDATE] Add StrategyInterface on previous Outer*Strategy's
Neirda24 Sep 21, 2023
4f03511
[FEATURE] Add header, query strategies through request stack and make…
Neirda24 Sep 21, 2023
416e91d
[UPDATE] Add UnanimousStrategy
Neirda24 Sep 21, 2023
17fae0a
[UPDATE] Prefixed some return phpdoc tag with phpstan-
Neirda24 Sep 21, 2023
ad36be4
[UPDATE] Rename to
Neirda24 Sep 21, 2023
858f66d
[UPDATE] Fix phpunit covers annotation
Neirda24 Sep 21, 2023
6a356aa
[UPDATE][fabbot] Coding standard
Neirda24 Sep 22, 2023
cec1e92
[UPDATE][fabbot] usage of void in tests
Neirda24 Sep 22, 2023
7618497
[UPDATE] Improve performance on FeatureCollection to stop at first found
Neirda24 Sep 22, 2023
0ff46e4
[Update] Move Debug files
Jean-Beru Sep 25, 2023
19b5c5f
Rework of providers
Neirda24 Sep 29, 2023
5be52b0
[UPDATE] Fix coding standards according to fabbot
Neirda24 Sep 29, 2023
63f256f
rename to FeatureFlags (#6)
Jean-Beru Sep 29, 2023
1673877
Feature/add debug command
Neirda24 Oct 5, 2023
00bed51
[UPDATE] Add coding standards
Neirda24 Oct 5, 2023
c4842ba
move to FrameworkBundle (#9)
Jean-Beru Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[UPDATE] Rename to
  • Loading branch information
Neirda24 authored and Jean-Beru committed Oct 16, 2023
commit ad36be4d41e1344781cf50a55c2536bc316858a8
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->always()
->then(static function (array $strategy): array {
$defaultWith = match ($strategy['type']) {
'date' => ['from' => null, 'until' => null, 'includeFrom' => false, 'includeUntil' => false],
'date' => ['since' => null, 'until' => null, 'includeSince' => false, 'includeUntil' => false],
'not' => ['strategy' => null],
'env', 'request_header', 'request_query', 'request_attribute' => ['name' => null],
'priority', 'affirmative', 'unanimous' => ['strategies' => null],
Expand All @@ -86,8 +86,8 @@ public function getConfigTreeBuilder(): TreeBuilder
/** @var ConfigurationStrategy $strategy */
$validator = match ($strategy['type']) {
'date' => static function (array $with): void {
if ('' === trim((string) $with['from'].(string) $with['until'])) {
throw new \InvalidArgumentException('Either "from" or "until" must be provided.');
if ('' === trim((string) $with['since'].(string) $with['until'])) {
throw new \InvalidArgumentException('Either "since" or "until" must be provided.');
}
},
'not' => static function (array $with): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ private function generateStrategy(string $type, array $with): Definition

return match ($type) {
'date' => $definition->setArguments([
'$from' => new Definition(\DateTimeImmutable::class, [$with['from']]),
'$since' => new Definition(\DateTimeImmutable::class, [$with['since']]),
'$until' => new Definition(\DateTimeImmutable::class, [$with['until']]),
'$includeFrom' => $with['includeFrom'],
'$includeSince' => $with['includeSince'],
'$includeUntil' => $with['includeUntil'],
]),
'env' => $definition->setArguments(['$envName' => $with['name']]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
'$envName' => abstract_arg('Defined in FeatureToggleExtension'),
]);
$services->set($prefix.'date', DateStrategy::class)->abstract()->args([
'$from' => abstract_arg('Defined in FeatureToggleExtension'),
'$since' => abstract_arg('Defined in FeatureToggleExtension'),
'$until' => abstract_arg('Defined in FeatureToggleExtension'),
'$includeFrom' => abstract_arg('Defined in FeatureToggleExtension'),
'$includeSince' => abstract_arg('Defined in FeatureToggleExtension'),
'$includeUntil' => abstract_arg('Defined in FeatureToggleExtension'),
'$clock' => service('clock')->nullOnInvalid(),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getConfig(): array
[
'name' => 'date.feature-strategy',
'type' => 'date',
'with' => ['from' => '-2 days'],
'with' => ['since' => '-2 days'],
],
[
'name' => 'env.feature-strategy',
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/FeatureToggle/Strategy/DateStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ final class DateStrategy implements StrategyInterface
{
public function __construct(
private readonly ClockInterface $clock,
private readonly \DateTimeImmutable|null $from = null,
private readonly \DateTimeImmutable|null $since = null,
private readonly \DateTimeImmutable|null $until = null,
private readonly bool $includeFrom = true,
private readonly bool $includeSince = true,
private readonly bool $includeUntil = true,
) {
if (null === $this->from && null === $this->until) {
if (null === $this->since && null === $this->until) {
throw new \InvalidArgumentException('Either from or until must be provided.');
}
}
Expand All @@ -32,12 +32,12 @@ public function compute(): StrategyResult
{
$now = $this->clock->now();

if (null !== $this->from) {
if ($this->includeFrom && $this->from > $now) {
if (null !== $this->since) {
if ($this->includeSince && $this->since > $now) {
return StrategyResult::Deny;
}

if (!$this->includeFrom && $this->from >= $now) {
if (!$this->includeSince && $this->since >= $now) {
return StrategyResult::Deny;
}
}
Expand Down