-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Config] Do not generate unreachable configuration paths #58995
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
bobvandevijver
wants to merge
4
commits into
symfony:6.4
Choose a base branch
from
bobvandevijver:generated-config-docblock
base: 6.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ced71ca
fix: Do not generate unreachable configuration paths
bobvandevijver ca26014
fix: Fully define @template doc in generated configuration code
bobvandevijver 096a798
Add tests
bobvandevijver 098586c
Apply suggestions from code review
bobvandevijver 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
19 changes: 19 additions & 0 deletions
19
src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayValues.config.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,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use Symfony\Config\ArrayValuesConfig; | ||
|
||
return static function (ArrayValuesConfig $config) { | ||
$config->transports('foo')->dsn('bar'); | ||
$config->transports('bar', ['dsn' => 'foobar']); | ||
|
||
$config->errorPages()->withTrace(false); | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayValues.output.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,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
return [ | ||
'transports' => [ | ||
'foo' => [ | ||
'dsn' => 'bar', | ||
], | ||
'bar' => [ | ||
'dsn' => 'foobar', | ||
], | ||
], | ||
'error_pages' => [ | ||
'with_trace' => false, | ||
] | ||
]; |
42 changes: 42 additions & 0 deletions
42
src/Symfony/Component/Config/Tests/Builder/Fixtures/ArrayValues.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,42 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\Config\Tests\Builder\Fixtures; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
class ArrayValues implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$tb = new TreeBuilder('array_values'); | ||
$rootNode = $tb->getRootNode(); | ||
$rootNode | ||
->children() | ||
->arrayNode('transports') | ||
->normalizeKeys(false) | ||
->useAttributeAsKey('name') | ||
->arrayPrototype() | ||
->beforeNormalization() | ||
->ifString() | ||
->then(function (string $dsn) { | ||
return ['dsn' => $dsn]; | ||
}) | ||
->end() | ||
->fixXmlConfig('option') | ||
->children() | ||
->scalarNode('dsn')->end() | ||
->end() | ||
->end() | ||
->end() | ||
->arrayNode('error_pages') | ||
->canBeEnabled() | ||
->children() | ||
->booleanNode('with_trace')->end() | ||
->end() | ||
->end() | ||
->end(); | ||
|
||
return $tb; | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...Config/Tests/Builder/Fixtures/ArrayValues/Symfony/Config/ArrayValues/ErrorPagesConfig.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,75 @@ | ||
<?php | ||
|
||
namespace Symfony\Config\ArrayValues; | ||
|
||
use Symfony\Component\Config\Loader\ParamConfigurator; | ||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; | ||
|
||
/** | ||
* This class is automatically generated to help in creating a config. | ||
*/ | ||
class ErrorPagesConfig | ||
{ | ||
private $enabled; | ||
private $withTrace; | ||
private $_usedProperties = []; | ||
|
||
/** | ||
* @default false | ||
* @param ParamConfigurator|bool $value | ||
* @return $this | ||
*/ | ||
public function enabled($value): static | ||
{ | ||
$this->_usedProperties['enabled'] = true; | ||
$this->enabled = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @default null | ||
* @param ParamConfigurator|bool $value | ||
* @return $this | ||
*/ | ||
public function withTrace($value): static | ||
{ | ||
$this->_usedProperties['withTrace'] = true; | ||
$this->withTrace = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function __construct(array $value = []) | ||
{ | ||
if (array_key_exists('enabled', $value)) { | ||
$this->_usedProperties['enabled'] = true; | ||
$this->enabled = $value['enabled']; | ||
unset($value['enabled']); | ||
} | ||
|
||
if (array_key_exists('with_trace', $value)) { | ||
$this->_usedProperties['withTrace'] = true; | ||
$this->withTrace = $value['with_trace']; | ||
unset($value['with_trace']); | ||
} | ||
|
||
if ([] !== $value) { | ||
throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); | ||
} | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$output = []; | ||
if (isset($this->_usedProperties['enabled'])) { | ||
$output['enabled'] = $this->enabled; | ||
} | ||
if (isset($this->_usedProperties['withTrace'])) { | ||
$output['with_trace'] = $this->withTrace; | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...Config/Tests/Builder/Fixtures/ArrayValues/Symfony/Config/ArrayValues/TransportsConfig.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,52 @@ | ||
<?php | ||
|
||
namespace Symfony\Config\ArrayValues; | ||
|
||
use Symfony\Component\Config\Loader\ParamConfigurator; | ||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; | ||
|
||
/** | ||
* This class is automatically generated to help in creating a config. | ||
*/ | ||
class TransportsConfig | ||
{ | ||
private $dsn; | ||
private $_usedProperties = []; | ||
|
||
/** | ||
* @default null | ||
* @param ParamConfigurator|mixed $value | ||
* @return $this | ||
*/ | ||
public function dsn($value): static | ||
{ | ||
$this->_usedProperties['dsn'] = true; | ||
$this->dsn = $value; | ||
|
||
return $this; | ||
} | ||
|
||
public function __construct(array $value = []) | ||
{ | ||
if (array_key_exists('dsn', $value)) { | ||
$this->_usedProperties['dsn'] = true; | ||
$this->dsn = $value['dsn']; | ||
unset($value['dsn']); | ||
} | ||
|
||
if ([] !== $value) { | ||
bobvandevijver marked this conversation as resolved.
Show resolved
Hide resolved
|
||
throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value))); | ||
} | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$output = []; | ||
if (isset($this->_usedProperties['dsn'])) { | ||
$output['dsn'] = $this->dsn; | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.