symplify icon indicating copy to clipboard operation
symplify copied to clipboard

add example with constant as key

Open tacman opened this issue 3 years ago • 9 comments

This is a shorter example. I think the issue is using a constant as the key, or maybe it's using a class constant rather than a PHP constant. Likely this test can be merged with constant.yaml.

Addresses #4436

tacman avatar Oct 18 '22 11:10 tacman

This looks much better :clap:

TomasVotruba avatar Oct 18 '22 11:10 TomasVotruba

I shortly analysed the problem the related code lines are:

  • https://github.com/symplify/symplify/blob/ba28094c01744a0571a5a8610402ac68857cc95c/packages/config-transformer/src/ConfigLoader.php#L34
  • https://github.com/symplify/symplify/blob/ba28094c01744a0571a5a8610402ac68857cc95c/packages/config-transformer/src/ConfigLoader.php#L68-L72

Sadly I was not yet able to find a way to support all cases. Maybe someone else with better regex skill can make this work :)

A Regex 101 link: https://regex101.com/r/gz7K1V/1

Expected:

parameters:
     class_constant: %const(Symplify\ConfigTransformer\Tests\Converter\ConfigFormatConverter\YamlToPhp\YamlToPhpTest::TEST)
     class: %const(Symplify\ConfigTransformer\Tests\Converter\ConfigFormatConverter\YamlToPhp\YamlToPhpTest::class)
     class2: %const(Symplify\ConfigTransformer\Tests\Converter\ConfigFormatConverter\YamlToPhp\YamlToPhpTest::class)
     const: %const(PHP_INT_MAX)
     const2: %const(PHP_INT_MAX)
     unexisting_constant: %const(SomeClass::Constant)
-    %const(PHP_INT_MAX: some_value)
-    %const(App\Entity\Plant::TRANSITION_PLANT: some_value)
-    %const(App\Entity\Plant::TRANSITION_TWO: some_value)
+    %const(PHP_INT_MAX): some_value
+    %const(App\Entity\Plant::TRANSITION_PLANT): some_value
+    %const(App\Entity\Plant::TRANSITION_TWO): some_value

alexander-schranz avatar Nov 23 '22 22:11 alexander-schranz

Check this one 😉

image

Wirone avatar Nov 24 '22 02:11 Wirone

FWIW, const2, above, no longer works in 6.2.

That is, !php/const: no longer is allowed, the colon must be removed.

On Wed, Nov 23, 2022 at 9:17 PM Grzegorz Korba @.***> wrote:

Check this one https://regex101.com/r/gz7K1V/2 😉

[image: image] https://user-images.githubusercontent.com/600668/203679273-bf3f6e13-a56b-40b3-a6dc-8e8e2eeb1df9.png

— Reply to this email directly, view it on GitHub https://github.com/symplify/symplify/pull/4441#issuecomment-1325862399, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEXIQI7HDFD77ZE65S76NLWJ3F27ANCNFSM6AAAAAARH72ZLU . You are receiving this because you authored the thread.Message ID: @.***>

tacman avatar Nov 24 '22 03:11 tacman

@tacman Thx for th ehint, for the upgrade process to convert both need to be supported if somebody uses older version :) at the end it should both be converted to:

->set('transitions', [OurConstant::class => 'value'])

alexander-schranz avatar Nov 24 '22 08:11 alexander-schranz

@Wirone Nice, thank you 👍 do you want to create the pull request, don't want to steal your contribution :)

alexander-schranz avatar Nov 24 '22 08:11 alexander-schranz

@alexander-schranz do I understand correctly that such PR should provide changes in 2 files that you mentioned earlier (plus 3rd revision of the regex)?

Wirone avatar Nov 24 '22 11:11 Wirone

@Wirone the lines are in the same file. The regex need to be adopted and the lines where the regex it is used. And we should adopt existing tests or use the one provided here :) I sadly did not test it yet out if there are more changes required, but I don't think it.

alexander-schranz avatar Nov 24 '22 11:11 alexander-schranz

FYI: I did not add fixtures for constants use as keys, so @tacman can do it, but I suggest to merge #4484 first and then add such examples to packages/config-transformer/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/normal/constant.yaml and packages/config-transformer/tests/Converter/ConfigFormatConverter/YamlToPhp/Fixture/normal/class_constant.yaml.

But be aware, I tested it and I got: image

😅

Wirone avatar Nov 25 '22 08:11 Wirone