Skip to content

Commit d8ac787

Browse files
minor #61649 [DependencyInjection][Validator] Remove needless code (nicolas-grekas)
This PR was merged into the 7.4 branch. Discussion ---------- [DependencyInjection][Validator] Remove needless code | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT I added the attribute in the validator component in 0197b50#diff-eadef5e494fbfb85346e70992f4b18994df0b999b7d336c9cece5ab9e9a4a18aR30 But I didn't realize this was required because of falsy logic in AttributeAutoconfigurationPass, which we can remove. It's the engine's job to validate attribute's targets, not ours. Commits ------- 70a5874 [DependencyInjection][Validator] Remove needless code
2 parents 2c1294b + 70a5874 commit d8ac787

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

src/Symfony/Component/DependencyInjection/Compiler/AttributeAutoconfigurationPass.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,10 @@ public function process(ContainerBuilder $container): void
5656
throw new LogicException(\sprintf('Argument "$%s" of attribute autoconfigurator should have a type, use one or more of "\ReflectionClass|\ReflectionMethod|\ReflectionProperty|\ReflectionParameter|\Reflector" in "%s" on line "%d".', $reflectorParameter->getName(), $callableReflector->getFileName(), $callableReflector->getStartLine()));
5757
}
5858

59-
try {
60-
$attributeReflector = new \ReflectionClass($attributeName);
61-
} catch (\ReflectionException) {
62-
continue;
63-
}
64-
65-
$targets = $attributeReflector->getAttributes(\Attribute::class)[0] ?? 0;
66-
$targets = $targets ? $targets->getArguments()[0] ?? -1 : 0;
67-
68-
foreach (['class', 'method', 'property', 'parameter'] as $symbol) {
69-
if (['Reflector'] !== $types) {
70-
if (!\in_array('Reflection'.ucfirst($symbol), $types, true)) {
71-
continue;
72-
}
73-
if (!($targets & \constant('Attribute::TARGET_'.strtoupper($symbol)))) {
74-
throw new LogicException(\sprintf('Invalid type "Reflection%s" on argument "$%s": attribute "%s" cannot target a '.$symbol.' in "%s" on line "%d".', ucfirst($symbol), $reflectorParameter->getName(), $attributeName, $callableReflector->getFileName(), $callableReflector->getStartLine()));
75-
}
59+
foreach (['Class', 'Method', 'Property', 'Parameter'] as $symbol) {
60+
if (['Reflector'] === $types || \in_array('Reflection'.$symbol, $types, true)) {
61+
$this->{lcfirst($symbol).'AttributeConfigurators'}[$attributeName][] = $callable;
7662
}
77-
$this->{$symbol.'AttributeConfigurators'}[$attributeName][] = $callable;
7863
}
7964
}
8065
}

src/Symfony/Component/Validator/Constraint.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
*
2828
* @author Bernhard Schussek <bschussek@gmail.com>
2929
*/
30-
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
3130
abstract class Constraint
3231
{
3332
/**

0 commit comments

Comments
 (0)