modera/routing-bundle

此包允许包动态包含您包内的路由文件。

安装次数: 5,114

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 4

分支: 1

开放问题: 0

类型:symfony-bundle

v3.1.0 2019-05-23 10:49 UTC

README

此包允许包动态包含路由文件,因此您不需要在根目录的 app/config/routing.yml 文件中手动注册它们。

安装

步骤 1: 下载包

composer require modera/routing-bundle:4.x-dev

此命令要求您全局安装了 Composer,如 Composer 文档中的 安装章节 所述。

步骤 2: 启用包

此包应通过 Flex 自动启用。如果您不使用 Flex,则需要手动通过在项目的 config/bundles.php 文件中添加以下行来启用包:

<?php
// config/bundles.php

return [
    // ...
    Sli\ExpanderBundle\SliExpanderBundle::class => ['all' => true], // if you still don't have it
    Modera\RoutingBundle\ModeraRoutingBundle::class => ['all' => true],
];

步骤 3: 添加路由

// config/routes.yaml

_modera_routing:
    resource: "@ModeraRoutingBundle/Resources/config/routing.yml"

文档

内部,ModeraRoutingBundle 依赖于 SliExpanderBundle 来利用创建扩展点的统一方法。简而言之,为了使包能够贡献路由资源,它必须做两件事:

  1. 创建一个实现 \Sli\ExpanderBundle\Ext\ContributorInterface 的贡献者类。
  2. 在服务容器中注册它,并带有标签 modera_routing.routing_resources_provider

以下是如何看起来您的贡献者类:

<?php

namespace Modera\ExampleBundle\Contributions;

use Sli\ExpanderBundle\Ext\ContributorInterface;

class RoutingResourcesProvider implements ContributorInterface
{
    public function getItems()
    {
        return array(
            '@ModeraExampleBundle/Resources/config/routing.yml'
        );
    }
}

以下是其在服务容器中的定义:

<services>
    <service id="modera_example.contributions.routing_resources_provider"
             class="Modera\ExampleBundle\Contributions\RoutingResourcesProvider">

        <tag name="modera_routing.routing_resources_provider" />
    </service>
</services>

从版本 v1.1 开始,添加了一种简化贡献新路由资源的方法(不需要添加中间文件)。现在,您可以通过返回标准化文件的內容来代替通过 getItems() 方法返回路由文件的路径。

<?php

class RoutingResourcesProvider implements ContributorInterface
{
    public function getItems()
    {
        return array(
            array(
                'resource' => '@ModeraExampleBundle/Controller/DefaultController.php',
                'type' => 'annotation',
            ),
        );
    }
}

许可

此包受 MIT 许可证的保护。请参阅包中的完整许可证:Resources/meta/LICENSE。