Skip to content

Commit 54cd159

Browse files
committed
fixes for php 7
1 parent 32cffa6 commit 54cd159

File tree

8 files changed

+110
-57
lines changed

8 files changed

+110
-57
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
env:
88
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99
COVERAGE: '0'
10+
SYMFONY_DEPRECATIONS_HELPER: 'disabled=1'
1011

1112
jobs:
1213
php-cs-fixer:
@@ -134,10 +135,6 @@ jobs:
134135
composer remove --dev --no-interaction --no-progress --no-update --ansi \
135136
doctrine/mongodb-odm \
136137
doctrine/mongodb-odm-bundle \
137-
- name: Set Composer platform config
138-
if: (startsWith(matrix.php, '8.0'))
139-
run: |
140-
composer config platform.php 7.4.99
141138
- name: Update project dependencies
142139
run: composer update --no-interaction --no-progress --ansi
143140
- name: Require Symfony components
@@ -146,11 +143,7 @@ jobs:
146143
- name: Install PHPUnit
147144
run: vendor/bin/simple-phpunit --version
148145
- name: Clear test app cache
149-
if: (!startsWith(matrix.php, '8.0'))
150146
run: tests/Fixtures/app/console cache:clear --ansi
151-
- name: Clear test app cache (php 8.0)
152-
if: (startsWith(matrix.php, '8.0'))
153-
run: rm -Rf tests/Fixtures/app/var/cache/*
154147
- name: Run PHPUnit tests
155148
run: |
156149
mkdir -p build/logs/phpunit

src/Api/IdentifiersExtractor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public function getIdentifiersFromItem($item, string $operationName = null, arra
6262
throw new RuntimeException('No identifier value found, did you forgot to persist the entity?');
6363
}
6464

65-
if (is_scalar($identifierValue) || $identifierValue instanceof \Stringable) {
65+
// TODO: php 8 remove method_exists
66+
if (is_scalar($identifierValue) || method_exists($identifierValue, '__toString') || $identifierValue instanceof \Stringable) {
6667
$identifiers[$parameterName] = (string) $identifierValue;
6768
continue;
6869
}
@@ -76,7 +77,7 @@ public function getIdentifiersFromItem($item, string $operationName = null, arra
7677
if (1 === \count($relatedIdentifiers)) {
7778
$identifierValue = $this->resolveIdentifierValue($identifierValue, $relatedResourceClass, current($relatedIdentifiers)[1]);
7879

79-
if (is_scalar($identifierValue) || $identifierValue instanceof \Stringable) {
80+
if (is_scalar($identifierValue) || method_exists($identifierValue, '__toString') || $identifierValue instanceof \Stringable) {
8081
$identifiers[$parameterName] = (string) $identifierValue;
8182
continue;
8283
}

src/Core/Bridge/Doctrine/EventListener/PublishMercureUpdatesListener.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use ApiPlatform\Core\Exception\InvalidArgumentException;
2121
use ApiPlatform\Core\Exception\RuntimeException;
2222
use ApiPlatform\Core\Util\ResourceClassInfoTrait;
23+
use ApiPlatform\Exception\OperationNotFoundException;
2324
use ApiPlatform\GraphQl\Subscription\MercureSubscriptionIriGeneratorInterface as GraphQlMercureSubscriptionIriGeneratorInterface;
2425
use ApiPlatform\GraphQl\Subscription\SubscriptionManagerInterface as GraphQlSubscriptionManagerInterface;
2526
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
@@ -72,7 +73,7 @@ final class PublishMercureUpdatesListener
7273
* @param array<string, string[]|string> $formats
7374
* @param HubRegistry|callable $hubRegistry
7475
*/
75-
public function __construct(ResourceClassResolverInterface $resourceClassResolver, IriConverterInterface $iriConverter, $resourceMetadataFactory, SerializerInterface $serializer, array $formats, MessageBusInterface $messageBus = null, $hubRegistry = null, ?GraphQlSubscriptionManagerInterface $graphQlSubscriptionManager = null, ?GraphQlMercureSubscriptionIriGeneratorInterface $graphQlMercureSubscriptionIriGenerator = null, ExpressionLanguage $expressionLanguage = null)
76+
public function __construct(ResourceClassResolverInterface $resourceClassResolver, IriConverterInterface $iriConverter, ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, SerializerInterface $serializer, array $formats, MessageBusInterface $messageBus = null, $hubRegistry = null, ?GraphQlSubscriptionManagerInterface $graphQlSubscriptionManager = null, ?GraphQlMercureSubscriptionIriGeneratorInterface $graphQlMercureSubscriptionIriGenerator = null, ExpressionLanguage $expressionLanguage = null)
7677
{
7778
if (null === $messageBus && null === $hubRegistry) {
7879
throw new InvalidArgumentException('A message bus or a hub registry must be provided.');
@@ -172,7 +173,11 @@ private function storeObjectToPublish($object, string $property): void
172173
return;
173174
}
174175

175-
$options = $this->resourceMetadataFactory->create($resourceClass)->getAttribute('mercure', false);
176+
try {
177+
$options = $this->resourceMetadataFactory->create($resourceClass)->getOperation()->getMercure() ?? false;
178+
} catch (OperationNotFoundException $e) {
179+
return;
180+
}
176181

177182
if (\is_string($options)) {
178183
if (null === $this->expressionLanguage) {
@@ -264,12 +269,7 @@ private function publishUpdate($object, array $options, string $type): void
264269
$data = json_encode(['@id' => $object->id]);
265270
} else {
266271
$resourceClass = $this->getObjectClass($object);
267-
if ($this->resourceMetadataFactory instanceof ResourceMetadataCollectionFactoryInterface) {
268-
$context = $options['normalization_context'] ?? $this->resourceMetadataFactory->create($resourceClass)->getOperation()->getNormalizationContext();
269-
} else {
270-
// TODO: remove in 3.0
271-
$context = $options['normalization_context'] ?? $this->resourceMetadataFactory->create($resourceClass)->getAttribute('normalization_context', []);
272-
}
272+
$context = $options['normalization_context'] ?? $this->resourceMetadataFactory->create($resourceClass)->getOperation()->getNormalizationContext();
273273

274274
$iri = $options['topics'] ?? $this->iriConverter->getIriFromItem($object, null, UrlGeneratorInterface::ABS_URL);
275275
$data = $options['data'] ?? $this->serializer->serialize($object, key($this->formats), $context);

src/Core/Bridge/Symfony/Bundle/Resources/config/doctrine_orm_mercure_publisher.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<service id="api_platform.doctrine.orm.listener.mercure.publish" class="ApiPlatform\Core\Bridge\Doctrine\EventListener\PublishMercureUpdatesListener">
1212
<argument type="service" id="api_platform.resource_class_resolver" />
1313
<argument type="service" id="api_platform.iri_converter" />
14-
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
14+
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory" />
1515
<argument type="service" id="api_platform.serializer" />
1616
<argument>%api_platform.formats%</argument>
1717
<argument type="service" id="messenger.default_bus" on-invalid="ignore" />

src/Core/JsonLd/Serializer/ItemNormalizer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ public function normalize($object, $format = null, array $context = [])
8484
$context = $this->initContext($resourceClass, $context);
8585
$metadata = $this->addJsonLdContext($this->contextBuilder, $resourceClass, $context);
8686

87-
if (isset($context['operation'])) {
88-
if ($previousResourceClass !== $resourceClass) {
89-
unset($context['operation'], $context['operation_name']);
90-
}
87+
if (isset($context['operation']) && $previousResourceClass !== $resourceClass) {
88+
unset($context['operation'], $context['operation_name']);
9189
}
9290

9391
if ($this->iriConverter instanceof IriConverterInterface) {

0 commit comments

Comments
 (0)