Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -588,22 +588,18 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
->then($workflowNormalizeArcs = static function ($arcs) {
// Fix XML parsing, when only one arc is defined
if (\array_key_exists('value', $arcs) && \array_key_exists('weight', $arcs)) {
return [[
$arcs = [[
'place' => $arcs['value'],
'weight' => $arcs['weight'],
]];
} elseif (\array_key_exists('place', $arcs)) {
$arcs = [$arcs];
}

$normalizedArcs = [];
foreach ($arcs as $arc) {
if ($arc instanceof \BackedEnum) {
$arc = $arc->value;
}
if (\is_string($arc)) {
$arc = [
'place' => $arc,
'weight' => 1,
];
if (\is_string($arc) || $arc instanceof \BackedEnum) {
$arc = ['place' => $arc];
} elseif (!\is_array($arc)) {
throw new InvalidConfigurationException('The "from" arcs must be a list of strings or arrays in workflow configuration.');
} elseif (\array_key_exists('value', $arc) && \array_key_exists('weight', $arc)) {
Expand All @@ -614,6 +610,10 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
];
}

if (($arc['place'] ?? null) instanceof \BackedEnum) {
$arc['place'] = $arc['place']->value;
}

$normalizedArcs[] = $arc;
}

Expand All @@ -628,7 +628,8 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
->cannotBeEmpty()
->end()
->integerNode('weight')
->isRequired()
->defaultValue(1)
->min(1)
->end()
->end()
->end()
Expand All @@ -648,7 +649,8 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
->cannotBeEmpty()
->end()
->integerNode('weight')
->isRequired()
->defaultValue(1)
->min(1)
->end()
->end()
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Configuration;
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Fixtures\Workflow\Places;
use Symfony\Bundle\FullStack;
use Symfony\Component\AssetMapper\Compressor\CompressorInterface;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
Expand Down Expand Up @@ -696,6 +697,48 @@ public function testSerializerJsonDetailedErrorMessagesNotSetByDefaultWithDebugD
$this->assertSame([], $config['serializer']['default_context'] ?? []);
}

public function testWorkflowEnumArcsNormalization()
{
$processor = new Processor();
$configuration = new Configuration(true);

$config = $processor->processConfiguration($configuration, [[
'http_method_override' => false,
'handle_all_throwables' => true,
'php_errors' => ['log' => true],
'workflows' => [
'workflows' => [
'enum' => [
'supports' => [self::class],
'places' => Places::cases(),
'transitions' => [
[
'name' => 'one',
'from' => [Places::A],
'to' => [['place' => Places::B, 'weight' => 2]],
],
[
'name' => 'two',
'from' => ['place' => Places::B, 'weight' => 3],
'to' => ['place' => Places::C],
],
],
],
],
],
]]);

$transitions = $config['workflows']['workflows']['enum']['transitions'];

$this->assertSame('one', $transitions[0]['name']);
$this->assertSame([['place' => 'a', 'weight' => 1]], $transitions[0]['from']);
$this->assertSame([['place' => 'b', 'weight' => 2]], $transitions[0]['to']);

$this->assertSame('two', $transitions[1]['name']);
$this->assertSame([['place' => 'b', 'weight' => 3]], $transitions[1]['from']);
$this->assertSame([['place' => 'c', 'weight' => 1]], $transitions[1]['to']);
}

public function testFormCsrfProtectionFieldAttrDoNotNormalizeKeys()
{
$processor = new Processor();
Expand Down
Loading