覆盖文件的 Symfony Bundle 名称

Symfony Bundle name for overriding files

当 extending/overriding Symfony (3.0.x) 项目中的 Bundle 时,将相应的文件夹添加到“/app/Resources”文件夹。我明白了。 我没有得到的是你怎么知道那个文件夹应该有什么名字。

示例: FOSUserBundle 想要一个名为 "FOSUserBundle" 的文件夹。 捆绑包的位置是“/vendor/friendsofsymfony/user-bundle/”。

显然这与 app/Resources 位置的文件夹名称不同。

在哪里可以找到定义如何调用要添加的文件夹的包的名称或映射信息? 提前致谢!

您可以在任何捆绑包的主 php Class 中找到捆绑包名称,它被称为捆绑包,在本例中为 /vendor/friendofsymfony/user-bundle/FOSUserBundle

捆绑包名称是实际捆绑包 class 的短 class 名称(class 名称的最后一部分,不带名称空间)(参见 the code) .

几个例子..

FOS\UserBundle\FOSUserBundle                  -> FOSUserBundle
Sylius\Bundle\ReviewBundle\SyliusReviewBundle -> SyliusReviewBundle
Sonata\BlockBundle\SonataBlockBundle          -> SonataBlockBundle

如果您查看用于将捆绑包添加到已注册捆绑包的 class,您可以从中获取捆绑包名称。

因此,例如(取自 Sonata Block Bundle 文档)..

public function registerBundles()
{
    return array(
        // Dependency (check that you don't already have this line)
        new Knp\Bundle\MenuBundle\KnpMenuBundle(),

        // Vendor specifics bundles
        new Sonata\CoreBundle\SonataCoreBundle(),
        new Sonata\BlockBundle\SonataBlockBundle(),
    );
}

将是 KnpMenuBundleSonataCoreBundleSonataBlockBundle

此外,您只需执行控制台命令 config:dump-reference 即可列出可用的包名称。

3.x php bin/console config:dump-reference

~2.4 php app/console config:dump-reference

输出:

Available registered bundles with their extension alias if available:

+------------------------------+--------------------------+
| Bundle name                  | Extension alias          |
+------------------------------+--------------------------+
| AppBundle                    |                          |
| AsseticBundle                | assetic                  |
| DebugBundle                  | debug                    |
| DoctrineBundle               | doctrine                 |
| DoctrineMongoDBBundle        | doctrine_mongodb         |
| FrameworkBundle              | framework                |
| KnpMenuBundle                | knp_menu                 |
| KnpPaginatorBundle           | knp_paginator            |
| LiipImagineBundle            | liip_imagine             |
| MewesKTwigExcelBundle        | mewes_k_twig_excel       |
| MonologBundle                | monolog                  |
| SecurityBundle               | security                 |
| SensioDistributionBundle     | sensio_distribution      |
| SensioFrameworkExtraBundle   | sensio_framework_extra   |
| SensioGeneratorBundle        |                          |
| StofDoctrineExtensionsBundle | stof_doctrine_extensions |
| SwiftmailerBundle            | swiftmailer              |
| TwigBundle                   | twig                     |
| UserBundle                   |                          |
| VichUploaderBundle           | vich_uploader            |
| WebProfilerBundle            | web_profiler             |
+------------------------------+--------------------------+