Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Move internal Container configuration from XML to PHP #37186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
40 tasks done
fabpot opened this issue Jun 10, 2020 · 94 comments · Fixed by #37217
Closed
40 tasks done

Move internal Container configuration from XML to PHP #37186

fabpot opened this issue Jun 10, 2020 · 94 comments · Fixed by #37217
Labels
Good first issue Ideal for your first contribution! (some Symfony experience may be required) Help wanted Issues and PRs which are looking for volunteers to complete them.

Comments

@fabpot
Copy link
Member

fabpot commented Jun 10, 2020

In Symfony 6, I we will promote usage of configuration written in PHP instead of YAML. For third-party bundles and core, we should do the same, replacing XML with PHP. Doing so would remove the need for the XML lib for core.

The biggest advantage is auto-completion with any modern IDE without explicit support for Symfony, and probably one less thing to learn (how to configure things in YAML/XML).

Be warned that semantic configuration will stay in YAML for now (as using PHP is much harder there).

#36778 did the work for the Twig bundle as an example.

We now need help from the community to move all the other bundles:

PLEASE, comment here BEFORE starting to work on something and WAIT for the confirmation to avoid duplicate work.

  • src/Symfony/Bundle/DebugBundle/Resources/config/services.xml (@jschaedl)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml (@magnetik)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml (@NguyenTruongLinh)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/cache*.xml (@iamvar)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/collectors.xml (@hvt)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml (@AhmedRaafat14)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/debug*.xml (@TuxBoy)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/error_renderer.xml (@benji07)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/esi.xml (@tuanminhgp)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/form*.xml (@misekai)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/fragment*.xml (@idetox)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/http*.xml (@IonBazan)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/identity_translator.xml (@smmd)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/lock.xml (@tomasjav)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/mailer*.xml (@instabledesign)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger*.xml (@hyoa)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/mime_type.xml (@GromNaN)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier*.xml (@szepczynski)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/profiling.xml (@hvt)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/property_access.xml (@qneyrat)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/property_info.xml (@qneyrat)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/request.xml (@dangkhoagms)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/routing*.xml (@phamuyentri)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/secrets.xml (@GromNaN)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/security_csrf.xml (@noweh)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml (@mamontovdmitriy)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml (@rvanlaak)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml (@cocorambo)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/ssi.xml (@50bhan)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml (@GaryPEGEOT)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/translation*.xml (@malteschlueter)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/validator*.xml (@simivar)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/web*.xml (@ck-developer)
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/workflow.xml (@lyrixx)
  • src/Symfony/Bundle/SecurityBundle/Resources/config/collectors.xml (@JudicaelR)
  • src/Symfony/Bundle/SecurityBundle/Resources/config/console.xml (@JudicaelR)
  • src/Symfony/Bundle/SecurityBundle/Resources/config/guard.xml (@JudicaelR)
  • src/Symfony/Bundle/SecurityBundle/Resources/config/security*.xml (@qneyrat)
  • src/Symfony/Bundle/SecurityBundle/Resources/config/templating_twig.xml (@ck-developer)
  • src/Symfony/Bundle/WebProfilerBundle/Resources/config/*.xml (@jschaedl)
@nicolas-grekas nicolas-grekas added the Help wanted Issues and PRs which are looking for volunteers to complete them. label Jun 10, 2020
@szepczynski
Copy link
Contributor

I do something in Notifier Component few weeks ago. I think I can migrate src/Symfony/Bundle/FrameworkBundle/Resources/config/notifier.xml

@fabpot
Copy link
Member Author

fabpot commented Jun 10, 2020

@szepczynski Great, can you do notifier_transports.xml as well? I've added you name on both :)

@szepczynski
Copy link
Contributor

yes, i missed them on the list

@ogizanagi ogizanagi added the Good first issue Ideal for your first contribution! (some Symfony experience may be required) label Jun 10, 2020
@szepczynski
Copy link
Contributor

One question about migrating FrameworkExtension - I guess that we need temporary two loaders, one for not migrated XMLs, and one for migrated until all configuration will be migrated.

Can someone add at first Php Loader to FrameworkExtension that everyone who starting from current master don't need create Php Loader?

@IonBazan
Copy link
Contributor

I can start with http_client.xml and http_client_debug.xml first 😅

@fabpot
Copy link
Member Author

fabpot commented Jun 10, 2020

@szepczynski Can you create the PHP loader in a separate PR that I can merge fast?
@IonBazan added, thanks

@szepczynski
Copy link
Contributor

@fabpot ok

fabpot added a commit that referenced this issue Jun 10, 2020
This PR was merged into the 5.2-dev branch.

Discussion
----------

add php loader to FrameworkExtension

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | #37186 <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT

Add php loader to migrate configuration from XML to PHP

Commits
-------

e05e811 add php loader to FrameworkExtension
@stof
Copy link
Member

stof commented Jun 10, 2020

For third-party bundles, we should do the same

For third-party bundles, I think it is too early to start this migration. The migration relies on using the new PHP DSL to configure services (migrating to the lower-level PHP API would not make sense as that would make maintenance harder). And this DSL is incomplete in previous versions of Symfony.
As we expect third-party bundles to keep support for our LTS release in a maintained version (otherwise, the LTS becomes useless, if it forces to use unmaintained versions of these bundles), they will either have to maintain 2 versions in parallel (high cost with low benefit as the XML config files will keep working) or delay the migration until the time they can go on supporting Symfony 5.2+ (so near the time 5.4 becomes the active LTS and 6.0 gets released).
The good news is that there is no actual BC impact for bundles to do the migration (they can do it in any minor version). And dropping ext-xml from project requirements will be possible only when all packages are migrated and nothing else needs it (dom-crawler needs it for instance)

@mamontovdmitriy
Copy link
Contributor

I want to help. Can I try to migrate [serializer] or something else?

@iamvar
Copy link
Contributor

iamvar commented Jun 10, 2020

Let me help. I can start from
src/Symfony/Bundle/FrameworkBundle/Resources/config/cache*.xml

@fabpot
Copy link
Member Author

fabpot commented Jun 10, 2020

@mamontovdmitriy serializer is yours
@iamvar cache*.xml files are yours
Thank you!

@phamuyentri
Copy link

I want to give it a hand. Can I start with
src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/errors.xml

@fabpot
Copy link
Member Author

fabpot commented Jun 11, 2020

@phamuyentri Sure, can you do routing*.xml?

@magnetik
Copy link
Contributor

Hi,
I can do annotations.xml to help :)

@fabpot
Copy link
Member Author

fabpot commented Jun 11, 2020

@magnetik Thank you, it's yours now.

@tomasjav
Copy link

Hi, I'd like to help with lock component.

@anvodev
Copy link
Contributor

anvodev commented Jun 11, 2020

I can help with src/Symfony/Bundle/FrameworkBundle/Resources/config/form*.xml
My understanding is they are 3 files, correct me if I'm wrong:

  • src/Symfony/Bundle/FrameworkBundle/Resources/config/form.xml
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/form_csrf.xml
  • src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml

@fabpot
Copy link
Member Author

fabpot commented Jun 11, 2020

@misekai Great! Thank you.

@fabpot
Copy link
Member Author

fabpot commented Jun 11, 2020

@tomasjav Lock is yours, thank you

fabpot added a commit that referenced this issue Jun 11, 2020
This PR was merged into the 5.2-dev branch.

Discussion
----------

[Notifier] Move configuration to PHP

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | #37186 <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT

Move Notifier Component Container configuration to PHP

Commits
-------

9891809 [Notifier] Move configuration yo PHP
@dangkhoagms
Copy link
Contributor

I can help with Bundle/FrameworkBundle/Resources/config/request.xml

@AhmedRaafat14
Copy link

@fabpot I can help with src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml

@fabpot
Copy link
Member Author

fabpot commented Jun 11, 2020

@dangkhoagms Thank you
@AhmedRaafat14 Thank you

@NguyenTruongLinh
Copy link
Contributor

Hi @fabpot, I think I can help src/Symfony/Bundle/FrameworkBundle/Resources/config/assets.xml

@jschaedl
Copy link
Contributor

@fabpot I'd like to help with

  • src/Symfony/Bundle/DebugBundle/Resources/config/services.xml and
  • src/Symfony/Bundle/WebProfilerBundle/Resources/config/*.xml

@adsazad
Copy link

adsazad commented Jun 25, 2020

@wouterj
I was not really emphasizing only file structure. Don't take this in wrong way but we have started thinking that symfony has started loosing its flexibility.

@adsazad
Copy link

adsazad commented Jun 25, 2020

i just want to say that updating symfony is really hard job.

@wouterj
Copy link
Member

wouterj commented Jun 25, 2020

I don't think you should have that feeling :). I think from a base, Symfony is just as flexible as in the past. However, I agree that one thing changed: The experience when using the default is now much much better by the introduction of Symfony Flex. This hasn't made the other formats worse though, they are still at the same level as when Symfony 2.0 was released.

And to be honest, I think that makes sense. Symfony allows you to get to your destination. When using the paved road, you have a smooth experience to the destination. You can also use the unpaved road, you still get to the destination but the experience is not so smooth. In Symfony 2.0, there was no paved road, in Symfony 4.0+ there is a paved road.

Anyway, yes it was a hard upgrade from the unpaved to the paved road in Symfony 4.0. I think the core team also realizes this. See e.g. this tweet from Fabien (responding to some people that expressed the same feelings as you): https://twitter.com/fabpot/status/1270981253962043392 "4.0 -> 5.2 is really about new features and refinements but no big changes. I don't envision any revolution in the next few versions either."

In any case, this is completely off-topic for this issue, as this issue is purely internal.

@TomasVotruba
Copy link
Contributor

@adsazad i just want to say that updating symfony is really hard job.

I feel you. I recommend you hire an external upgrade consultant to upgrade it. Doing it manually is hell... and non-sense in 2020. I do around 1 project upgrade a month on average, usually Symfony 3 to 5. With right tools like @rectorphp, coding standard and @phpstan it's piece of cake

@adsazad
Copy link

adsazad commented Jun 25, 2020

this month i did 6 upgrades. i have even developed my own tool for upgrading them.

@pounard
Copy link
Contributor

pounard commented Jun 25, 2020

I just wanted to highlight:

You can also use the unpaved road, you still get to the destination but the experience is not so smooth. In Symfony 2.0, there was no paved road, in Symfony 4.0+ there is a paved road.

I disagree, I used to bend Symfony in all most terrible ways I could think of (starting at 2.8) and it was fine, until 3.4. 3.4 did some great optimizations, and very nice end-user improvements, but it broke some of the natural flexibility it had before. I think it's the natural cost of specialisation and optimisation, nobody can't get around, not even Symfony.

Don't take it wrong, it's not a complaint, I love Symfony and continue gladly to use it, yet in my experience, trying to walk out the paved road since 3.4 may be very difficult, at least compared to how it was very easy and nice before. Especially with debug component, which is really invasive, and a few other performance optimisations that made the code much harder to read, and broke some undocumented edge cases.

@gggeek
Copy link

gggeek commented Jun 26, 2020

FWIW (and sorry for the OT) I agree with the sentiment that the "paved road" comes with a cost. Increasing the magic while keeping the flexibility leads naturally to greater code complexity. This is also often the case for speed optimizations. The end result is a framework which makes a lot of tedious operations quick and easy, but is harder to grasp when you want to tweak/change bits of it.
Maybe it's just me getting old and taking time to learn all the novelties (aka grumpy), but I am a great fan of code which is easy to read and fits in my head.

@aleksblendwerk
Copy link

aleksblendwerk commented Jul 3, 2020

Here, it's all about internal changes, it does not change anything for developers.

@fabpot Looks like this issue has caused some confusion and some people thought it affects all configuration files.

Also see here: https://www.reddit.com/r/PHP/comments/h93fjc/symfony_will_now_promote_php_over_yaml_and_xml/.

@enumag
Copy link
Contributor

enumag commented Aug 1, 2020

Be warned that semantic configuration will stay in YAML for now (as using PHP is much harder there).

@fabian Can you be more specific? Which parts of configuration will stay in YAML?

@Taluu
Copy link
Contributor

Taluu commented Aug 1, 2020

I think he's referring to semantic config (the one you parametrize through Configuration class and its ArrayNodse, prototypes, and so on)

@enumag
Copy link
Contributor

enumag commented Aug 1, 2020

@Taluu As in bundles will still be configured in YAML?

@chapterjason
Copy link
Contributor

@enumag You can cofigure these in php you just have to load them yourself.

// src/Kernel.php
class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    protected function prepareContainer(ContainerBuilder $container)
    {
        parent::prepareContainer($container);

        (require dirname(__DIR__) . '/config/packages/workflow.php')($container);
    }
}
// config/packages/workflow.php
return static function (ContainerBuilder $container) {
    $container->loadFromExtension(
        'framework',
        [
            'workflows' => [
                ChangeEmailWorkflow::NAME => [
                    "type" => "state_machine",
                    "marking_store" => [
                        "type" => "method",
                        "property" => "state",
                    ],
                    "supports" => [Token::class],
                    "initial_marking" => ChangeEmailWorkflow::STATE_PENDING,
                    "places" => [
                        ChangeEmailWorkflow::STATE_PENDING,
                        ChangeEmailWorkflow::STATE_APPROVED,
                        ChangeEmailWorkflow::STATE_VERIFIED,
                    ],
                    "transitions" => [
                        ChangeEmailWorkflow::TRANSITION_APPROVE => [
                            "from" => ChangeEmailWorkflow::STATE_PENDING,
                            "to" => ChangeEmailWorkflow::STATE_APPROVED,
                        ],
                        ChangeEmailWorkflow::TRANSITION_VERIFY => [
                            "from" => ChangeEmailWorkflow::STATE_APPROVED,
                            "to" => ChangeEmailWorkflow::STATE_VERIFIED,
                        ],
                    ],
                ],
            ],
        ]
    );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Ideal for your first contribution! (some Symfony experience may be required) Help wanted Issues and PRs which are looking for volunteers to complete them.
Projects
None yet
Development

Successfully merging a pull request may close this issue.