Skip to content

Commit 3481e18

Browse files
committed
[Workflow] Removed the MetadataBag
1 parent d25e8da commit 3481e18

File tree

9 files changed

+35
-103
lines changed

9 files changed

+35
-103
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Bridge\Twig\Extension\WorkflowExtension;
1616
use Symfony\Component\Workflow\Definition;
1717
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
18-
use Symfony\Component\Workflow\Metadata\MetadataBag;
1918
use Symfony\Component\Workflow\Registry;
2019
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
2120
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
@@ -42,10 +41,10 @@ protected function setUp()
4241
$metadataStore = null;
4342
if (class_exists(InMemoryMetadataStore::class)) {
4443
$transitionsMetadata = new \SplObjectStorage();
45-
$transitionsMetadata->attach($this->t1, new MetadataBag(array('title' => 't1 title')));
44+
$transitionsMetadata->attach($this->t1, array('title' => 't1 title'));
4645
$metadataStore = new InMemoryMetadataStore(
47-
new MetadataBag(array('title' => 'workflow title')),
48-
array('orderer' => new MetadataBag(array('title' => 'ordered title'))),
46+
array('title' => 'workflow title'),
47+
array('orderer' => array('title' => 'ordered title')),
4948
$transitionsMetadata
5049
);
5150
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,12 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
469469
// Process Metadata (workflow + places (transition is done in the "create transition" block))
470470
$metadataStoreDefinition = new Definition(Workflow\Metadata\InMemoryMetadataStore::class, array(null, null, null));
471471
if ($workflow['metadata']) {
472-
$metadataStoreDefinition->replaceArgument(0, new Definition(Workflow\Metadata\MetadataBag::class, array($workflow['metadata'])));
472+
$metadataStoreDefinition->replaceArgument(0, $workflow['metadata']);
473473
}
474474
$placesMetadata = array();
475475
foreach ($workflow['places'] as $place) {
476476
if ($place['metadata']) {
477-
$placesMetadata[$place['name']] = new Definition(Workflow\Metadata\MetadataBag::class, array($place['metadata']));
477+
$placesMetadata[$place['name']] = $place['metadata'];
478478
}
479479
}
480480
if ($placesMetadata) {
@@ -491,7 +491,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
491491
if ($transition['metadata']) {
492492
$transitionsMetadataDefinition->addMethodCall('attach', array(
493493
$transitionDefinition,
494-
new Definition(Workflow\Metadata\MetadataBag::class, array($transition['metadata'])),
494+
$transition['metadata'],
495495
));
496496
}
497497
} elseif ('state_machine' === $type) {
@@ -502,7 +502,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
502502
if ($transition['metadata']) {
503503
$transitionsMetadataDefinition->addMethodCall('attach', array(
504504
$transitionDefinition,
505-
new Definition(Workflow\Metadata\MetadataBag::class, array($transition['metadata'])),
505+
$transition['metadata'],
506506
));
507507
}
508508
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,11 @@ public function testWorkflows()
239239
$this->assertSame(Workflow\Metadata\InMemoryMetadataStore::class, $metadataStoreDefinition->getClass());
240240

241241
$workflowMetadata = $metadataStoreDefinition->getArgument(0);
242-
$this->assertInstanceOf(Definition::class, $workflowMetadata);
243-
$this->assertSame(Workflow\Metadata\MetadataBag::class, $workflowMetadata->getClass());
244-
$this->assertSame(array('title' => 'workflow title'), $workflowMetadata->getArgument(0));
242+
$this->assertSame(array('title' => 'workflow title'), $workflowMetadata);
245243

246244
$placesMetadata = $metadataStoreDefinition->getArgument(1);
247245
$this->assertArrayHasKey('start', $placesMetadata);
248-
$this->assertInstanceOf(Definition::class, $placesMetadata['start']);
249-
$this->assertSame(Workflow\Metadata\MetadataBag::class, $placesMetadata['start']->getClass());
250-
$this->assertSame(array('title' => 'place start title'), $placesMetadata['start']->getArgument(0));
246+
$this->assertSame(array('title' => 'place start title'), $placesMetadata['start']);
251247

252248
$transitionsMetadata = $metadataStoreDefinition->getArgument(2);
253249
$this->assertSame(\SplObjectStorage::class, $transitionsMetadata->getClass());
@@ -258,9 +254,7 @@ public function testWorkflows()
258254
$this->assertInstanceOf(Definition::class, $params[0]);
259255
$this->assertSame(Workflow\Transition::class, $params[0]->getClass());
260256
$this->assertSame(array('submit', 'start', 'travis'), $params[0]->getArguments());
261-
$this->assertInstanceOf(Definition::class, $params[1]);
262-
$this->assertSame(Workflow\Metadata\MetadataBag::class, $params[1]->getClass());
263-
$this->assertSame(array('title' => 'transition submit title'), $params[1]->getArgument(0));
257+
$this->assertSame(array('title' => 'transition submit title'), $params[1]);
264258

265259
$serviceMarkingStoreWorkflowDefinition = $container->getDefinition('workflow.service_marking_store_workflow');
266260
/** @var Reference $markingStoreRef */

src/Symfony/Component/Workflow/Metadata/GetMetadataTrait.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ trait GetMetadataTrait
2222
public function getMetadata(string $key, $subject = null)
2323
{
2424
if (null === $subject) {
25-
return $this->getWorkflowMetadata()->get($key);
25+
return $this->getWorkflowMetadata()[$key] ?? null;
2626
}
2727

2828
if (\is_string($subject)) {
@@ -31,7 +31,7 @@ public function getMetadata(string $key, $subject = null)
3131
return null;
3232
}
3333

34-
return $metadataBag->get($key);
34+
return $metadataBag[$key] ?? null;
3535
}
3636

3737
if ($subject instanceof Transition) {
@@ -40,7 +40,7 @@ public function getMetadata(string $key, $subject = null)
4040
return null;
4141
}
4242

43-
return $metadataBag->get($key);
43+
return $metadataBag[$key] ?? null;
4444
}
4545

4646
throw new InvalidArgumentException(sprintf('Could not find a MetadataBag for the subject of type "%s".', is_object($subject) ? get_class($subject) : gettype($subject)));

src/Symfony/Component/Workflow/Metadata/InMemoryMetadataStore.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ final class InMemoryMetadataStore implements MetadataStoreInterface
2424
private $placesMetadata;
2525
private $transitionsMetadata;
2626

27-
public function __construct(MetadataBag $workflowMetadata = null, array $placesMetadata = null, \SplObjectStorage $transitionsMetadata = null)
27+
public function __construct($workflowMetadata = array(), array $placesMetadata = array(), \SplObjectStorage $transitionsMetadata = null)
2828
{
29-
$this->workflowMetadata = $workflowMetadata ?: new MetadataBag();
30-
$this->placesMetadata = $placesMetadata ?: array();
29+
$this->workflowMetadata = $workflowMetadata;
30+
$this->placesMetadata = $placesMetadata;
3131
$this->transitionsMetadata = $transitionsMetadata ?: new \SplObjectStorage();
3232
}
3333

34-
public function getWorkflowMetadata(): MetadataBag
34+
public function getWorkflowMetadata(): array
3535
{
3636
return $this->workflowMetadata;
3737
}
3838

39-
public function getPlaceMetadata(string $place): ?MetadataBag
39+
public function getPlaceMetadata(string $place): array
4040
{
41-
return $this->placesMetadata[$place] ?? null;
41+
return $this->placesMetadata[$place] ?? array();
4242
}
4343

44-
public function getTransitionMetadata(Transition $transition): ?MetadataBag
44+
public function getTransitionMetadata(Transition $transition): array
4545
{
46-
return $this->transitionsMetadata[$transition] ?? null;
46+
return $this->transitionsMetadata[$transition] ?? array();
4747
}
4848
}

src/Symfony/Component/Workflow/Metadata/MetadataBag.php

-37
This file was deleted.

src/Symfony/Component/Workflow/Metadata/MetadataStoreInterface.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
*/
2121
interface MetadataStoreInterface
2222
{
23-
public function getWorkflowMetadata(): MetadataBag;
23+
public function getWorkflowMetadata(): array;
2424

25-
public function getPlaceMetadata(string $place): ?MetadataBag;
25+
public function getPlaceMetadata(string $place): array;
2626

27-
public function getTransitionMetadata(Transition $transition): ?MetadataBag;
27+
public function getTransitionMetadata(Transition $transition): array;
2828

2929
/**
3030
* Returns the metadata for a specific subject.

src/Symfony/Component/Workflow/Tests/Metadata/InMemoryMetadataStoreTest.php

+11-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPUnit\Framework\TestCase;
66
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
7-
use Symfony\Component\Workflow\Metadata\MetadataBag;
87
use Symfony\Component\Workflow\Transition;
98

109
/**
@@ -17,54 +16,51 @@ class InMemoryMetadataStoreTest extends TestCase
1716

1817
protected function setUp()
1918
{
20-
$workflowMetadata = new MetadataBag(array(
19+
$workflowMetadata = array(
2120
'title' => 'workflow title',
22-
));
21+
);
2322
$placesMetadata = array(
24-
'place_a' => new MetadataBag(array(
23+
'place_a' => array(
2524
'title' => 'place_a title',
26-
)),
25+
),
2726
);
2827
$transitionsMetadata = new \SplObjectStorage();
2928
$this->transition = new Transition('transition_1', array(), array());
30-
$transitionsMetadata[$this->transition] = new MetadataBag(array(
29+
$transitionsMetadata[$this->transition] = array(
3130
'title' => 'transition_1 title',
32-
));
31+
);
3332

3433
$this->store = new InMemoryMetadataStore($workflowMetadata, $placesMetadata, $transitionsMetadata);
3534
}
3635

3736
public function testGetWorkflowMetadata()
3837
{
3938
$metadataBag = $this->store->getWorkflowMetadata();
40-
$this->assertInstanceOf(MetadataBag::class, $metadataBag);
41-
$this->assertSame('workflow title', $metadataBag->get('title'));
39+
$this->assertSame('workflow title', $metadataBag['title']);
4240
}
4341

4442
public function testGetUnexistingPlaceMetadata()
4543
{
4644
$metadataBag = $this->store->getPlaceMetadata('place_b');
47-
$this->assertNull($metadataBag);
45+
$this->assertSame(array(), $metadataBag);
4846
}
4947

5048
public function testGetExistingPlaceMetadata()
5149
{
5250
$metadataBag = $this->store->getPlaceMetadata('place_a');
53-
$this->assertInstanceOf(MetadataBag::class, $metadataBag);
54-
$this->assertSame('place_a title', $metadataBag->get('title'));
51+
$this->assertSame('place_a title', $metadataBag['title']);
5552
}
5653

5754
public function testGetUnexistingTransitionMetadata()
5855
{
5956
$metadataBag = $this->store->getTransitionMetadata(new Transition('transition_2', array(), array()));
60-
$this->assertNull($metadataBag);
57+
$this->assertSame(array(), $metadataBag);
6158
}
6259

6360
public function testGetExistingTransitionMetadata()
6461
{
6562
$metadataBag = $this->store->getTransitionMetadata($this->transition);
66-
$this->assertInstanceOf(MetadataBag::class, $metadataBag);
67-
$this->assertSame('transition_1 title', $metadataBag->get('title'));
63+
$this->assertSame('transition_1 title', $metadataBag['title']);
6864
}
6965

7066
public function testGetMetadata()

src/Symfony/Component/Workflow/Tests/Metadata/MetadataBagTest.php

-20
This file was deleted.

0 commit comments

Comments
 (0)