Skip to content

Commit 0154fbf

Browse files
authored
fix(elasticsearch): wrong namespace for stateOptions (#6260)
1 parent e3d26c9 commit 0154fbf

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/Metadata/Extractor/XmlResourceExtractor.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
namespace ApiPlatform\Metadata\Extractor;
1515

16+
use ApiPlatform\Elasticsearch\State\Options;
1617
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
1718
use ApiPlatform\Metadata\GetCollection;
1819
use ApiPlatform\Metadata\Post;
19-
use ApiPlatform\Metadata\Tests\Fixtures\StateOptions;
2020
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
2121
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
2222
use ApiPlatform\OpenApi\Model\Parameter;
@@ -451,10 +451,12 @@ private function buildStateOptions(\SimpleXMLElement $resource): ?OptionsInterfa
451451
}
452452
$elasticsearchOptions = $stateOptions->elasticsearchOptions ?? null;
453453
if ($elasticsearchOptions) {
454-
return new StateOptions(
455-
isset($elasticsearchOptions['index']) ? (string) $elasticsearchOptions['index'] : null,
456-
isset($elasticsearchOptions['type']) ? (string) $elasticsearchOptions['type'] : null,
457-
);
454+
if (class_exists(Options::class)) {
455+
return new Options(
456+
isset($elasticsearchOptions['index']) ? (string) $elasticsearchOptions['index'] : null,
457+
isset($elasticsearchOptions['type']) ? (string) $elasticsearchOptions['type'] : null,
458+
);
459+
}
458460
}
459461

460462
return null;

src/Metadata/Extractor/YamlResourceExtractor.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
namespace ApiPlatform\Metadata\Extractor;
1515

16+
use ApiPlatform\Elasticsearch\State\Options;
1617
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
1718
use ApiPlatform\Metadata\GetCollection;
1819
use ApiPlatform\Metadata\Post;
19-
use ApiPlatform\Metadata\Tests\Fixtures\StateOptions;
2020
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
2121
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
2222
use ApiPlatform\OpenApi\Model\Parameter;
@@ -410,7 +410,9 @@ private function buildStateOptions(array $resource): ?OptionsInterface
410410
$configuration = reset($stateOptions);
411411
switch (key($stateOptions)) {
412412
case 'elasticsearchOptions':
413-
return new StateOptions($configuration['index'] ?? null, $configuration['type'] ?? null);
413+
if (class_exists(Options::class)) {
414+
return new Options($configuration['index'] ?? null, $configuration['type'] ?? null);
415+
}
414416
}
415417

416418
return null;

src/Metadata/Tests/Extractor/ResourceMetadataCompatibilityTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@
3636
use ApiPlatform\Metadata\Tests\Extractor\Adapter\XmlResourceAdapter;
3737
use ApiPlatform\Metadata\Tests\Extractor\Adapter\YamlResourceAdapter;
3838
use ApiPlatform\Metadata\Tests\Fixtures\ApiResource\Comment;
39-
use ApiPlatform\Metadata\Tests\Fixtures\StateOptions;
4039
use ApiPlatform\Metadata\Util\CamelCaseToSnakeCaseNameConverter;
4140
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
4241
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
4342
use ApiPlatform\OpenApi\Model\RequestBody;
44-
use ApiPlatform\State\OptionsInterface;
4543
use PHPUnit\Framework\AssertionFailedError;
4644
use PHPUnit\Framework\TestCase;
4745
use Symfony\Component\WebLink\Link;
@@ -720,7 +718,7 @@ private function withGraphQlOperations(array $values, ?array $fixtures): array
720718
return $operations;
721719
}
722720

723-
private function withStateOptions(array $values): ?OptionsInterface
721+
private function withStateOptions(array $values)
724722
{
725723
if (!$values) {
726724
return null;
@@ -733,7 +731,7 @@ private function withStateOptions(array $values): ?OptionsInterface
733731
$configuration = reset($values);
734732
switch (key($values)) {
735733
case 'elasticsearchOptions':
736-
return new StateOptions($configuration['index'] ?? null, $configuration['type'] ?? null);
734+
return null;
737735
}
738736

739737
throw new \LogicException(sprintf('Unsupported "%s" state options.', key($values)));

0 commit comments

Comments
 (0)