modera/routing-bundle

This bundle makes it possible for bundles to dynamically include routing files from within your bundles.

Installs: 5 114

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 1

Open Issues: 0

Type:symfony-bundle

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

README

This bundle makes it possible for bundles to dynamically include routing files so you don't need to manually register them in root app/config/routing.yml file.

Installation

Step 1: Download the Bundle

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

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

This bundle should be automatically enabled by Flex. In case you don't use Flex, you'll need to manually enable the bundle by adding the following line in the config/bundles.php file of your project:

<?php
// config/bundles.php

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

Step 3: Add routing

// config/routes.yaml

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

Documentation

Internally ModeraRoutingBundle relies on SliExpanderBundle to leverage a consistent approach to creating extension points. Shortly speaking, in order for a bundle to contribute routing resources it has to do two things:

  1. Create a contributor class which implements \Sli\ExpanderBundle\Ext\ContributorInterface
  2. Register it in a service container with tag modera_routing.routing_resources_provider.

This is how your contributor class may look like:

<?php

namespace Modera\ExampleBundle\Contributions;

use Sli\ExpanderBundle\Ext\ContributorInterface;

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

And here we have its service container definition:

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

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

Since version v1.1 a simplified way of contributing new routing resources has been added (which doesn't require adding intermediate files). Instead of having getItems() method return a path to a routing file you can now return normalized file's content:

<?php

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

Licensing

This bundle is under the MIT license. See the complete license in the bundle: Resources/meta/LICENSE