Symfony 4 不鼓励捆绑包,这是为什么呢?什么取代了它们?

Bundles are not encouraged in Symfony 4, why is that? And what replaces them?

在练习 Symfony 4.1 时,我注意到它在捆绑页面上是怎么说的:(https://symfony.com/doc/current/bundles.html)

In Symfony versions prior to 4.0, it was recommended to organize your own application code using bundles. This is no longer recommended and bundles should only be used to share code and features between multiple applications.

为什么会这样?用什么来替换捆绑包?只需在一个 "App" 包中创建目录?

所以仅仅一个子文件夹代替了一个包?

您可以在此处查看演示应用程序 -> https://github.com/symfony/demo

您问题的答案写在本页底部here on symfony site。 总结

But a bundle is meant to be something that can be reused as a stand-alone piece of software. If UserBundle cannot be used "as is" in other Symfony apps, then it shouldn't be its own bundle. Moreover, if InvoiceBundle depends on ProductBundle, then there's no advantage to having two separate bundles.

然后

Don't create any bundle to organize your application logic.

Symfony applications can still use third-party bundles (installed in vendor/) to add features, but you should use PHP namespaces instead of bundles to organize your own code.

所以回答你的问题 “那么仅仅一个子文件夹就可以取代一个包?”是的!如果它是一段可以被其他应用程序使用的可重用代码,则将其打包成一个包,否则如果它只是用于组织应用程序,请为此使用文件夹(带有名称空间)。