|
3 | 3 | namespace webignition\InternetMediaType\Parser; |
4 | 4 |
|
5 | 5 | use webignition\InternetMediaType\InternetMediaType; |
| 6 | +use webignition\InternetMediaType\Parameter\Parameter; |
6 | 7 | use webignition\InternetMediaType\Parameter\Parser\AttributeFixer; |
7 | 8 | use webignition\InternetMediaType\Parameter\Parser\AttributeParser; |
8 | 9 | use webignition\InternetMediaType\Parameter\Parser\AttributeParserException; |
@@ -35,7 +36,6 @@ public function __construct( |
35 | 36 | private AttributeFixer $attributeFixer, |
36 | 37 | ) { |
37 | 38 | $this->configuration = new Configuration(); |
38 | | - $this->parameterParser->setConfiguration($this->configuration); |
39 | 39 | } |
40 | 40 |
|
41 | 41 | public static function create(): Parser |
@@ -113,7 +113,6 @@ public function parse(string $internetMediaTypeString): ?InternetMediaTypeInterf |
113 | 113 | public function setConfiguration(Configuration $configuration): void |
114 | 114 | { |
115 | 115 | $this->configuration = $configuration; |
116 | | - $this->parameterParser->setConfiguration($configuration); |
117 | 116 | } |
118 | 117 |
|
119 | 118 | public function getConfiguration(): Configuration |
@@ -186,7 +185,11 @@ private function getParameters(array $parameterStrings): array |
186 | 185 | { |
187 | 186 | $parameters = []; |
188 | 187 | foreach ($parameterStrings as $parameterString) { |
189 | | - $parameters[] = $this->parseParameterString($parameterString); |
| 188 | + $parameter = $this->parseParameterString($parameterString); |
| 189 | + |
| 190 | + if ($parameter instanceof ParameterInterface) { |
| 191 | + $parameters[] = $parameter; |
| 192 | + } |
190 | 193 | } |
191 | 194 |
|
192 | 195 | return $parameters; |
@@ -224,11 +227,16 @@ private function parseSubtype(string $inputString): string |
224 | 227 | * @throws QuotedStringException |
225 | 228 | * @throws UnknownStateException |
226 | 229 | */ |
227 | | - private function parseParameterString(string $parameterString): ParameterInterface |
| 230 | + private function parseParameterString(string $parameterString): ?ParameterInterface |
228 | 231 | { |
229 | 232 | try { |
230 | 233 | return $this->parameterParser->parse($parameterString); |
231 | 234 | } catch (AttributeParserException $attributeParserException) { |
| 235 | + $shouldIgnoreInvalidAttributes = $this->getConfiguration()->ignoreInvalidAttributes(); |
| 236 | + if ($shouldIgnoreInvalidAttributes) { |
| 237 | + return null; |
| 238 | + } |
| 239 | + |
232 | 240 | $shouldAttemptToFixInvalidInternalCharacter = |
233 | 241 | $this->getConfiguration()->attemptToRecoverFromInvalidInternalCharacter() |
234 | 242 | && !$this->hasAttemptedToFixAttributeInvalidInternalCharacter; |
|
0 commit comments