Skip to content

Commit 9d916da

Browse files
authored
Merge pull request #2584 from api-platform/revert-2569-messenger-per-operation
Revert "Allow per-operation messenger configuration"
2 parents 5701093 + 0db9525 commit 9d916da

File tree

5 files changed

+15
-65
lines changed

5 files changed

+15
-65
lines changed

src/Bridge/Symfony/Messenger/DataPersister.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
namespace ApiPlatform\Core\Bridge\Symfony\Messenger;
1515

16-
use ApiPlatform\Core\Api\OperationType;
17-
use ApiPlatform\Core\DataPersister\ContextAwareDataPersisterInterface;
16+
use ApiPlatform\Core\DataPersister\DataPersisterInterface;
1817
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
1918
use ApiPlatform\Core\Util\ClassInfoTrait;
2019
use Symfony\Component\Messenger\Envelope;
@@ -28,7 +27,7 @@
2827
*
2928
* @author Kévin Dunglas <[email protected]>
3029
*/
31-
final class DataPersister implements ContextAwareDataPersisterInterface
30+
final class DataPersister implements DataPersisterInterface
3231
{
3332
use ClassInfoTrait;
3433

@@ -44,20 +43,9 @@ public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFa
4443
/**
4544
* {@inheritdoc}
4645
*/
47-
public function supports($data, array $context = []): bool
46+
public function supports($data): bool
4847
{
49-
$resourceMetadata = $this->resourceMetadataFactory->create($this->getObjectClass($data));
50-
if (null !== $operationName = $context['collection_operation_name'] ?? $context['item_operation_name'] ?? null) {
51-
return true === $resourceMetadata->getTypedOperationAttribute(
52-
$context['collection_operation_name'] ?? false ? OperationType::COLLECTION : OperationType::ITEM,
53-
$operationName,
54-
'messenger',
55-
false,
56-
true
57-
);
58-
}
59-
60-
return true === $resourceMetadata->getAttribute('messenger');
48+
return true === $this->resourceMetadataFactory->create($this->getObjectClass($data))->getAttribute('messenger');
6149
}
6250

6351
/**

src/DataPersister/ContextAwareDataPersisterInterface.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/EventListener/WriteListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function onKernelView(GetResponseForControllerResultEvent $event)
4949
}
5050

5151
$controllerResult = $event->getControllerResult();
52-
if (!$this->dataPersister->supports($controllerResult, $attributes)) {
52+
if (!$this->dataPersister->supports($controllerResult)) {
5353
return;
5454
}
5555

tests/Bridge/Symfony/Messenger/DataPersisterTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,4 @@ public function testHandle()
7272
$dataPersister = new DataPersister($this->prophesize(ResourceMetadataFactoryInterface::class)->reveal(), $messageBus->reveal());
7373
$this->assertSame('result', $dataPersister->persist($dummy));
7474
}
75-
76-
public function testSupportsPerOperation()
77-
{
78-
$resourceMetadata = (new ResourceMetadata())->withCollectionOperations(['operation' => ['messenger' => true]]);
79-
$metadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
80-
$metadataFactoryProphecy->create(Dummy::class)->willReturn($resourceMetadata);
81-
82-
$dataPersister = new DataPersister($metadataFactoryProphecy->reveal(), $this->prophesize(MessageBusInterface::class)->reveal());
83-
$this->assertTrue($dataPersister->supports(new Dummy(), ['collection_operation_name' => 'operation']));
84-
}
8575
}

tests/EventListener/WriteListenerTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\ConcreteDummy;
2222
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
2323
use PHPUnit\Framework\TestCase;
24-
use Prophecy\Argument;
2524
use Symfony\Component\HttpFoundation\Request;
2625
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
2726
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -37,7 +36,7 @@ public function testOnKernelViewWithControllerResultAndPersist()
3736
$dummy->setName('Dummyrino');
3837

3938
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
40-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->willReturn(true)->shouldBeCalled();
39+
$dataPersisterProphecy->supports($dummy)->willReturn(true)->shouldBeCalled();
4140
$dataPersisterProphecy->persist($dummy)->willReturn($dummy)->shouldBeCalled();
4241

4342
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
@@ -72,7 +71,7 @@ public function testOnKernelViewWithControllerResultAndPersistReturningVoid()
7271
$dummy->setName('Dummyrino');
7372

7473
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
75-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->willReturn(true)->shouldBeCalled();
74+
$dataPersisterProphecy->supports($dummy)->willReturn(true)->shouldBeCalled();
7675
$dataPersisterProphecy->persist($dummy)->shouldBeCalled();
7776

7877
$request = new Request([], [], ['_api_resource_class' => Dummy::class]);
@@ -105,7 +104,7 @@ public function testOnKernelViewWithControllerResultAndPersistWithImmutableResou
105104
$dummy2->setName('Dummyferoce');
106105

107106
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
108-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->willReturn(true)->shouldBeCalled();
107+
$dataPersisterProphecy->supports($dummy)->willReturn(true)->shouldBeCalled();
109108

110109
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
111110
$iriConverterProphecy->getIriFromItem($dummy)->willReturn('/dummy/1')->shouldBeCalled();
@@ -142,7 +141,7 @@ public function testOnKernelViewDoNotCallIriConverterWhenOutputClassDisabled()
142141
$dummy->setName('Dummyrino');
143142

144143
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
145-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->willReturn(true)->shouldBeCalled();
144+
$dataPersisterProphecy->supports($dummy)->willReturn(true)->shouldBeCalled();
146145

147146
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
148147
$iriConverterProphecy->getIriFromItem($dummy)->shouldNotBeCalled();
@@ -171,7 +170,7 @@ public function testOnKernelViewWithControllerResultAndRemove()
171170
$dummy->setName('Dummyrino');
172171

173172
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
174-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->willReturn(true)->shouldBeCalled();
173+
$dataPersisterProphecy->supports($dummy)->willReturn(true)->shouldBeCalled();
175174
$dataPersisterProphecy->remove($dummy)->shouldBeCalled();
176175

177176
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
@@ -196,7 +195,7 @@ public function testOnKernelViewWithSafeMethod()
196195
$dummy->setName('Dummyrino');
197196

198197
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
199-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->shouldNotBeCalled();
198+
$dataPersisterProphecy->supports($dummy)->shouldNotBeCalled();
200199
$dataPersisterProphecy->persist($dummy)->shouldNotBeCalled();
201200
$dataPersisterProphecy->remove($dummy)->shouldNotBeCalled();
202201

@@ -222,7 +221,7 @@ public function testOnKernelViewWithPersistFlagOff()
222221
$dummy->setName('Dummyrino');
223222

224223
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
225-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->shouldNotBeCalled();
224+
$dataPersisterProphecy->supports($dummy)->shouldNotBeCalled();
226225
$dataPersisterProphecy->persist($dummy)->shouldNotBeCalled();
227226
$dataPersisterProphecy->remove($dummy)->shouldNotBeCalled();
228227

@@ -248,7 +247,7 @@ public function testOnKernelViewWithNoResourceClass()
248247
$dummy->setName('Dummyrino');
249248

250249
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
251-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->shouldNotBeCalled();
250+
$dataPersisterProphecy->supports($dummy)->shouldNotBeCalled();
252251
$dataPersisterProphecy->persist($dummy)->shouldNotBeCalled();
253252
$dataPersisterProphecy->remove($dummy)->shouldNotBeCalled();
254253

@@ -273,7 +272,7 @@ public function testOnKernelViewWithParentResourceClass()
273272
$dummy = new ConcreteDummy();
274273

275274
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
276-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->willReturn(true)->shouldBeCalled();
275+
$dataPersisterProphecy->supports($dummy)->willReturn(true)->shouldBeCalled();
277276
$dataPersisterProphecy->persist($dummy)->willReturn($dummy)->shouldBeCalled();
278277

279278
$iriConverterProphecy = $this->prophesize(IriConverterInterface::class);
@@ -298,7 +297,7 @@ public function testOnKernelViewWithNoDataPersisterSupport()
298297
$dummy->setName('Dummyrino');
299298

300299
$dataPersisterProphecy = $this->prophesize(DataPersisterInterface::class);
301-
$dataPersisterProphecy->supports($dummy, Argument::type('array'))->willReturn(false)->shouldBeCalled();
300+
$dataPersisterProphecy->supports($dummy)->willReturn(false)->shouldBeCalled();
302301
$dataPersisterProphecy->persist($dummy)->shouldNotBeCalled();
303302
$dataPersisterProphecy->remove($dummy)->shouldNotBeCalled();
304303

0 commit comments

Comments
 (0)