Skip to content

Commit 47d16ba

Browse files
committed
review
1 parent 269906a commit 47d16ba

File tree

7 files changed

+51
-4
lines changed

7 files changed

+51
-4
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/FeatureFlagPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public function process(ContainerBuilder $container): void
4545
if (!$r->hasMethod($method)) {
4646
throw new \RuntimeException(\sprintf('Invalid feature method "%s": method "%s::%s()" does not exist.', $serviceId, $r->getName(), $method));
4747
}
48+
if (!$r->getMethod($method)->isPublic()) {
49+
throw new \RuntimeException(\sprintf('Invalid feature method "%s": method "%s::%s()" must be public.', $serviceId, $r->getName(), $method));
50+
}
4851

4952
$features[$featureName] = $container->setDefinition(
5053
'.feature_flag.feature',
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FeatureFlag;
13+
14+
use Symfony\Component\FeatureFlag\Attribute\AsFeature;
15+
16+
#[AsFeature(method: 'resolve')]
17+
class InvalidMethodVisibilityFeature
18+
{
19+
protected function resolve(): bool
20+
{
21+
return true;
22+
}
23+
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/FeatureFlagTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ public function testFeatureFlagAssertionsWithInvalidMethod()
5555
static::bootKernel(['test_case' => 'FeatureFlag', 'root_config' => 'config_with_invalid_method.yml']);
5656
}
5757

58+
public function testFeatureFlagAssertionsWithInvalidMethodVisibility()
59+
{
60+
$this->expectException(\RuntimeException::class);
61+
$this->expectExceptionMessage('Invalid feature method "Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FeatureFlag\InvalidMethodVisibilityFeature": method "Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FeatureFlag\InvalidMethodVisibilityFeature::resolve()" must be public.');
62+
63+
static::bootKernel(['test_case' => 'FeatureFlag', 'root_config' => 'config_with_invalid_method_visibility.yml']);
64+
}
65+
5866
public function testFeatureFlagAssertionsWithDifferentMethod()
5967
{
6068
$this->expectException(\LogicException::class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
imports:
2+
- { resource: ../config/default.yml }
3+
4+
framework:
5+
http_method_override: false
6+
feature_flag:
7+
enabled: true
8+
9+
services:
10+
Symfony\Bundle\FrameworkBundle\Tests\Fixtures\FeatureFlag\InvalidMethodVisibilityFeature:
11+
autoconfigure: true

src/Symfony/Component/FeatureFlag/Debug/TraceableFeatureChecker.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,17 @@ public function isEnabled(string $featureName): bool
4040

4141
public function getValue(string $featureName): mixed
4242
{
43+
$value = $this->decorated->getValue($featureName);
44+
4345
$this->resolvedValues[$featureName] ??= [
4446
'status' => 'resolved',
45-
'value' => $this->decorated->getValue($featureName),
47+
'value' => $value,
4648
'calls' => 0,
4749
];
4850

4951
++$this->resolvedValues[$featureName]['calls'];
5052

51-
return $this->decorated->getValue($featureName);
53+
return $value;
5254
}
5355

5456
/**

src/Symfony/Component/FeatureFlag/FeatureChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function isEnabled(string $featureName): bool
3232

3333
public function getValue(string $featureName): mixed
3434
{
35-
if (isset($this->cache[$featureName])) {
35+
if (array_key_exists($featureName, $this->cache)) {
3636
return $this->cache[$featureName];
3737
}
3838

src/Symfony/Component/FeatureFlag/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2024-present Fabien Potencier
1+
Copyright (c) 2025-present Fabien Potencier
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)