Skip to content
This repository was archived by the owner on Dec 3, 2023. It is now read-only.
This repository was archived by the owner on Dec 3, 2023. It is now read-only.

[config-transformer] PHP Constants not transforming correctly, invalid PHP generated #4436

@tacman

Description

@tacman

I used PHP constants in my yaml files to avoid typos in specific strings. It was a thing for a while, but never caught on, in part because of how enormously ugly it was.

Here's a yaml workflow

framework:
    workflows:
        Drawing:
            type: state_machine
            audit_trail:
                enabled: true
            marking_store:
                property: status
            supports: App\Entity\Drawing
            transitions:
                !php/const App\Entity\Drawing::TRANSITION_UPLOAD:
                    from:
                        - !php/const App\Entity\Drawing::PLACE_NEW
                    to: !php/const App\Entity\Drawing::PLACE_UPLOADED
                    metadata:
                        label: Upload
                        description: ''
                !php/const App\Entity\Drawing::TRANSITION_RENAME:
                    from:
                        - !php/const App\Entity\Drawing::PLACE_UPLOADED
                    to: !php/const App\Entity\Drawing::PLACE_RENAMED
                    metadata:
                        label: Rename
                        description: ''
                !php/const App\Entity\Drawing::TRANSITION_RESET:
                    from:
                        - !php/const App\Entity\Drawing::PLACE_UPLOADED
                        - !php/const App\Entity\Drawing::PLACE_RENAMED
                    to: !php/const App\Entity\Drawing::PLACE_NEW
                    metadata:
                        label: Reset
                        description: ''
            initial_marking: !php/const App\Entity\Drawing::PLACE_NEW
            places:
                !php/const App\Entity\Drawing::PLACE_NEW:
                    metadata:
                        label: New
                        description: ''
                !php/const App\Entity\Drawing::PLACE_UPLOADED:
                    metadata:
                        label: Uploaded
                        description: ''
                !php/const App\Entity\Drawing::PLACE_RENAMED:
                    metadata:
                        label: Renamed
                        description: ''

When I run

vendor/bin/config-transformer switch-format config/packages/workflow_Drawing.yaml 

The resulting PHP is invalid, and has enormously long lines, which ecs can't fix because the PHP is invalid (an unwanted colon on the end of the constant)

use App\Entity\Drawing;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension('framework', ['workflows' => ['Drawing' => ['type' => 'state_machine', 'audit_trail' => ['enabled' => true], 'marking_store' => ['property' => 'status'], 'supports' => Drawing::class, 'transitions' => Drawing::TRANSITION_UPLOAD:, 'initial_marking' => Drawing::PLACE_NEW, 'places' => Drawing::PLACE_NEW:]]]);
};

FWIW, the class has the constants defined as expected:

#[ORM\Entity(repositoryClass: DrawingRepository::class)]
class Drawing 
{
    final const PLACE_NEW = 'new';
    final const PLACE_UPLOADED = 'uploaded';
    final const PLACE_RENAMED= 'renamed';
    final const TRANSITION_UPLOAD= 'upload';
    final const TRANSITION_RENAME= 'rename';
    final const TRANSITION_RESET = 'reset';

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions